sm702 发表于 2015-11-12 09:47:52

Solr学习总结-附加功能

  找到与查询结果相似的文档:
  http://localhost:8983/solr/select?q=name:edition&mlt=true&mlt.fl=name&mlt.mintf=1&mlt.mindf=1


  mlt.fl:按照结果文档的哪一个field求相似。


  mlt.mintf:结果文档中的本field的某一个词出现的tf大于此值,才以此词求相似。


  mlt.mindf:通上,不过是df。


  自定义的显示结果(非xml):
  首先定义渲染器和名字:<queryResponseWriter name=&quot;velocity&quot; class=&quot;org.apache.solr. request.VelocityResponseWriter&quot;/>其次定义请求的处理器(包括显示的结果,行数,默认的查询域,查询的格式等等):<requestHandler name=&quot;/browse&quot; class=&quot;solr.SearchHandler&quot;>
<lst name=&quot;defaults&quot;>
<str name=&quot;wt&quot;>velocity</str>
<str name=&quot;v.template&quot;>browse</str>
<str name=&quot;v.layout&quot;>layout</str>
<str name=&quot;title&quot;>Solr cookbook example</str>
<str name=&quot;defType&quot;>dismax</str>
<str name=&quot;q.alt&quot;>*:*</str>
<str name=&quot;rows&quot;>10</str>
<str name=&quot;fl&quot;>*,score</str>
<str name=&quot;qf&quot;>name</str>
</lst>
</requestHandler>对匹配的词高亮显示:
  
  http://localhost:8983/solr/select?q=name:book&hl=true


  指定高亮显示的field:http://localhost:8983/solr/select?q=name:book&hl=true&hl.fl=name,description
  指定高亮的标签:http://localhost:8983/solr/select?q=name:book&hl=true&hl.simple.pre=<b>&hl.simple.post=</b>
  高亮长文本并获得好的性能:<field name=&quot;name&quot; type=&quot;text&quot; indexed=&quot;true&quot; stored=&quot;true&quot;
termVectors=&quot;true&quot; termPositions=&quot;true&quot; termOffsets=&quot;true&quot; />http://localhost:8983/solr/select?q=name:book&hl=true&hl.useFastVectorHighlighter=true


  
  对某些field按照函数结果进行排序:
  http://localhost:8983/solr/select?q=name:company&sort=dist(2,geoX,geoY,13,13)&#43;asc
  按照发音查询:

<field name=&quot;name&quot; type=&quot;phonetic&quot; indexed=&quot;true&quot; stored=&quot;true&quot; />
<fieldtype name=&quot;phonetic&quot; stored=&quot;false&quot; indexed=&quot;true&quot; class=&quot;solr.
TextField&quot; >
<analyzer>
<tokenizer class=&quot;solr.StandardTokenizerFactory&quot;/>
<filter class=&quot;solr.DoubleMetaphoneFilterFactory&quot; inject=&quot;false&quot;/>
</analyzer>
</fieldtype>
  自定义忽略的词语:

<field name=&quot;name&quot; type=&quot;text_ignored&quot; indexed=&quot;true&quot; stored=&quot;true&quot; />
<fieldType name=&quot;text_ignored&quot; class=&quot;solr.TextField&quot;
positionIncrementGap=&quot;100&quot;>
<analyzer>
<tokenizer class=&quot;solr.WhitespaceTokenizerFactory&quot;/>
<filter class=&quot;solr.StopFilterFactory&quot; ignoreCase=&quot;true&quot;
words=&quot;ignored.txt&quot; enablePositionIncrements=&quot;true&quot; />
</analyzer>
</fieldType>

  对查询结果计算统计:
  http://localhost:8983/solr/select?q=name:book&stats=true&stats.field=price


  返回结果:

<lst name=&quot;stats&quot;>
<lst name=&quot;stats_fields&quot;>
<lst name=&quot;price&quot;>
<double name=&quot;min&quot;>27.77</double>
<double name=&quot;max&quot;>39.99</double>
<double name=&quot;sum&quot;>97.86999999999999</double>
<long name=&quot;count&quot;>3</long>
<long name=&quot;missing&quot;>0</long>
<double name=&quot;sumOfSquares&quot;>3276.9851000000003</double>
<double name=&quot;mean&quot;>32.62333333333333</double>
<double name=&quot;stddev&quot;>6.486118510583508</double>
</lst>
</lst>
</lst>
  检查拼写错误:

<searchComponent name=&quot;spellcheck&quot; class=&quot;solr.SpellCheckComponent&quot;>
<lst name=&quot;spellchecker&quot;>
<str name=&quot;name&quot;>default</str>
<str name=&quot;field&quot;>name</str>
<str name=&quot;spellcheckIndexDir&quot;>./spellchecker</str><!-- 目录等同于索引目录-->
<str name=&quot;buildOnCommit&quot;>true</str>
</lst>
</searchComponent>
<requestHandler name=&quot;standard&quot; class=&quot;solr.SearchHandler&quot;
default=&quot;true&quot;>
<arr name=&quot;last-components&quot;>
<str>spellcheck</str>
</arr>
</requestHandler>
  http://localhost:8983/solr/spell?q=name:(other boak)&spellcheck=true&spellcheck.collate=true

<lst name=&quot;spellcheck&quot;>
<lst name=&quot;suggestions&quot;>
<lst name=&quot;othar&quot;>
<int name=&quot;numFound&quot;>1</int>
<int name=&quot;startOffset&quot;>6</int>
<int name=&quot;endOffset&quot;>11</int>
<arr name=&quot;suggestion&quot;>
<str>other</str>
</arr>
</lst>
<lst name=&quot;boak&quot;>
<int name=&quot;numFound&quot;>1</int>
<int name=&quot;startOffset&quot;>12</int>
<int name=&quot;endOffset&quot;>16</int>
<arr name=&quot;suggestion&quot;>
<str>book</str>
</arr>
</lst>
<str name=&quot;collation&quot;>name:(other book)</str>
</lst>
</lst>
  group by功能:

http://localhost:8983/solr/select?q=name:company&group=true&group.field=mainOfficeId

每个组允许的最大的文档数目:
  http://localhost:8983/solr/select?q=name:company&group=true&group.field=mainOfficeId&group.limit=4.




  



版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: Solr学习总结-附加功能