简体   繁体   English

mongodb,全文搜索而不是多个字段

[英]mongodb, full text search instead of multiple fields

I need to query against many fields inside my documents, and I got the idea of instead of having to index (or compound index) the fields I need, to concatenate the relevant data that needs to be searchable inside a single text field in the document and search against it. 我需要查询文档中的许多字段,然后想到了不必索引(或复合索引)所需的字段,而是将需要在文档中的单个文本字段内可搜索的相关数据连接起来的想法并针对它进行搜索。 Bad or good idea? 好主意?

Possible example with indexes (or compound indexes) 索引(或复合索引)的可能示例

{
    name: "john",
    last: "doe,
    city: "new york",
    likes: ["pizza", "ice cream"],
}

Possible example with a single index on a text field: 在文本字段上使用单个索引的可能示例:

{
    name: "john",
    last: "doe,
    city: "new york",
    likes: "pizza",
    search: "john doe new york pizza ice cream",
}

It all depends on your data retrieval pattern from db of your application. 这一切都取决于您从应用程序数据库获取数据的方式。 If you have a lot of text (paragraphs of text) to be searched, full text search is a good idea. 如果要搜索大量文本(文本段),则全文搜索是一个好主意。 If it is few, better to stick to a array of texts approach. 如果数量很少,最好坚持采用多种文本方法。

However, keep in mind that only one full text search field allowed within a single collection. 但是,请记住,单个集合中仅允许一个全文搜索字段。

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

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