I. Introduction of SOLR
Recently in a project to do a full-text search function, initially intended to use Apache Lucene to achieve, after all, before the Lucene have a little understanding, but in the Internet to see the technical articles when they saw someone introduced Apache SOLR, feel very good,
is also an open source search server, mainly based on HTTP and Apache Lucene implementation. The resources stored in Apache Solr are stored in Document as objects, highlighting search results with their own Chinese word segmentation technology.
Ii. SOLR Configuration
First step: Download SOLR, HTTP://WWW.APACHE.ORG/DYN/CLOSER.CGI/LUCENE/SOLR
Unzip to the 3.6.1 version of the download, unzip it to the E-drive. e:/apache-solr-3.6.1
Step Two: Modify the Conf\server.xml to change the line where the port 8080 is located as follows:
<connector port= "8080" protocol= "http/1.1"
connectiontimeout= "20000"
Redirectport= "8443" uriencoding= "UTF-8"/>
Added the uriencoding= "UTF-8" configuration.
Step Three: Configure SOLR
In the Tomcat conf directory, add the Catalina\localhost\solr.xml file, if the Conf folder does not have Catalina, create it.
Solr.xml content:
<context docbase= "E:/apache-solr-3.6.1/dist/apache-solr-3.6.1.war" debug= "0" crosscontext= "true" >
<environment name= "Solr/home" type= "java.lang.String" value= "E:/APACHE-SOLR-3.6.1/EXAMPLE/SOLR" override= "true" /></context>
Fourth step: Start Tomcat. The input http://localhost:8080/solr/appears as a welcome interface, indicating success.
Iii. Use of SOLR
When invoking the SOLR service, Apache-solr-solrj-3.6.1.jar,apache has already provided us with the SOLRJ tool, and we simply import the relevant packages and use their simple APIs to easily manipulate SOLR.
Establish a connection to the SOLR service
String url = "HTTP://10.13.17.38:8983/SOLR";
Commonshttpsolrserver Server = new Commonshttpsolrserver (URL);
Server.setsotimeout (3000); Socket Read timeout
Server.setconnectiontimeout (1000);
Server.setdefaultmaxconnectionsperhost (1000);
Server.setmaxtotalconnections (10);
Server.setfollowredirects (FALSE); Defaults to False
Server.setallowcompression (TRUE);
Server.setmaxretries (1);
Settings for search criteria
Solrquery query = new Solrquery ();
Query.setquery ("Tags:t5 and T7");
Query.addfield ("auction_id");
Query.setstart (0);
Query.setrows (4);
Query.addsortfield ("auction_id", SolrQuery.ORDER.desc);
Query.addsortfield ("Auction_point", SOLRQUERY.ORDER.ASC);
Set highlighting
Query.sethighlight (TRUE); Turn on Highlight components
Query.addhighlightfield ("content");//Highlight Field
Query.addhighlightfield ("Titlestr");//Highlight Field
Query.sethighlightsimplepre ("<font color= ' Red ' >");//tag, highlight keyword prefix
Query.sethighlightsimplepost ("</font>");//suffix
Query.sethighlightsnippets (3);//result shard number, default is 1
Query.sethighlightfragsize (70);//maximum length per shard, default is 100
Add Chinese participle
Modify the Solr\conf\schema.xml file to include the following field type in the file.
<fieldtype name= "Text_zh" class= "SOLR. TextField "
Positionincrementgap= ">"
<analyzer type= "Index" >
<tokenizer
class= "Org.wltea.analyzer.solr.IKTokenizerFactory" usesmart= "false"/>
</analyzer>
<analyzer type= "Query" >
<tokenizer
class= "Org.wltea.analyzer.solr.IKTokenizerFactory" usesmart= "false"/>
</analyzer>
</fieldType>
And then you need to use this type of participle field
<field name= "Content" type= "Text_zh" indexed= "true" stored= "true"/>
Apache SOLR uses