MONGODB Full Text Search Logical OR Query
NickName:Max Hamulyák Ask DateTime:2016-01-15T00:31:31

MONGODB Full Text Search Logical OR Query

I am currently working on a project where a large database (+25.000.000 records) needs to be searched (on a local machine) in under the 1000ms. That made me think of MongoDB and the desired performance can be reached. I can do this by several different kinds of indexes, however I need to be able to match partially.

The end user is allowed to search on a couple of fields. (Not all of the fields; Need to be able to search 5/9 of the fields the rest is meta data not searchable for the end user)

I first tried creating a compound index (on all 5 of the fields) for full text search

db.tracks.find({$text:{$search:"Greatest Hits"}})

This seems to be working rather well and giving me all sorts of results with Great, Greatest and Hits on any of the compound fields.

However a user should be able to select the fields that he wants to search on. (For example: AlbumTitle, TrackTitle etc). This means that When track title is toggled off I don't want results from that column.

db.tracks.find({AlbumTitle: "Greatest Hits"})

The above query would be able to find exact matches and thus not finding the same result when searching on Greatest. This made me think of something like the following

db.tracks.find({AlbumTitle: {$text: {$search: "Greatest Hits"}}})

but that doesn't work because then $text would be an unknown operator.

If something like the above would be possible I would be able to build my query dynamically based on the toggled fields like

db.tracks.find({$or: [ {ToggledField1: ...}, {ToggeldField4: ...}  ]})

and thus ensuring only the needed fields are queried. Would this at all be possible inside a MongoDB database, and if so what is the best way to achieve the desired functionality

Thanks in Advance

Copyright Notice:Content Author:「Max Hamulyák」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34794774/mongodb-full-text-search-logical-or-query

More about “MONGODB Full Text Search Logical OR Query” related questions

MONGODB Full Text Search Logical OR Query

I am currently working on a project where a large database (+25.000.000 records) needs to be searched (on a local machine) in under the 1000ms. That made me think of MongoDB and the desired perform...

Show Detail

MongoDB - Logical OR when searching for words and phrases using full text search

I asked a related question previously, and as suggested by the poster there have created this new question as a follow up: MongoDB full text search - matching words and exact phrases I was having...

Show Detail

How to combine a Spring Data MongoDB Query with full text search?

I've recently upgraded to Spring Data MongoDB 1.6.0.RC1, which is very good and implements the full text search feature of MongoDB 2.6 (huuurah!). My question is: how can I combine the Criteria and

Show Detail

MongoDB text search logical AND

MongoDB seems to only do logical OR text queries? If I want to find all documents that contain the words ('apple' or 'orange' or 'pear') I can do the following. db.collection.runCommand('text', {..

Show Detail

JS partial Text Search in MongoDB

Env: MongoDB (4.0.6) At the beginning I was used regex search like this: keyword = new RegExp(keyword, 'img'); query.$or = [ { campaignTitle: keyword } ]; but main problem, "keyword" i

Show Detail

Mongodb doctrine query builder full text search does not sort the results based on the textScore

I am new to doctrine mongodb query builder and trying to combine query builder and mongodb to do a full text search in php(Symfony 2.6) first of all I have indexed the field of the collection I wa...

Show Detail

Mongodb vs elastic search for non-full-text search

I am making an website that use mongoDB to store product information. I want to use elastic search to let user search products by name or description. However, I also want to let user search prod...

Show Detail

Full text search options for MongoDB setup

We are planning to store millions of documents in MongoDB and full text search is very much required. I read Elasticsearch and Solr are the best available solutions for full text search. Is Elastic

Show Detail

How to make full text search with mongodb spring data?

Before asking this question, I have searched much about my problem. I need to make full text search from mongodb in spring framework. Up to now I just tried something with regex, but it does not co...

Show Detail

Full Text Search & Inverted Indexes in MongoDB

I’m playing around with MongoDB for the moment to see what nice features it has. I’ve created a small test suite representing a simple blog system with posts, authors and comments, very basic. I’ve

Show Detail