Solr - 如何“由...分组”和“限制”? [英] Solr - how to "group by" and "limit"?

查看:130
本文介绍了Solr - 如何“由...分组”和“限制”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我从我的数据库索引以下内容:

  ============== ======================== 
| Id |代码|说明|
======================================
| 1 | A1 |你好世界|
| 2 | A1 |你好世界123 |
| 3 | A1 |世界你好嗨|
| 4 | B1 |快狐跳了|
| 5 | B1 |懒狗|
...

此外,假设用户搜索hello,应该返回记录1,2和3.有没有办法让Solrgroup by的 Code 字段并应用限制(比如10条记录)?我有点期待GROUP BY和LIMIT的SQL对手。



另外,当它使用group by时,我希望它选择最相关的文档并使用该文档的 Description 字段作为返回的一部分。



当然,我可以让Solr返回所有内容到我的应用程序,我可以操纵结果做GROUP BY和LIMIT。如果可能的话,我宁愿不这样做。 apache.org/solr/FieldCollapsing\">折叠,可在Solr 4.0中找到。按相关性对组进行排序: group.sort = score desc


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

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.

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.

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.

解决方案

Have a look at field collapsing, available in Solr 4.0. Sorting groups on relevance: group.sort=score desc.

这篇关于Solr - 如何“由...分组”和“限制”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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