Solr - 如何“分组"和“限制"? [英] Solr - how to "group by" and "limit"?
问题描述
假设我从我的数据库中索引了以下内容:
Say I indexed the following from my database:
======================================
| Id | Code | Description |
======================================
| 1 | A1 | Hello world |
| 2 | A1 | Hello world 123 |
| 3 | A1 | World hello hi |
| 4 | B1 | Quick fox jumped |
| 5 | B1 | Lazy dog |
...
进一步,假设用户搜索hello",它应该返回记录 1、2 和 3.有没有办法让 Solr分组"Code
字段并应用限制(比如说,10 条记录)?我有点在寻找 GROUP BY 和 LIMIT 的 SQL 对应物.
Further, say the user searches for "hello", which should return records 1, 2, and 3. Is there a way to make Solr "group by" the Code
field and apply a limit (say, 10 records)? I'm somewhat looking for a SQL counterpart of GROUP BY and LIMIT.
此外,当它执行此分组依据"时,我希望它选择最相关的文档并使用该文档的 Description
字段作为返回的一部分.
Also, when it does this "group by", I want it to choose the most relevant document and use that document's Description
field as part of the return.
当然,我可以让 Solr 将所有内容返回到我的应用程序,我可以操纵结果来执行 GROUP BY 和 LIMIT.如果可能,我宁愿不这样做.
Of course, I could just have Solr return everything to my application and I can manipulate the results to do the GROUP BY and LIMIT. I'd rather not do this if possible.
推荐答案
查看 field collapsing,可在索尔 4.0.根据相关性对组进行排序:group.sort=score desc
.
Have a look at field collapsing, available in Solr 4.0. Sorting groups on relevance: group.sort=score desc
.
这篇关于Solr - 如何“分组"和“限制"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!