问题
*Mongo newbie here (using Mongo C# Driver on Windows)
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....
For example:
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.
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. I know can always order the results from the cursor in my client, but would like to do it server end if possible.
回答1:
Mongo doesn't have any score based sorting, it returns docs in the order they're indexed (assuming your query hits an index).
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.
来源:https://stackoverflow.com/questions/11696627/mongodb-query-results-ordering-numeric-range-query