`
ynial
  • 浏览: 225759 次
  • 来自: ...
社区版块
存档分类
最新评论

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

    博客分类:
  • php
阅读更多
关于solr的faceting 有很多中处理方案;

比较常用有

faceting text
faceting date
faceting query


模拟一个简单的需求:

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


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



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

相应片段
<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);

分享到:
评论

相关推荐

    Solr和ElasticSearch全文检索客户端代码

    包括Solr和ElasticSerch的增删改查客户端Java代码

    solr入门java工程

    华为 fusioninsight solrtest solrcloud java客户端测试

    solarium, PHP Solr客户端库.zip

    solarium, PHP Solr客户端库 Solarium PHP客户端库什么是 Solarium?Solarium是一个PHP客户端库,可以精确地模型Solr概念。 它的他多个cics库只处理与Solr的通信,因这里a 也使用一个文档化的API处理所有复杂的roo...

    Laravel-4-Solr:Apache Solr简单查询客户端

    "require": {"laravel/framework": "4.1.*","davispeixoto/laravel-4-solr": "dev-master"}接下来,从终端更新Composer: composer update此操作完成后,仍在终端运行: php artisan config:publish davispeixoto/...

    已编译版本solr-8.11.2.tgz

    他的主要特性包括:高效,灵活的缓存功能,垂直搜索功能,高亮下试搜索结果,通过索引复制来提高可用性,提供一套强大的data schema 来定义字段,类型和设置文本分析,提供基于web的管理界面等。

    Solr高级搜索+tomcat整合服务器

    Solr如何进行索引和搜索 ...搜索:客户端(可以是浏览器可以是java程序)发送get请求到solr服务器,请求solr服务器给它响应一个结果文档(xml、json),程序员拿到这些文档就可以对其进行解析。进行视图渲染。

    php_solr.dll ,php5.3版本

    php5.3版本的php_solr.dll哦,很难找到的哦

    solr 企业搜索引擎教程

     后台缓存热启:当一个新的搜索器被打开时,可配置的搜索将它热启,避免第一个结果慢 下来,当热启时,当前搜索器处理目前的请求(???)。  后台自动热启:当前搜索器缓存中最常访问的项目在新的搜索器中再次生成,能够在...

    SolrClient:Solr客户端

    Composer的Solr php客户端 使用 CURL 访问 Solr API #lib Client.php 这是我的工作本写的

    使用mahout机器学习改进solr查询结果

    使用mahout机器学习改进solr查询结果

    Solr分组统计

    演示了怎样使用easysolr.net开发facet功能,怎样模糊查询,精确查询。

    solr.war包solr.war包solr.war包solr.war包solr.war包

    solr.warsolr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包...

    solr配置搜索引擎平台

    solr配置搜索引擎平台 一、 SOLR搭建企业搜索平台 二.... 三,,,,

    solr4tcl:Apache Solr的轻量级Tcl客户端界面

    solr4tcl 一个轻量级客户界面到 。 该库由单个文件组成。 solr4tcl使用Tcl内置软件包http向发送请求并获得响应。 该库需要软件包tdom。 界面 该库具有1个TclOO类Solr_Request。 提供以下内容: 简单的搜索界面 ...

    php_solr.dll

    windows环境php5.5的php_solr.dll

    ES和solr搜索方案对比

    ES和solr都是基于Lucence的搜索框架,文档比较2中方案适合的不同场景和优劣

    Solr搜索引擎

    Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口。用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引;也可以通过Http Get操作提出查找请求,并得到XML格式的...

    Solr学习笔记(三)Solr客户端开发实例

    NULL 博文链接:https://kylinsoong.iteye.com/blog/714511

    企业级搜索引擎solr教程

    tomcat7下实现solr4.3的部署与配置,配置中文服务器。通过solrj实现索引的创建,修改,删除,查询。并实现httpclienct创建、修改索引,检索信息等。

Global site tag (gtag.js) - Google Analytics