zoukankan      html  css  js  c++  java
  • Solr -- Solr Facet 1

    一、Facet介绍

    solr facet 是solr搜索的一大特色,facet不好翻译,有说是垂直搜索,有说是分片搜索,但都不是很好,还是懒得翻译了,就叫facet ,具体功能看下面的例子意会吧。

    比如你上淘宝,输入“笔记本”进行搜索,就会出现品牌分类,价格范围等分类,这个就叫facet了。这个例子也许好不是那么准确的描述facet,不过基本上就是这个意思。对输入关键字后搜索出来的结果再进行分类。


    二、 Facet查询

    进行Facet查询需要在请求参数中加入”facet=on”或者”facet=true”只有这样Facet组件才起作用.

    1. Field Facet

    Facet字段通过在请求中加入”facet.field”参数加以声明,如果需要对多个字段进行Facet查询,那么将该参数声明多次.比如

    http://localhost:8983/solr/select?q=联想&facet=on&facet.field=cpu&facet.field=videoCard

    查询返回

    Xml代码 收藏代码

    1. <lst name="facet_counts">
    2. <lst name="facet_queries"/>
    3. <lst name="facet_fields">
    4. <lst name="cpu">
    5. <int name="Intel 酷睿2双核 T6600">48</int>
    6. <int name="Intel 奔腾双核 T4300">28</int>
    7. <int name="Intel 酷睿2双核 P8700">18</int>
    8. <int name="Intel 酷睿2双核 T6570">11</int>
    9. <int name="Intel 酷睿2双核 T6670">11</int>
    10. <int name="Intel 奔腾双核 T4400">9</int>
    11. <int name="Intel 酷睿2双核 P7450">9</int>
    12. <int name="Intel 酷睿2双核 T5870">8</int>
    13. <int name="Intel 赛扬双核 T3000">7</int>
    14. <int name="Intel 奔腾双核 SU4100">6</int>
    15. <int name="Intel 酷睿2双核 P8400">6</int>
    16. <int name="Intel 酷睿2双核 SU7300">5</int>
    17. <int name="Intel 酷睿 i3 330M">4</int>
    18. </lst>
    19. <lst name="videoCard">
    20. <int name="ATI Mobility Radeon HD 4">63</int>
    21. <int name="NVIDIA GeForce G 105M">24</int>
    22. <int name="NVIDIA GeForce GT 240M">21</int>
    23. <int name="NVIDIA GeForce G 103M">8</int>
    24. <int name="NVIDIA GeForce GT 220M">8</int>
    25. <int name="NVIDIA GeForce 9400M G">7</int>
    26. <int name="NVIDIA GeForce G 210M">6</int>
    27. </lst>
    28. </lst>
    29. <lst name="facet_dates"/>
    30. </lst>

    各个Facet字段互不影响,且可以针对每个Facet字段设置查询参数.以下介绍的参数既可以应用于所有的Facet字段,也可以应用于每个单独的Facet字段.应用于单独的字段时通过

    f.字段名.参数名=参数值

    这种方式调用.比如facet.prefix参数应用于cpu字段,可以采用如下形式

    f.cpu.facet.prefix=Intel


    三、facet 参数

    facet的参数见solr官方wiki  http://wiki.apache.org/solr/SimpleFacetParameters

    说明:

    搜索结果按照Facet的字段分组并统计

    facet 参数字段要求

    字段必须被索引

    #.field Facet

    facet=on 或 facet=true

    1.facet.field 

    分组的字段

    2.facet.prefix

    表示Facet字段前缀

    3.facet.limit

    Facet字段返回条数

    4.facet.offict

    开始条数,偏移量,它与facet.limit配合使用可以达到分页的效果

    5.facet.mincount

    Facet字段最小count,默认为0

    6.facet.missing

    如果为on或true,那么将统计那些Facet字段值为null的记录

    7.facet.method

    取值为enum或fc,默认为fc, fc表示Field Cache

    8.facet.enum.cache.minDf

    当facet.method=enum时,参数起作用,文档内出现某个关键字的最少次数

    例:

    &facet=on

    &facet.field=city_id

    &facet.field=address

    http://localhost:8983/solr/select/?q=*:*&indent=on&facet=on&facet.field=unit_price&facet.field=developer_id

    返回结果facet_counts:

    Xml代码 收藏代码

    1. <lst name="facet_counts">
    2. <lst name="facet_queries"/>
    3. <lst name="facet_fields">
    4. <lst name="unit_price">
    5. <int name="9100.0">2</int>
    6. <int name="1100.0">1</int>
    7. </lst>
    8. <lst name="developer_id">
    9. <int name="101">2</int>
    10. <int name="100">1</int>
    11. </lst>
    12. </lst>
    13. <lst name="facet_dates"/>
    14. </lst>

    #.Date Facet

    日期类型的字段

    1.facet.date

    表示需要Data Facet的字段名

    2.facet.date.start

    起始时间.时间一般格式为"1995-12-31T12:59:59Z"

    另外可以使用"NOW","YEAR","MONTH"等

    3.facet.date.end

    结束时间

    4.facet.date.gap

    时间间隔

    5.facet.date.hardend

    true|false

    6.facet.date.other

    before|after|between|none|all 默认为none

    before会对start之前的值做统计

    after会对end之后的值做统计

    between会对start至end之间的值做统计,如果hardend为true的话,那么改值就是各个时间段统计值的和

    none 表示该项禁用

    all 表示before,after,all都会统计

    例:

    $facet=on

    &facet.date=date

    &facet.date.start=2009-1-1T0:0:0Z

    &facet.date.end=2010-1-1T0:0:0Z

    &facet.date.gap=;1MONTH

    &facet.date.other=all

    7.facet.date.include

    lower|upper|edge|outer|all

    #.Facet Query

    facet.query 可以对任意的字段进行筛选

    例:

    &facet=on

    &facet.query=date:[2009-1-1T0:0:0Z TO 2010-1-1T0:0:0Z]

  • 相关阅读:
    js setTimeout深度递归后完成回调
    [Err]1267
    YII数据库操作中打印sql
    Creating a web server in pure C(c/c++ 写web server)
    lighttpd 介绍及安装
    HDU 1003 Max Sum
    2014-8-10 掉落不简单
    最全SpringMVC具体演示样例实战教程
    Android 之 资源文件的介绍及使用
    我的创业劲儿,无可阻挡-JAVA学院张孝伟
  • 原文地址:https://www.cnblogs.com/wych/p/4097853.html
Copyright © 2011-2022 走看看