only one match
This script searches for ma in a database full of all possible 3 character names, and it should find everything from maa to maz, but only finds mas.
Here is the test output:
$ node index.js
inserted 17576 values (took 1976ms)
querying for ma
{ name: 'mas' }
{ indexHits: 1, dataHits: 1, matchHits: 1 }
1 out of 17576 names match (took 274ms)
adding a 1s delay before querying doesn't help.
Hi @juliangruber, sorry for taking so long to back to you.
The issue is that the full-text engine builds an inverted indexed based on words (after a stemming algorithm has been applied).
So, you can't use it currently to do partial matching within words.
The reason that you get a hit at all is because when 'mas' is inserted, the porter stemming algorithm converts this to 'ma', so searching for 'ma' hits 'mas'.
Here's an example where I add some other word phrases:
https://gist.github.com/7327394
I get:
inserted 17576 values (took 2390ms)
querying for training
{ name: 'cat training' }
{ name: 'dog training' }
{ indexHits: 2, dataHits: 2, matchHits: 2 }
2 out of 17576 names match (took 6ms)
I guess we could extend the full text search algorithm to search the inverted index for partial matches and then do the lookups.
aah, didn't realize it only matches full names. How complicated would this be to add?
Not too tricky if you need to do a match at the start of a word, but you'd suffer quite a bit of performance having to do an index scan to do matches in the middle of a word.
What's your use case?
searching through users' nicknames and full names for a dropdown, like when you add someone on github to your repo or org.