SOLR Use Introduction to search forum posts for example

Source: Internet
Author: User
Tags solr

Copyright information: You can reprint, reprint, please be sure to hyperlink form to indicate the original source of the article, that is the following statement.

Original source: Click to open the link

The original text also describes the deployment of SOLR, because I have already had an article before, so omit

Application design index structure for search forum posts:

Field Description
Id Post ID
User Publish user name or UserID
Title Title
Content Content
Timestamp Publication time
Text Put the title and content here, and you can search for the content at the same time.

6. The index structure above tells SOLR to overwrite E:\apache-solr-1.3.0\example\solr\conf\scheam.xml with the following, (you can back up this file to see the official example later):

<?xml version= "1.0" encoding= "UTF-8"?> <schema name= "Example" version= "1.1" > <types> <fie Ldtype name= "string" class= "SOLR. Strfield ' sortmissinglast= true ' omitnorms= ' true '/> <fieldtype name= ' Sint ' Class= ' SOLR. Sortableintfield "sortmissinglast=" true "omitnorms=" true "/> <fieldtype name=" date "class=" SOLR. Datefield "sortmissinglast=" true "omitnorms=" true "/> <fieldtype name=" text "class=" SOLR. TextField "positionincrementgap=" > <analyzer> <tokenizer class= "SOLR." Cjktokenizerfactory "/> </analyzer> </fieldType> </types> <fields> ; field name= "id" type= "Sint" Indexed= "true" stored= "true" required= "true"/> <field "User" Name= "string" in Dexed= "true" stored= "true"/> <field name= "title" type= "text" indexed= "true" stored= "true"/> <field nam E= "Content" type= "text" indexed= "true" stored= "true"/> <fieLD name= "timestamp" type= "date" indexed= "true" stored= "true" default= "Now"/> <field name= "text" type= "text" Inde Xed= "true" stored= "false" multivalued= "true"/> </fields> <!--Field to the determine and enforce do   
      Cument uniqueness. Unless this field are marked with required= "false", it would be a required field--> <uniquekey>id</uni quekey> <!--field for the "Queryparser to" explicit FieldName is absent--> &LT;DEFAULTSEARCHF ield>text</defaultsearchfield> <!--solrqueryparser configuration:defaultoperator= "AND|OR"--> &L T;solrqueryparser defaultoperator= "and"/> <!--copyfield commands copy one field to another in the time a docu  ment is added to the index. It ' s used either to index the same field differently, or to add multiple fields to the same field for Easier/fas  ter searching. --> <!----> <copyfield source= "title" Dest= "Text "/> <copyfield source=" content "dest=" text "/> </schema>   


7, restart Tomcat, and then manually create two XML data files in E:\apache-solr-1.3.0\example\exampledocs. Save As Demo-doc1.xml and Demo-doc2.xml, respectively:

<?xml version= "1.0" encoding= "UTF-8"?>  
<add>  
    <doc>  
        <field name= "id" >1</ field>  
        <field name= "user" >chenlb</field>  
        <field name= "title" >SOLR Application speech </field>  
        <field name= "Content" > This section is about submitting data to the server to index, here are some data, such as: server, you can try to find it. </field>  
    </doc>  


<?xml version= "1.0" encoding= "UTF-8"?>  
<add>  
    <doc>  
        <field name= "id" >2</ field>  
        <field name= "user" >bory.chan</field>  
        <field name= "title" > Search engine </field>  
        <field name= "Content" > Search server There is a lot of data. </field>  
        <field name= "timestamp" >2009-02-18T00:00:00Z</field>  
    </doc>  
    < doc>  
        <field name= "id" >3</field>  
        <field name= "user" >other</field>  
        < Field name= "title" > What is this </field>  
        <field name= "Content" > What sports do you like? Basketball. </field>  
        <field name= "timestamp" >2009-02-18T12:33:05.123Z</field>  
    </doc>  


8, submit data to do index, to E:\apache-solr-1.3.0\example\exampledocs, run:

E:\apache-solr-1.3.0\example\exampledocs>java-durl=http://localhost:8080/solr/update-dcommit=yes-jar Post.jar demo-doc*.xml
simpleposttool:version 1.2
SimplePostTool:WARNING:Make sure your XML documents are Enco Ded in UTF-8, encodings are not currently supported
files to simpleposttool:posting Update..
simpleposttool:posting file demo-doc1.xml
simpleposttool:posting file demo-doc2.xml
simpleposttool: Committing SOLR index changes.

This is the problem with SOLR 1.4 running this example. Error: Org.apache.solr.common.SolrException:QueryElevationComponent requires the schema to have a Uniquekeyfield Implemented using Strfield.

Remove two nodes from the Solrconfig.xml: the elevator component.

<searchcomponent name= "Elevator" class= "SOLR." Queryelevationcomponent ">
    <!--pick a fieldtype to analyze queries--> <str name=
   " Queryfieldtype "& gt;string</str>
    <str name= "Config-file" >elevate.xml</str>
  </searchComponent>

  <!--A Request handler for demonstrating the elevator component--> <requesthandler name=
  "/elevate" CLA Ss= "SOLR. Searchhandler "startup=" lazy ">
    <lst name=" Defaults ">
      <str name=" Echoparams ">explicit</ str>
      <str name= "DF" >text</str>
    </lst>
    <arr name= "last-components" >
      <str>elevator</str>
    </arr>
  </requestHandler>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.