0

I'm using MongoDB for my project and with it the text search. I've seen that the only way to make it return results that could really be what the user is looking for is to use the exact match

Without it MongoDB tends to give me result that aren't precise (primarily because some documents has repeated words that make them have a higher score even if they aren't usually what the user was looking for. For instance, the user searches "neu! hallogallo" and the first document in the sort is the one with name "neu! neu!" and not "neu! hallogallo")

The problem with this method is that it's too much precise. I mean, it only returns one exact document, while my ideal query should at least have 10 documents

The questione is: is there a way to ask to Mongo to return first the exact matches and then the inexact ones in the same query? Or the only way to do this is to make two queries?

lemmasim
  • 21
  • 2
  • In the documentation of for [$text](https://docs.mongodb.com/manual/reference/operator/query/text/#stemmed-words). *"For case insensitive and diacritic insensitive text searches, the $text operator matches on the complete stemmed word. So if a document field contains the word blueberry, a search on the term blue will not match. However, blueberry or blueberries will match."*. You want the search with **blue** here. This is a [`$regex'](https://docs.mongodb.com/manual/reference/operator/query/regex/) argument as explained in the linked answers. – Neil Lunn Jun 04 '17 at 23:15
  • I don't think that this can solve my problem. My problem isn't about misspelled and incomplete words, but instaed about extra words with no match in database For instance: i have a document that matches with "neu! neu!" but the query is "neu! neu! full album (1972) - HQ sound ecc." Exact match makes the AND on the words – lemmasim Jun 06 '17 at 06:56

0 Answers0