如何使用Solr选择不同的字段值? [英] How to select distinct field values using Solr?

查看:107
本文介绍了如何使用Solr选择不同的字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做与此SQL等效的操作,但以Solr作为我的数据存储.

I would like to do the equivalent of this SQL but with Solr as my data store.

SELECT
   DISTINCT txt
FROM
   my_table;

什么语法会迫使Solr只给我不同的值?

What syntax would force Solr to only give me distinct values?

http://localhost:8983/solr/select?q=txt:?????&fl=txt

因此,多面搜索似乎很合适,但是在我进行调查时,我意识到我只解决了一半的问题.

So faceted searching seems to fit, but as I investigated it, I realized I had only detailed half of the problem.

我的SQL查询应该已经读过...

My SQL query should have read...

SELECT
   DISTINCT SUBSTR(txt,0,3)
FROM
   my_table;

使用Solr可能吗?

推荐答案

Faceting将为您提供一个结果集,其中包含字段的不同值.

Faceting would get you a results set that contains distinct values for a field.

例如

http://localhost:8983/solr/select/?q=*%3A*&rows=0&facet=on&facet.field=txt

您应该像这样回来:

<response>
<responseHeader><status>0</status><QTime>2</QTime></responseHeader>
<result numFound="4" start="0"/>
<lst name="facet_counts">
 <lst name="facet_queries"/>
 <lst name="facet_fields">
  <lst name="txt">
        <int name="value">100</int>
        <int name="value1">80</int>
        <int name="value2">5</int>
        <int name="value3">2</int>
        <int name="value4">1</int>
  </lst>
 </lst>
</lst>
</response>

查看Wiki,以获取更多信息.刻面是Solr的一个非常酷的部分.享受:)

Check out the wiki for more information. Faceting is a really cool part of solr. Enjoy :)

http://wiki.apache.org/solr/SimpleFacetParameters#Facet_Fields

注意:构面将显示索引值,即在应用所有过滤器之后.解决此问题的一种方法是使用copyfield方法,以便可以创建txt字段的构面版本.这样您的结果将显示原始值.

Note: Faceting will show the indexed value, I.e. after all the filters have been applied. One way to get around this is to use the copyfield method, so that you can create a facet version of the txt field. THis way your results will show the original value.

希望有帮助..Wiki上有很多有关刻面的文档.或者我确实写了一些带屏幕截图的..您可以在这里查看:

Hope that helps.. Lots of documentation on faceting available on the wiki. Or I did write some with screen shots.. which you can check out here:

http://www.craftyfella.com/2010/01/faceting-and-multifaceting-syntax-in.html

这篇关于如何使用Solr选择不同的字段值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆