lunr.py
lunr.py copied to clipboard
Incorrect search results (partial match)
When using the query tas
lunr matches on ta
rather than the full word.
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