我正在尝试对集合进行文本查询并按文本匹配顺序检索结果。文档很好地解释了如何在 shell 中执行此操作:
db.articles.find(
{ status: "A", $text: { $search: "coffee cake" } },
{ score: { $meta: "textScore" } }
).sort( { date: 1, score: { $meta: "textScore" } } )
Run Code Online (Sandbox Code Playgroud)
但它需要将附加score字段从 find投影到排序中。
在 C# 中,我有一个如下所示的函数:
public IEnumerable<T> TextSearch<T>(MongoCollection<T> coll, string text) {
var cursor = coll.Find(Query.Text(text))
.SetSortOrder(SortBy<T>.MetaTextScore(???));
foreach(var t in cursor) {
// strip projected score from value
yield return t;
}
}
Run Code Online (Sandbox Code Playgroud)
但我缺少如何将“textScore”值投影到我的结果中,以便我可以将列指定为MetaTextScorein SetSortOrder。