I'm currently having some issues with the full text search functionality in MongoDB. Specifically when trying to match exact phrases.
I'm testing out the functionality in the mongo shell, but ultimately I'll be using Spring Data MongoDB with Java.
So I first tried running this command to search for the words "delay", "late" and the phrase "on time"
db.mycollection.find( { $text: { $search: "delay late \"on time\"" } }).explain(true);
And the resulting explain query told me:
"parsedTextQuery" : {
"terms" : [
"delay",
"late",
"time"
],
"negatedTerms" : [ ],
"phrases" : [
"on time"
],
"negatedPhrases" : [ ] },
The issues here being that I don't want to search for the word "time", but rather the phrase "on time". I do want to search for delay and late and ideally don't want to prevent the stemming.
I tried a few different permutations e.g.
db.mycollection.find( { $text: { $search: "delay late \"'on time'\"" } }).explain(true);
db.mycollection.find( { $text: { $search: "delay late \"on\" \"time\"" } }).explain(true);
But couldn't seem to get the right results. I can't see anything obvious in the documentation about this.
For my purposes should I use the full text search for individual words and the regex search functionality for phrases?
Currently working with MongoDB version 2.6.5. Thanks.