olivernn / lunr.js

A bit like Solr, but much smaller and not as bright
http://lunrjs.com
MIT License
8.96k stars 548 forks source link

Get position of found words #161

Closed Integral closed 9 years ago

Integral commented 9 years ago

Hello there! Is there any way to get position of what lunr found? Or is there actually any way to print what words it found? Thanks.

olivernn commented 9 years ago

With the current way lunr stores the index and performs searches it is not possible to return the positions of the matched words in the returned documents. This is a very popular feature request that I really want to add, but it is a complicated and large change that requires a lot of time.

For lunr to return documents all search terms must be present in the document. You can see what terms lunr is looking for by running the pipeline manually your self:

idx.pipeline.run(lunr.tokenizer("my search term here")) //= ["search", "term", "here"]

This is how the search method turns your string query into tokens, notice above that "my" has been removed as it is a stop word. Its not shown in this example but the tokens returned will have been passed through the text processing pipeline, by default this will mean they will be stemmed, and therefore may not resemble normal english words anymore, so there use outside of querying the index may be limited.

Integral commented 9 years ago

Ok, thank you!