设为首页 收藏本站
查看: 810|回复: 0

[经验分享] Solr学习笔记之5、Component(组件)与Handler(处理器)学习

[复制链接]

尚未签到

发表于 2015-7-18 10:31:41 | 显示全部楼层 |阅读模式
  Solr学习笔记之5、Component(组件)与Handler(处理器)学习
  一、搜索篇
  拼写检查(spellCheck)
  作用:用来检查用户输入的检索内容是否存在,如果不存在则给它提示出相近或相似的内容
  配置:在solrconfig.xml中配置如下


DSC0000.gif DSC0001.gif


  
  
default  
  
Title  
  
spellchecker  
  
  
true  
  

  
  
  
false  
false  
  
1  
  
  
spellcheck  
  

View Code  举例:
  http://localhost:8080/solr/collection1/spell?q=Title:tests&spellcheck=true
  请求结果如下图:








0
119





1
6
11
0


test
6



false

Title:test
6

test





View Code  检索建议(suggest)
  作用:检索建议则是用户输入某个检索条件后,会立刻友好的给出一系列提示内容,并推荐首个出现的相似的词,作为推荐词。如果这个条件想关的东西一个都没有,则不会提示,所以某种意义上来说,可以在用户输入检索条件时使用suggest,而在点击完搜索时,使用拼写检查,二者结合给可以用户带来比较好的用户体验。
  配置:在solrconfig.xml中配置如下





  

text

suggest
org.apache.solr.spelling.suggest.Suggester
org.apache.solr.spelling.suggest.tst.TSTLookup
Title
0.0001

freq
true
true




true
suggest
10
true
false
true



suggest


View Code  举例:
  http://localhost:8080/solr/collection1/suggest?wt=xml&indent=true&spellcheck=true&spellcheck.q=tes
  http://localhost:8080/solr/collection1/suggest?q=Title:tes&wt=xml&indent=true
  该请求执行结果如下:








0
1




103-
test


test



View Code  分层查询(facet)
  作用:Facet是solr的高级搜索功能之一,可以给用户提供更友好的搜索体验。在搜索关键字的同时,能够按照Facet的字段进行分组并统计。Facet是Solr默认集成的一个组件。
  配置:无需额外配置
  特别说明:
  1、适宜被Facet的字段
    一般代表了实体的某种公共属性,如商品的分类、商品的制造厂家、书籍的出版商等等。
  2、Facet字段的要求
    Facet的字段必须被索引,一般来说该字段无需分词,无需存储。
         无需分词是因为该字段的值代表了一个整体概念,另外该字段的值无需进行大小写转换等处理,保持其原貌即可。
         无需存储是因为一般而言用户所关心的并不是该字段的具体值,而是作为对查询结果进行分组的一种手段,用户一般会沿着这个分组进一步深入搜索。
  3、特殊情况
         对于一般查询而言,分词和存储都是必要的。比如CPU类型”Intel 酷睿2双核 P7570”, 拆分成”Intel”,”酷睿”,”P7570”这样一些关键字并分别索引,可能提供更好的搜索体验。但是如果将CPU作为Facet字段,最好不进行分词,这样就造成了矛盾,解决方法为,将CPU字段设置为不分词不存储,然后建立另外一个字段为它的COPY,对这个COPY的字段进行分词和存储。
  参数说明:
  Field Facet :Facet字段通过在请求中加入facet.field参数加以声明,如果需要对多个字段进行Facet查询,那么将该参数声明多次。
  各个Facet字段互不影响,且可以针对每个Facet字段设置查询参数。形式为:f.字段名.参数名=参数值,字段为为空代表应用于所有facet字段
  举例:
  http://localhost:8080/solr/collection1/select/?q=*:*&indent=on&facet=on&facet.field=ArticleTypeName&facet.field=EditorialOfficeName
  该请求执行结果如下:








0
1

on
on
ArticleId:5

ArticleTypeName
EditorialOfficeName





2
5
false
2
content five
2014-03-24T16:00:00Z
test title 5 five
体育
燕赵都市报
1463443978500177920






1
0


1
0
0






View Code  Date Facet :Solr为日期字段提供了更为方便的日期查询统计方式,字段的类型必须是DateField(或其子类型)。
  需要注意的是使用Date Facet时,字段名、起始时间、结束时间、时间间隔这4个参数都必须提供。
  举例:
  http://localhost:8080/solr/collection1/select/?q=*:*&indent=on&facet=on&facet.date=CreateDate&facet.date.start=2014-3-10T0:0:0Z&facet.date.end=2014-3-26T0:0:0Z&facet.date.gap=%2B1DAY&facet.date.other=all
  该请求执行结果如下:








0
39

2014-3-10T0:0:0Z
on
on
*:*
CreateDate
all
+1DAY
2014-3-26T0:0:0Z




2
5
false
2
content five
2014-03-24T16:00:00Z
test title 5 five
体育
燕赵都市报
1463443978500177920


2
6
false
3
content six
2014-03-25T16:00:00Z
test title 6 six
体育
北京晚报
1463443978552606720


1
7
false
1
content seven
2014-03-26T16:00:00Z
test title 7 seven
财经
光明日报
1463443978554703872


1
8
false
2
content eight
2014-03-27T16:00:00Z
test title 8 eight
财经
燕赵都市报
1463443978556801024


1
9
false
3
content nine
2014-03-28T16:00:00Z
test title 9 nine
财经
北京晚报
1463443978558898176


1
10
false
2
content ten
2014-03-23T16:00:00Z
test title 10 ten
财经
燕赵都市报
1463443978559946752







0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
+1DAY
2014-03-10T00:00:00Z
2014-03-26T00:00:00Z
0
3
3





View Code  Facet Query :Facet Query利用类似于filter query的语法提供了更为灵活的Facet,通过facet.query参数,可以对任意字段进行筛选。
  举例:
  http://localhost:8080/solr/collection1/select/?q=*:*&indent=on&facet=on&facet.query=CreateDate:[2014-3-24T0:0:0Z TO 2014-3-26T0:0:0Z]
  该请求执行结果如下:








0
1

on
on
CreateDate:[2014-3-24T0:0:0Z TO 2014-3-26T0:0:0Z]
*:*




2
5
false
2
content five
2014-03-24T16:00:00Z
test title 5 five
体育
燕赵都市报
1463443978500177920


2
6
false
3
content six
2014-03-25T16:00:00Z
test title 6 six
体育
北京晚报
1463443978552606720


1
7
false
1
content seven
2014-03-26T16:00:00Z
test title 7 seven
财经
光明日报
1463443978554703872


1
8
false
2
content eight
2014-03-27T16:00:00Z
test title 8 eight
财经
燕赵都市报
1463443978556801024


1
9
false
3
content nine
2014-03-28T16:00:00Z
test title 9 nine
财经
北京晚报
1463443978558898176


1
10
false
2
content ten
2014-03-23T16:00:00Z
test title 10 ten
财经
燕赵都市报
1463443978559946752




2






View Code  Range Facet 举例:范围查询统计
  http://localhost:8080/solr/collection1/select/?q=*:*&indent=on&facet=on&facet.range=CreateDate&facet.range.start=2014-03-24T16:00:00Z&facet.range.end=2014-03-26T16:00:00Z&facet.range.gap=%2B1DAY








0
2

on
on
*:*
2014-03-24T16:00:00Z
CreateDate
+1DAY
2014-03-26T16:00:00Z




2
5
false
2
content five
2014-03-24T16:00:00Z
test title 5 five
体育
燕赵都市报
1463443978500177920


2
6
false
3
content six
2014-03-25T16:00:00Z
test title 6 six
体育
北京晚报
1463443978552606720


1
7
false
1
content seven
2014-03-26T16:00:00Z
test title 7 seven
财经
光明日报
1463443978554703872


1
8
false
2
content eight
2014-03-27T16:00:00Z
test title 8 eight
财经
燕赵都市报
1463443978556801024


1
9
false
3
content nine
2014-03-28T16:00:00Z
test title 9 nine
财经
北京晚报
1463443978558898176


1
10
false
2
content ten
2014-03-23T16:00:00Z
test title 10 ten
财经
燕赵都市报
1463443978559946752









1
1

+1DAY
2014-03-24T16:00:00Z
2014-03-26T16:00:00Z




View Code  分组统计:
  分组示例(group):
  http://localhost:8080/solr/collection1/select?q=*:*&wt=xml&indent=true&group=true&group.field=TypeId&group.ngroups=true
  统计示例(stats):
  httphttp://localhost:8080/solr/select?q=*:*&stats=true&stats.field=Price&rows=10&indent=true
  该请求执行结果如下:








0
32

true
Price
true
*:*
10




2
6
6.0
false
3
content six
2014-03-25T16:00:00Z
test title 6 six
体育
北京晚报
1463715628722421760


1
7
7.0
false
1
content seven
2014-03-26T16:00:00Z
test title 7 seven
财经
光明日报
1463715628782190592


1
8
8.0
false
2
content eight
2014-03-27T16:00:00Z
test title 8 eight
财经
燕赵都市报
1463715628784287744


1
9
9.0
false
3
content nine
2014-03-28T16:00:00Z
test title 9 nine
财经
北京晚报
1463715628786384896


1
10
10.0
false
2
content ten
2014-03-23T16:00:00Z
test title 10 ten
财经
燕赵都市报
1463715628788482048





6.0
10.0
5
0
40.0
330.0
8.0
1.5811388300841898





View Code  注:统计字段应为数字类型,如果为字符串类型则统计结果不全。
  自动聚合(clustering)
  作用:能够把检索到的内容自动分类。
  配置:在solrconfig.xml中配置如下








lingo
org.carrot2.clustering.lingo.LingoClusteringAlgorithm
clustering/carrot2



stc
org.carrot2.clustering.stc.STCClusteringAlgorithm



kmeans
org.carrot2.clustering.kmeans.BisectingKMeansClusteringAlgorithm




true
true
name
id
features
true
false
edismax

text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4

*:*
10
*,score


clustering



View Code  举例:
  http://localhost:8080/solr/clustering?q=*:*&rows=10&LingoClusteringAlgorithm.desiredClusterCountBase=20
  该请求执行结果如下:








0
12



2
5
false
2
content five
2014-03-24T16:00:00Z
test title 5 five
体育
燕赵都市报
1463443978500177920
0.42292467


2
6
false
3
content six
2014-03-25T16:00:00Z
test title 6 six
体育
北京晚报
1463443978552606720
0.42292467


1
7
false
1
content seven
2014-03-26T16:00:00Z
test title 7 seven
财经
光明日报
1463443978554703872
0.42292467


1
8
false
2
content eight
2014-03-27T16:00:00Z
test title 8 eight
财经
燕赵都市报
1463443978556801024
0.42292467


1
9
false
3
content nine
2014-03-28T16:00:00Z
test title 9 nine
财经
北京晚报
1463443978558898176
0.42292467


1
10
false
2
content ten
2014-03-23T16:00:00Z
test title 10 ten
财经
燕赵都市报
1463443978559946752
0.42292467





Other Topics

0.0
true

5
6
7
8
9
10




View Code  注意事项:
  使用该功能需要在%solr_home%/lib目录下添加扩展包:
  从下载的solr项目中将
  dist/apache-solr-clustering-*.jar,
  contrib/clustering目录下的所有jar包,
  contrib/clustering/downloads 目录下的所有jar包
  加入到%solr_home%/lib中。
  简单方法:直接拷贝源码中 dist 及 contrib 文件夹到 %solr_home%/collection1\conf中即可。
  相似匹配(MoreLikeThis)
  作用:查找相似的document
  配置:在solrconfig.xml中配置如下



  


  参数说明:
mlt:在查询时,打开/关闭 MoreLikeThisComponent 的布尔值。 (true|false)
mlt.count:可选。每一个结果要检索的相似文档数。 (> 0)
mlt.fl:用于创建 MLT 查询的字段。 模式中任何被储存的或含有检索词向量的字段。
mlt.maxqt:可选。查询词语的最大数量。由于长文档可能会有很多关键词语,这样 MLT 查询可能会很大,从而导致反应缓慢或可怕的 TooManyClausesException,该参数只保留最关键的词语。 (> 0)
  举例:
  http://localhost:8080/solr/mlt?q=ArticleId:5&mlt.true&mlt.fl=Title&mlt.mintf=1&mlt.mindf=1
  该请求的意思是查找 ArticleId为 5 的 document ,然后返回与此 document 在 Title 字段上相似的其他 document。需要注意的是 mlt.fl 中的 field 的 termVector=true 才有效果
  该请求执行结果如下:








0
34



2
5
false
2
content five
2014-03-24T16:00:00Z
test title 5 five
体育
燕赵都市报
1463443978500177920




2
6
false
3
content six
2014-03-25T16:00:00Z
test title 6 six
体育
北京晚报
1463443978552606720


1
7
false
1
content seven
2014-03-26T16:00:00Z
test title 7 seven
财经
光明日报
1463443978554703872


1
8
false
2
content eight
2014-03-27T16:00:00Z
test title 8 eight
财经
燕赵都市报
1463443978556801024


1
9
false
3
content nine
2014-03-28T16:00:00Z
test title 9 nine
财经
北京晚报
1463443978558898176


1
10
false
2
content ten
2014-03-23T16:00:00Z
test title 10 ten
财经
燕赵都市报
1463443978559946752



View Code  高亮显示
  作用:将结果中与搜索关键词匹配的地方高亮显示。
  配置:无需额外配置
  参数说明:
  hl 是否启用高亮显示 (true|false)
  hl.fl 要进行高亮显示的字段,如需对多个字段显示用逗号分隔(hl.fl=name,name2,name3)
  hl.simple.pre 高亮显示前缀标签 (默认)
  hl.simple.post 高亮显示后缀标签(默认)
  举例:
  http://localhost:8080/solr/select?q=ArticleId:9&start=0&rows=10&hl=true&hl.fl=Title
  该请求执行结果如下:








0
2

0
ArticleId:9
Title
true
10




1
9
false
3
content nine
2014-03-28T16:00:00Z
test title 9 nine
财经
北京晚报
1463443978558898176






test title 9 nine





View Code  
  二、索引篇
  更新索引(update)
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-87911-1-1.html 上篇帖子: Solr配置与简单Demo[转] 下篇帖子: Solr简单部署
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表