【Solr】solr suggest

1. Add some testing data to solr
open command prompt, and  cd D:\solr_home\exampledocs

D:\solr_home\exampledocs>java -Durl=http://localhost:8080/solr/update -jar post  jar *xml

If you can see the following information, adding index is successfully.
SimplePostTool version 1.5
Posting files to base url [http://localhost:8080/solr/update|http://localhost:8080/solr/update] using content-type
pplication/xml..
POSTing file gb18030-example.xml
POSTing file hd.xml
POSTing file ipod_other.xml
POSTing file ipod_video.xml
POSTing file manufacturers.xml
POSTing file mem.xml
POSTing file money.xml
POSTing file monitor.xml
POSTing file monitor2.xml
POSTing file mp500.xml
POSTing file sd500.xml
POSTing file solr.xml
POSTing file utf8-example.xml
POSTing file vidcard.xml
14 files indexed.
COMMITting Solr index changes to [http://localhost:8080/solr/update|http://localhost:8080/solr/update]..

Here, if use command D:\solr_home\exampledocs>java -jar post  jar *xml

will has the error SimplePostTool: FATAL: IOException while posting data: java.net.ConnectException: Connection refused: connect

that's because solr uses default port 8983, here is using port 8080.



2. modify configuration
open file D:\solr_home\solr\collection1\conf\solrconfig.xml

add configuration:
<searchComponent name="suggest" class="solr.SpellCheckComponent">
  <lst name="spellchecker">
    <str name="name">suggest</str>
    <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
    <str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str>
    <str name="field">name</str>
    <float name="threshold">0.005</float>
    <str name="buildOnCommit">true</str>
    <!--<str name="storeDir">spellchecker</str>-->
  </lst>
</searchComponent>
 
 <requestHandler name="/suggest" class="org.apache.solr.handler.component.SearchHandler">
  <lst name="defaults">
    <str name="spellcheck">true</str>
    <str name="spellcheck.dictionary">suggest</str>
    <str name="spellcheck.count">10</str>
    <str name="spellcheck.onlyMorePopular">true</str>
    <str name="spellcheck.collate">true</str>
  </lst>
  <arr name="components">
    <str>suggest</str>
  </arr>
</requestHandler>


3. test
In the browser input  http://localhost:8983/solr/suggester/?q=s , you will set the following result:
<response>
<lst name="responseHeader">
 <int name="status">0</int>
 <int name="QTime">2</int>
</lst>
<lst name="spellcheck">
 <lst name="suggestions">
  <lst name="s">
   <int name="numFound">10</int>
   <int name="startOffset">0</int>
   <int name="endOffset">1</int>
   <arr name="suggestion">
     <str>sdram</str>
     <str>system</str>
     <str>some</str>
     <str>server</str>
     <str>series</str>
     <str>sp2514n</str>
     <str>samsung</str>
     <str>spinpoint</str>
     <str>sata</str>
     <str>search</str>
   </arr>
  </lst>
  <str name="collation">sdram</str>
 </lst>
</lst>
</response>

interface




http://wiki.apache.org/solr/Suggester

猜你喜欢

转载自smallwildpig.iteye.com/blog/1738543
今日推荐