wxsheng 发表于 2016-12-15 07:10:34

solr安装和suggest

  学习记录:
  使用solr之前先安装jdk 这些大家都知道了
  solr下载地址:http://labs.mop.com/apache-mirror/lucene/solr/3.6.2
  windows 下载zip格式的 直接解压可以使用 开始安装solr 解压下载下来的 apache-solr-x.x.x.zip,可以看到其中包含 example 目录,这个目录下有个 jetty web容器和solr war包,以及在example\solr\conf solr的配置文件:solrconfig.xml、schema.xml。
  打开命令行,cd 到 example 目录,然后输入以下命令来启动 solr 命令:
  java -jar start.jar 当命令行中出现 “2013-04-09 15:39:26.299:INFO::StartedSocketConnector@0.0.0.0:8983”时,就代表jetty服务已经运行了,打开浏览器,输入 "http://localhost:8983/solr/admin/" 就可以看到solr运行的界面,如果出现该界面,说明solr运行成功了
  下面是启用solr suggest suggest 的功能依赖拼写组件,solr_home/data 目录下会有一个 spellchecker 目录,该目录用于存放 suggest 和 拼写检查的索引库,所以要先配置 spell 功能,首先在sehema.xml里面配置,配置如下:
  <field name="suggestion"  type="string" indexed="true"
  stored="true" termVectors="true" multiValued="true"/>
  配置 suggest 的处理组件和请求类,在solrconfig.xml中配置,配置如下:
  <searchComponent name="spellcheck" class="solr.SpellCheckComponent">
  <str name="queryAnalyzerFieldType">textSpell</str>
  <lst name="spellchecker">
  <str name="name">default</str>
  <str name="field">title</str>
  <str name="buildOnCommit">true</str>
  <str name="spellcheckIndexDir">spellchecker</str>
  </lst>
  </searchComponent>
  <searchComponent class="solr.SpellCheckComponent" name="suggest">
  <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">suggestion</str>  
  <str name="sourceLocation">dict.txt</str> 
  <float name="threshold">0.005</float>
  <str name="buildOnCommit">true</str>
  </lst>
  </searchComponent>
  <requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggest">
  <lst name="defaults">
  <str name="spellcheck">true</str>
  <str name="spellcheck.dictionary">suggest</str>
  <str name="spellcheck.onlyMorePopular">true</str>
  <str name="spellcheck.count">5</str>
  <str name="spellcheck.collate">true</str>
  </lst>
  <arr name="components">
  <str>suggest</str>
  </arr>
  </requestHandler>
  其中使用到dict.text 为:
  # sample dict 
  HP compaq
  HP Pavilion
  HP EliteBook
  在使用搜索前 ,先建立索引:
  http://localhost:8983/solr/suggest?spellcheck.build=true
  搜索:
  http://localhost:8983/solr/suggest/?q=HP搜索结果为:
  

  学习过程 仅供参考!
 
页: [1]
查看完整版本: solr安装和suggest