首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

Solr 学习(七) —- Solr Facet

2012-10-08 
Solr 学习(7) —- Solr Facet?一、Facet介绍solr facet 是solr搜索的一大特色,facet不好翻译,有说是垂直搜索

Solr 学习(7) —- Solr Facet

?

一、Facet介绍

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

?

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

?


Solr 学习(七) —- Solr Facet


?

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

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

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

?

查询返回

?

<lst name="facet_counts"><lst name="facet_queries"/><lst name="facet_fields"><lst name="cpu"><int name="Intel 酷睿2双核 T6600">48</int><int name="Intel 奔腾双核 T4300">28</int><int name="Intel 酷睿2双核 P8700">18</int><int name="Intel 酷睿2双核 T6570">11</int><int name="Intel 酷睿2双核 T6670">11</int><int name="Intel 奔腾双核 T4400">9</int><int name="Intel 酷睿2双核 P7450">9</int><int name="Intel 酷睿2双核 T5870">8</int><int name="Intel 赛扬双核 T3000">7</int><int name="Intel 奔腾双核 SU4100">6</int><int name="Intel 酷睿2双核 P8400">6</int><int name="Intel 酷睿2双核 SU7300">5</int><int name="Intel 酷睿 i3 330M">4</int></lst><lst name="videoCard"><int name="ATI Mobility Radeon HD 4">63</int><int name="NVIDIA GeForce G 105M">24</int><int name="NVIDIA GeForce GT 240M">21</int><int name="NVIDIA GeForce G 103M">8</int><int name="NVIDIA GeForce GT 220M">8</int><int name="NVIDIA GeForce 9400M G">7</int><int name="NVIDIA GeForce G 210M">6</int></lst></lst><lst name="facet_dates"/></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:

<lst name="facet_counts"><lst name="facet_queries"/><lst name="facet_fields"><lst name="unit_price"><int name="9100.0">2</int><int name="1100.0">1</int></lst><lst name="developer_id"><int name="101">2</int><int name="100">1</int></lst></lst><lst name="facet_dates"/></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]

相当棒的。博主

热点排行