Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect search results (partial match) #147

Open
wolfiex opened this issue Mar 14, 2024 · 1 comment
Open

Incorrect search results (partial match) #147

wolfiex opened this issue Mar 14, 2024 · 1 comment

Comments

@wolfiex
Copy link

wolfiex commented Mar 14, 2024

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

@yeraydiazdiaz
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants