
db.MyCollection.createIndex({'$**': 'text'},{name: 'FullTextIndex'}) 搜索匹配
db.MyCollection.find({$text: {$search: 'myWord'}}).count() 对于具有“myWord is here”值的字段,结果为1.
如果我经常搜索所选字段如下,我得到两条记录,一条记录名称=“myWord就在这里”,第二条记录中的“myWord”在详细信息中归档为“这里的东西,myWord就在这里”
db.getCollection('MyCollection').find({ "$or":[{"name":/myWord/i},{"Details":/myWord/i}] }).sort({"name": 1}) 如何重新创建索引,以便在所有字段中搜索sql,其中任何字段如%searchText%
最后,我如何在C#Driver中编写此搜索查询
更新:
我进一步调查了它.它找到所有带有前缀和后缀空格的搜索键的结果,但不是单词中字符串的一部分.
示例它返回值“Hello myWord is here”的记录,但不返回“HellomyWord”
但根据这份文件,它必须支持通配符搜索. https://docs.mongodb.com/v3.0/reference/operator/query/text/
解决方法 由于我没有找到很多有关使用Mongo的通配符搜索/全文搜索的帮助,我已经想出了一个解决方案.foreach (var doc in batch) { if (custDictionary.ContainsKey(projectID)) { string concatenatedCustomFIElds = custFIEldsList.Aggregate(string.Empty,(current,custFIEld) => current + (ds.tables[0].Columns.Contains(custFIEld) ? (ds.tables[0].Rows[i][custFIEld].GetType().name == typeof(dbnull).name ? string.Empty : ((string) ds.tables[0].Rows[i][custFIEld]).StripHTML()) : string.Empty)); doc.Add("CustomFIEldsConcatenated",concatenatedCustomFIElds); } i++; } 我读了每组文档的自定义字段列表,然后创建一个连接的Mongo字段,然后在该字段上使用正则表达式查询.
然后提高查询性能,添加以下索引
_mongoConnect.Database?.GetCollection<Bsondocument>("MyCollectionname") .Indexes.CreateOneAsync(new Bsondocument("CustomFIEldsConcatenated","hashed"),new CreateIndexOptions { name = "Collectionname_FIEldname_Index" }); 总结 以上是内存溢出为你收集整理的c# – MongoDB全文搜索全部内容,希望文章能够帮你解决c# – MongoDB全文搜索所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)