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

查看:24
本文介绍了如何使用 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 有没有可能做到这一点?

Any possibility of this with Solr?

推荐答案

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

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

你应该得到这样的回报:

You should get something back like this:

<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>

查看维基了解更多信息.分面是 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天全站免登陆