lunr.py icon indicating copy to clipboard operation
lunr.py copied to clipboard

Incorrect search results (partial match)

Open wolfiex opened this issue 11 months ago • 1 comments

When using the query tas lunr matches on ta rather than the full word.

wolfiex avatar Mar 14 '24 00:03 wolfiex

This is expected behaviour as tas is stemmed to ta, both on index building time and when searching.

To disable the stemmer you'll need to disable it from both the indexing pipeline and the search results pipeline, something like:

from lunr import get_default_builder
from lunr.stemmer import stemmer

docs = [
    {
        "id": 1,
        "text": "rax tas ras",
    },
    {
        "id": 2,
        "text": "rex tas res",
    },
]

builder = get_default_builder()
builder.ref("id")
builder.field("text")
builder.pipeline.remove(stemmer)
builder.search_pipeline.remove(stemmer)
for doc in docs:
    builder.add(doc)

idx = builder.build()
results = idx.search("tas")
assert len(results) == 2

yeraydiazdiaz avatar Mar 17 '24 19:03 yeraydiazdiaz