我想做相当于这个SQL,但Solr作为我的数据存储.
SELECT
DISTINCT txt
FROM
my_table;
Run Code Online (Sandbox Code Playgroud)
什么语法会迫使Solr只给我不同的值?
http://localhost:8983/solr/select?q=txt:?????&fl=txt
Run Code Online (Sandbox Code Playgroud)
编辑:如此刻面的搜索似乎很合适,但正如我调查的那样,我意识到我只有一半的问题.
我的SQL查询应该已阅读...
SELECT
DISTINCT SUBSTR(txt,0,3)
FROM
my_table;
Run Code Online (Sandbox Code Playgroud)
Solr的任何可能吗?
Cra*_*lla 72
Faceting会为您提供包含字段的不同值的结果集.
例如
http://localhost:8983/solr/select/?q=*%3A*&rows=0&facet=on&facet.field=txt
Run Code Online (Sandbox Code Playgroud)
你应该得到这样的东西:
<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>
Run Code Online (Sandbox Code Playgroud)
查看Wiki以获取更多信息.Faceting是solr非常酷的一部分.请享用 :)
http://wiki.apache.org/solr/SimpleFacetParameters#Facet_Fields
注意:Faceting将显示索引值,即应用所有过滤器后的值.解决此问题的一种方法是使用copyfield方法,以便您可以创建txt字段的facet版本.这样,您的结果将显示原始值.
希望有所帮助..关于维基上可用的分面的大量文档.或者我写了一些屏幕截图..你可以在这里查看:
http://www.craftyfella.com/2010/01/faceting-and-multifaceting-syntax-in.html
使用带参数的 StatsComponentstats.calcdistinct
获取特定字段的不同值列表:
Solr 7 https://lucene.apache.org/solr/guide/7_7/the-stats-component.html
Solr 6 https://cwiki.apache.org/confluence/display/solr/The+Stats+Component
它还将为您提供不同值的计数。
stats.calcdistinct
可能从 4.7 开始可用。
http://wiki.apache.org/solr/StatsComponent
已过时,因为它不包括stats.calcdistinct
/select?stats=on&stats.field=region&rows=0&stats.calcdistinct=true
"stats":{
"stats_fields":{
"region":{
"min":"GB",
"max":"GB",
"count":20276,
"missing":0,
"distinctValues":["GB"],
"countDistinct":1}}}}
Run Code Online (Sandbox Code Playgroud)
在 facet 的情况下,您需要知道请求所有的计数,或者您将 facet.limit 设置为非常高的值并自己计算结果。此外,您需要一个字符串字段来使构面按照您在此处需要的方式工作。
归档时间: |
|
查看次数: |
76800 次 |
最近记录: |