fulltext-engine icon indicating copy to clipboard operation
fulltext-engine copied to clipboard

only one match

Open juliangruber opened this issue 12 years ago • 5 comments

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)

juliangruber avatar Oct 27 '13 11:10 juliangruber

adding a 1s delay before querying doesn't help.

juliangruber avatar Oct 27 '13 11:10 juliangruber

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.

eugeneware avatar Nov 05 '13 22:11 eugeneware

aah, didn't realize it only matches full names. How complicated would this be to add?

juliangruber avatar Nov 05 '13 23:11 juliangruber

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?

eugeneware avatar Nov 06 '13 01:11 eugeneware

searching through users' nicknames and full names for a dropdown, like when you add someone on github to your repo or org.

juliangruber avatar Nov 06 '13 09:11 juliangruber