Solr学习总结-附加功能

本文详细介绍了Solr的高级搜索特性,包括查询参数、显示结果定制、高亮显示、自定义忽略词语、统计计算、拼写检查等功能,以及如何对查询结果进行排序和优化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

找到与查询结果相似的文档

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)

首先定义渲染器和名字:

[html]  view plain copy
  1. <queryResponseWriter name="velocity" class="org.apache.solr. request.VelocityResponseWriter"/>  
其次定义请求的处理器(包括显示的结果,行数,默认的查询域,查询的格式等等):
[html]  view plain copy
  1. <requestHandler name="/browse" class="solr.SearchHandler">  
  2. <lst name="defaults">  
  3. <str name="wt">velocity</str>  
  4. <str name="v.template">browse</str>  
  5. <str name="v.layout">layout</str>  
  6. <str name="title">Solr cookbook example</str>  
  7. <str name="defType">dismax</str>  
  8. <str name="q.alt">*:*</str>  
  9. <str name="rows">10</str>  
  10. <str name="fl">*,score</str>  
  11. <str name="qf">name</str>  
  12. </lst>  
  13. </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>

高亮长文本并获得好的性能

[html]  view plain copy
  1. <field name="name" type="text" indexed="true" stored="true"  
  2. <strong>termVectors="true" termPositions="true" termOffsets="true"</strong> />  
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)+asc

按照发音查询

[html]  view plain copy
  1. <field name="name" type="phonetic" indexed="true" stored="true" />  
  2. <fieldtype name="phonetic" stored="false" indexed="true" class="solr.  
  3. TextField" >  
  4. <analyzer>  
  5. <tokenizer class="solr.StandardTokenizerFactory"/>  
  6. <filter class="solr.DoubleMetaphoneFilterFactory" inject="false"/>  
  7. </analyzer>  
  8. </fieldtype>  

自定义忽略的词语

[html]  view plain copy
  1. <field name="name" type="text_ignored" indexed="true" stored="true" />  
  2. <fieldType name="text_ignored" class="solr.TextField"  
  3. positionIncrementGap="100">  
  4. <analyzer>  
  5. <tokenizer class="solr.WhitespaceTokenizerFactory"/>  
  6. <filter class="solr.StopFilterFactory" ignoreCase="true"  
  7. words="ignored.txt" enablePositionIncrements="true" />  
  8. </analyzer>  
  9. </fieldType>  

对查询结果计算统计

http://localhost:8983/solr/select?q=name:book&stats=true&stats.field=price

返回结果:

[html]  view plain copy
  1. <lst name="stats">  
  2. <lst name="stats_fields">  
  3. <lst name="price">  
  4. <double name="min">27.77</double>  
  5. <double name="max">39.99</double>  
  6. <double name="sum">97.86999999999999</double>  
  7. <long name="count">3</long>  
  8. <long name="missing">0</long>  
  9. <double name="sumOfSquares">3276.9851000000003</double>  
  10. <double name="mean">32.62333333333333</double>  
  11. <double name="stddev">6.486118510583508</double>  
  12. </lst>  
  13. </lst>  
  14. </lst>  

检查拼写错误

[html]  view plain copy
  1. <searchComponent name="<strong>spellcheck</strong>" class="solr.<strong>SpellCheckComponent</strong>">  
  2. <lst name="spellchecker">  
  3. <str name="name">default</str>  
  4. <str name="field">name</str>  
  5. <str name="spellcheckIndexDir">./<strong>spellchecker</strong></str><!-- 目录等同于索引目录-->  
  6. <str name="buildOnCommit">true</str>  
  7. </lst>  
  8. </searchComponent>  
  9. <requestHandler name="standard" class="solr.SearchHandler"  
  10. default="true">  
  11. <arr name="last-components">  
  12. <str><strong>spellcheck</strong></str>  
  13. </arr>  
  14. </requestHandler>  

http://localhost:8983/solr/spell?q=name:(other boak)&spellcheck=true&spellcheck.collate=true

[html]  view plain copy
  1. <lst name="spellcheck">  
  2. <lst name="suggestions">  
  3. <lst name="othar">  
  4. <int name="numFound">1</int>  
  5. <int name="startOffset">6</int>  
  6. <int name="endOffset">11</int>  
  7. <arr name="suggestion">  
  8. <str>other</str>  
  9. </arr>  
  10. </lst>  
  11. <lst name="boak">  
  12. <int name="numFound">1</int>  
  13. <int name="startOffset">12</int>  
  14. <int name="endOffset">16</int>  
  15. <arr name="suggestion">  
  16. <str>book</str>  
  17. </arr>  
  18. </lst>  
  19. <str name="collation">name:(other book)</str>  
  20. </lst>  
  21. </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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值