lucaong / minisearch

Tiny and powerful JavaScript full-text search engine for browser and Node
https://lucaong.github.io/minisearch/
MIT License
4.64k stars 133 forks source link

How to search for parts of a word? #225

Closed Thomas-1985 closed 1 year ago

Thomas-1985 commented 1 year ago

Hi

I am using minisearch and with prefix search but i need a way to search for parts of a word. So as an example:

"post" should also find "Filzpostkarten"

How can i make this work? Prefix search doesn't work, it will match "Alm" -> "Almbauer" but not the case above

Best, Thomas

lucaong commented 1 year ago

Hi @Thomas-1985 , in general, this is not supported by MiniSearch out of the box. This is a technical choice: the specific data structure used for the index makes it very efficient to perform prefix and fuzzy search, but a partial match in the middle of a word would be inefficient. I think that lunr supports such pattern, although I suspect it isn't efficient either (as the index data structure is similar).

There are ways to achieve what you want with MiniSearch, but while they are efficient at search time, they do result in a larger index. Depending on your case, if the collection you are indexing is not too large, it could be a good option. The easiest way is what suggested in this comment on another issue.

I hope this helps.

Thomas-1985 commented 1 year ago

Thanks a lot, ill try that out. The ticket can be closed :)