MongoDB查询结果排序(数值范围查询) [英] MongoDB query results ordering (Numeric Range query)

查看:561
本文介绍了MongoDB查询结果排序(数值范围查询)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

*此处为Mongo新手(在Windows上使用Mongo C#驱动程序)

*Mongo newbie here (using Mongo C# Driver on Windows)

您好,我正在评估Mongo应用数字维度的组合.我有数百个数字字段并创建一个布尔查询(我与Lucene,Solr等广泛合作,因此请原谅术语). Solr中的结果按相关性排序,即沿多个维度的最接近匹配,然后是下一个最接近的匹配,依此类推....

Hi, I am evaluating Mongo for applying a combination of numeric dimensions . I have a hundreds of numeric fields and create a boolean query(I work extensively with Lucene, Solr etc hence pardon the terminology). The results in Solr are ordered by relevance i.e. closest match along the multiple dimensions, followed by the next closest, and so on....

例如:

Doc1: 
 - NumField 1 : 9.9
 - NumField 2: 8.2

Doc2:
 - NumField 1 : 5.9
 - NumField 2: 8.9


**Query**
 - NumField 1: Between 7 & 10
 - NumField 2: Between 8 & 10

I would want Doc1 to show up before Doc2.

使用类似的结构查询Mongo可以得到我的结果,而看上去似乎没有相关性排序.有什么办法可以通过相关性"对查询结果进行排序?

Querying Mongo using a similar construct gets me results with no seeming relevance ordering. Is there any way I can order the query results by "relevance"?

p.s.我知道总是可以从客户端的游标中订购结果,但是如果可能的话,我希望在服务器端做到这一点.

p.s. I know can always order the results from the cursor in my client, but would like to do it server end if possible.

推荐答案

Mongo没有基于分数的排序,它按索引顺序返回文档(假设查询命中索引).

Mongo doesn't have any score based sorting, it returns docs in the order they're indexed (assuming your query hits an index).

您最好的选择可能是对客户进行排序.如果您确实要在Mongo中做到这一点,则可以使用map/reduce功能在文档上打分,然后查询输出集合并按得分排序.但这可能不是一个好主意.

Your best bet is probably sorting on the client. If you really, really want to do it in Mongo you can use the map/reduce functionality to put a score on docs, then query the output collection and sort by score. That's probably not a good idea though.

这篇关于MongoDB查询结果排序(数值范围查询)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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