使用多个字段对 solr 搜索结果进行排序 (solrj)
我需要根据两个因素对从 apache solr 返回的结果进行排序:
我们的系统中存在由 solr 索引的三个实体(组、项目和数据集),并且在结果中我希望首先显示数据集,然后是项目,然后是小组;但我仍然希望它尊重每种类型的评分值。
因此,例如:结果将是
- 得分为 0.325 的
- 数据集 得分为 0.282 的
- 数据集 得分为 0.200 的数据集
- 得分为 0.298 的
- 项目 得分为 0.186 的
- 组 得分为 0.360 的
- 组 得分为 0.270
我正在 < strong>java 并使用 solrj 构建 solr 查询。问题是,当我尝试向 SolrQuery 对象添加 2 个排序字段时,它似乎只使用其中之一。此外,在 solr 文档中,没有任何内容来说明实体类型,但文档的 ID 以实体名称为前缀,因此我打算使用它。
如果有人对我如何实现这一目标有任何想法,我将不胜感激,因为我已经坚持了一段时间了!
提前致谢, -杰克。
I need to sort the results I get back from apache solr based on two factors:
There are three entities in our system that are indexed by solr (groups, projects and datasets) and in the results I want datasets to be displayed first, followed by projects and then groups; but I still want it to respect to score values for each of the types.
So, for example: results would be
- Dataset with score of 0.325
- Dataset with score of 0.282
- Dataset with score of 0.200
- Project with score of 0.298
- Project with score of 0.186
- Group with score of 0.360
- Group with score of 0.270
I'm doing this in java and using solrj to construct the solr queries. The problem is that when I try to add 2 sort fields to the SolrQuery object it only seems to use one of them. Also in the solr documents there isn't anything to state the entity type but the document's ID is prefixed with the entity name so I was planning to use that.
If anyone has got any ideas on how I could achieve this it would be greatly appreciated as I've been stuck on this for a while now!
Thanks in advance,
-Jake.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 solrj 看起来只使用其中一个排序字段,也许您正在使用
SolrQuery#setSortField
方法而不是addSortField
像这样:为了排序正如您所描述的结果,一个更干净的解决方案是在索引中添加一个字段,其中包含一种基于实体类型的权重。然后您可以直接使用该字段进行排序:
weight desc, Score desc
。在执行此操作之前,只需确保权重始终能够战胜 solr 分数,否则您应该努力影响 solr 分数。If it looks like solrj is using just one of the sort fields, maybe you're using the
SolrQuery#setSortField
method instead of theaddSortField
like this:In order to sort the results as you described, a cleaner solution would be adding a field to your index containing a kind of weight based on the entity type. Then you could directly sort using that field:
weight desc, score desc
. Before doing this, just make sure the weight has always to win against the solr score, otherwise you should work on influencing the solr score.