solr faceting 搜索结果统计 php客户端

关于solr的faceting 有很多中处理方案;

比较常用有

faceting text
faceting date
faceting query


模拟一个简单的需求:

企业索引库中
[list]
[*]字段comCate 公司类型
[*]字段comSize 公司规模
[*]字段date 入库时间
[*]字段info 公司基本信息
[*]字段comName 公司名称
[/list]

业务:输入关键字 (在公司名称字段 + 公司基本信息)中检索、显示出相应的查询结果
并列出 结果中各种类型的公司个数 各种规模的公司个数
近一年来的入库公司个数 近两年来入库公司的个数 近5年来入库的个数

以上的业务处理完全可以使用faceting来实现;


关于solr搜索结果统计的具体实现【小例子】

【http://localhost:8044/solr/job/select/?q=*%3a*&version=2.2&start=0&rows=10&indent=on&facet=on&facet.field=comCate&f.comCate.facet.missing=on&f.comCate.facet.method=enum】

上面的url为solr的搜索查询命令

相应片段

<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">3</int>

<lst name="params">
[color=red]<str name="facet">on</str>[/color]
<str name="indent">on</str>
<str name="start">0</str>
<str name="q">*:*</str>
[color=red]<str name="f.comCate.facet.method">enum</str>
<str name="facet.field">comCate</str>
<str name="f.comCate.facet.missing">on</str>[/color]
<str name="rows">10</str>
<str name="version">2.2</str>
</lst>


</lst>

[list]

[color=red]<str name="facet">on</str>[/color]
打开facet(统计)
[color=red]<str name="facet.field">comCate</str>[/color]
统计字段为 comCate
[color=red]<str name="f.comCate.facet.missing">on</str>[/color]
貌似不处理空内容
[color=red]<str name="f.comCate.facet.method">enum</str>[/color]
统计方法枚举类型统计
[/list]
相应片段

<lst name="facet_counts">
<lst name="facet_queries"/>

<lst name="facet_fields">

<lst name="comCate">
<int name="民营公司">1721</int>
<int name="外资(欧美)">367</int>
<int name="外资(非欧美)">333</int>
<int name="合资(非欧美)">169</int>
<int name="合资(欧美)">141</int>
<int name="国企">130</int>
<int name="外企代表处">15</int>
<int>575</int>
</lst>
</lst>
<lst name="facet_dates"/>
</lst>


该应用为检索企业库 统计各个企业类型下有多少企业 类似sql中的 group by
\ count(*)

《solr1.4 enterprise search server》书中 第五章 141页 明细介绍!
---------------------

如果你使用php客户端来处理这个应用的话 在多统计的时候可能会出一些小罗乱:



$solr = new Apache_Solr_service('localhost', '8044', '/solr/ent');
$condition['q.op'] = 'OR';
$condition['sort']='date desc';
$condition['facet'] = 'true';
$condition['facet.mincount'] = '1';
[color=red]$condition['facet.field'] = 'comCate';
$condition['facet.field'] = 'comSize';[/color]
$condition['f.conCate.facet.missing'] = 'true';
$condition['f.conCate.facet.method'] = 'enum';
$condition['f.comSize.facet.missing'] = 'true';
$condition['f.comSize.facet.method'] = 'enum';
$q_str = "*:*";
r = $solr->search($q_str, $offset, 10, $condition);

上面的代码显然是数组的索引重复 、
【解决方案:】


[color=red]$condition['facet.field'] = 'comCate';
$condition['facet.field'] = 'comSize';[/color]
//修改成
[color=red]$condition['facet.field_1'] = 'comCate';
$condition['facet.field_2'] = 'comSize';[/color]
//继续修改 Apache/Solr/service.php文件 960行左右
// anywhere else the regex isn't expecting it
$queryString = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $queryString);
//在此添加下面代码即可
$queryString = preg_replace('/field_[0-9]{1}/', 'field', $queryString);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值