简体   繁体   English

如何在c#驱动程序中为mongo集合中的所有文本字段创建全文搜索?

[英]How do you create a full text search for all text fields in a mongo collection in the c# driver?

I feel like this should be really simple, yet I've had a google and can't find exactly what I'm looking for.我觉得这应该很简单,但我有一个谷歌,无法准确找到我正在寻找的东西。

I can apply the following code in the mongo console:我可以在 mongo 控制台中应用以下代码:

db.collection.createIndex( { "$**": "text" } )

and I'll get a full text index on all text fields in my collection.我将在我的集合中的所有文本字段上获得全文索引。 How do I achieve this same result on a given collection in the mongo c# driver ?如何在mongo c# 驱动程序中的给定集合上实现相同的结果?

you can create a wildcard text index with the following.您可以使用以下内容创建通配符文本索引。

     collection.Indexes.CreateOne(
         new CreateIndexModel<MyType>(
             Builders<MyType>.IndexKeys.Text("$**")));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM