xuyaxiu 发表于 2015-11-12 09:41:52

Solr学习总结-Facet

  返回查询集合中指定field的统计情况,例如找到city一样的文档数目:
  加入文档<add>
<doc>
<field name=&quot;id&quot;>1</field>
<field name=&quot;name&quot;>Company 1</field>
<field name=&quot;city&quot;>New York</field>
</doc>
<doc>
<field name=&quot;id&quot;>2</field>
<field name=&quot;name&quot;>Company 2</field>
<field name=&quot;city&quot;>New Orleans</field>
</doc>
<doc>
<field name=&quot;id&quot;>3</field>
<field name=&quot;name&quot;>Company 3</field>
<field name=&quot;city&quot;>New York</field>
</doc>
</add>查询:http://localhost:8983/solr/select?q=name:company&facet=true&facet.field=city&facet.mincount=1
  结果:<lst name=&quot;facet_fields&quot;>
<lst name=&quot;city&quot;>
<int name=&quot;New York&quot;>2</int>
<int name=&quot;New Orleans&quot;>1</int>
</lst>
</lst>
  



获得指定日期范围内的文档:添加的文档<add>
<doc>
<field name=&quot;id&quot;>1</field>
<field name=&quot;title&quot;>Lucene or Solr ?</field>
<field name=&quot;added&quot;>2010-12-06T12:12:12Z</field>
</doc>
<doc>
<field name=&quot;id&quot;>2</field>
<field name=&quot;title&quot;>My Solr and the rest of the world</field>
<field name=&quot;added&quot;>2010-12-07T11:11:11Z</field>
</doc>
<doc>
<field name=&quot;id&quot;>3</field>
<field name=&quot;title&quot;>Solr recipes</field>
<field name=&quot;added&quot;>2010-11-30T12:12:12Z</field>
</doc>
<doc>
<field name=&quot;id&quot;>4</field>
<field name=&quot;title&quot;>Solr cookbook</field>
<field name=&quot;added&quot;>2010-11-29T12:12:12Z</field>
</doc>
</add>查询语句:分别指定时间的field,开始时间和结束时间,gap指定时间的划分,结果显示时间区间的数目。  http://localhost:8983/solr/select?q=*:*&rows=0&facet=true&facet.date=added&facet.date.start=NOW/DAY-30DAYS&facet.date.end=NOW/DAY&facet.date.gap=&#43;7DAY


  结果:<int name=&quot;2010-11-08T00:00:00Z&quot;>0</int>
<int name=&quot;2010-11-15T00:00:00Z&quot;>0</int>
<int name=&quot;2010-11-22T00:00:00Z&quot;>0</int>
<int name=&quot;2010-11-29T00:00:00Z&quot;>2</int>
<int name=&quot;2010-12-06T00:00:00Z&quot;>2</int>


  得到数值范围的数目,和时间范围一样:
  http://localhost:8983/solr/select?q=*:*&rows=0&facet=true&facet.range=price&facet.range.start=0&facet.range.end=400&facet.range.gap=100


  


  自定义区间,而不是连续区间的划分:
  http://localhost:8983/solr/select?q=name:car&facet=true&facet.query=price:&facet.query=price:


  
  移除过滤:
  http://localhost:8983/solr/select?q=name:company&facet=true&fq={!tag=stateTag}state:&quot;New York&quot;&facet.field={!ex=stateTag}city&facet.field={!ex=stateTag}state


  fq={!tag=stateTag}state:&quot;New York&quot;:只显示state为&quot;New York&quot;的结果。


  facet.field={!ex=stateTag}city:移除stateTag的过滤后,在结果集中,对city域进行统计。
  
  命名facet结果集:
  http://localhost:8983/solr/select?q=name:company&facet=true&fq={!tag=stateTag}state:Luiziana&facet.field={!key=stateFiltered}city&facet.field={!ex=stateTag key=stateUnfiltered}state


  acet.field={!key=stateFiltered}city:命名city为stateFiltered,并按照前面的过滤


  


  对facet结果集进行排序按照字典序排序,默认是按数量排序:
  http://localhost:8983/solr/select?q=name:house&facet=true&facet.field=city&facet.sort=index


  
  实现自动提示:前缀为so的都会显示,一般不需要分词
  http://localhost:8983/solr/select?q=*:*&rows=0&facet=true&facet.field=title_autocomplete&facet.prefix=so


  
  得到某一个域中不含某词的facet,也可以是不含某个域:
  http://localhost:8983/solr/select?q=title:solr&facet=true&facet.query=!price:[* TO *]


  
  指定结果集数目的统计facet:-1表示所有
  http://localhost:8983/solr/select?q=title:solr&facet=true&facet.field=category&facet.limit=-1


  


  指定不同域的facet的限制数目:一个没限制,一个限制10
  http://localhost:8983/solr/select?q=name:car&facet=true&facet.field=category&facet.field=manufacturer&f.category.facet.limit=-1&f.manufacturer.facet.limit=10



版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: Solr学习总结-Facet