solr 分面搜索(转载)

原文地址:http://blog.csdn.net/bingduanlbd/article/details/52199347

分面搜索(Faceting)基于索引词项对搜索结果进行分类,同时返回每个分类对应的文档数。用户可以可以分类缩小结果范围。下图是一个结果汇总的例子:

Amazon的搜索也提供了非常优秀的分面及相应的过滤:

环境

Solr的发行版自带了一些很好的例子,使用这些例子研究Solr的各种特性非常合适。我们这里使用Solr自带的techproducts索引作为例子。启动solr

solr -e techproducts -p 8984

  • 1

    通用参数

  • facet: true/false 是否开启faceting计数
  • facet.query: 指定计数防暑,语法跟Solr正常的查询一致。默认情况上检查字段唯一term并返回计数,相当于count(distinct field)

    Field-value Faceting

    主要参数:

  • facet.field: 指定字段

    查询:

    http://localhost:8984/solr/techproducts/select?q=price:[0 TO 400]&fl=id,name,price&facet=true&facet.field=cat

  • 1

    Range Faceting

    主要参数:

  • facet.range: 指定字段
  • facet.range.start:区间开始值
  • facet.range.end: 区间结束值
  • facet.range.gap:步长

    http://localhost:8984/solr/techproducts/select?q=price:[0 TO 4000]&fl=id,name,price&facet=true&facet.field=cat&facet.range=price&f.price.facet.range.start=0.0&f.price.facet.range.end=1000.0&f.price.facet.range.gap=100

  • 1

    Interval Faceting

    主要参数:

  • facet.interval:指定字段
  • facet.interval.set: 间隔设置

    http://localhost:8984/solr/techproducts/select?q=*:*&fl=id,name,price&facet=true&facet.field=cat&facet.interval=price&f.price.facet.interval.set=[0,10]&f.price.facet.interval.set=(10,100]

  • 1

    参考资料

    官方文档: 
    https://cwiki.apache.org/confluence/display/solr/Faceting

posted on 2017-08-30 00:21  张小贱1987  阅读(328)  评论(0编辑  收藏  举报

导航