Quantcast
Channel: Active questions tagged mongodb-atlas - Stack Overflow
Viewing all articles
Browse latest Browse all 271

Mongo Atlas Search - Look for exact substring, even across words

$
0
0

Desired behavior:

Assuming I have two documents with these descrirption field values:

  • The Lazy Fox Jumps Over
  • The Lazy Boy is my favorite pastime

and I search:

Lazy F

I'd like the result to be the document with:

The Lazy Fox Jumps Over

and NOT bring up the one with

The Lazy Boy is my favorite pastime

Initially I had a regular phrase search which failed brought me the Lazy Fox document, but also the Lazy Boy... record, because it had the word Lazy in it.

Then I tried autocomplete:

{"mappings": {"dynamic": false,"fields": {"description": [        {"type": "string"        },        {"tokenization": "nGram","type": "autocomplete"        }      ]    }  }}

and search:

{"$search":{"autocomplete":{"query": querySplit,"path":"description"      },"index":"my_test_index"   }}

That improved things, for partial string search, but it also gets me those two documents where the word lazy exists, instead of the one I was aiming for.

SO: Is there any mapping that would be able to search for exact substrings, case insensitive?

The search logic should work as this sample python works, the simplest of partial string search, even across words:

s = "This is a Lazy Fox"f = "This is a Lazy Boy"print(s.find('Lazy F') > -1)print(f.find('Lazy F') > -1)

output:

TrueFalse

Thanks!


Viewing all articles
Browse latest Browse all 271

Trending Articles