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

Field-specific pipeline skips are not respected in search #152

Open
dhdaines opened this issue Jul 5, 2024 · 0 comments · May be fixed by #153
Open

Field-specific pipeline skips are not respected in search #152

dhdaines opened this issue Jul 5, 2024 · 0 comments · May be fixed by #153

Comments

@dhdaines
Copy link
Contributor

dhdaines commented Jul 5, 2024

Lunr allows you to skip steps in the pipeline for specific fields, as detailed in the customization document. Unfortunately this functionality is not very useful, because these skips are only applied during indexing and not during search. Here is an example:

from lunr import lunr, get_default_builder, stop_word_filter, stemmer

builder = get_default_builder()
builder.pipeline.skip(stop_word_filter.stop_word_filter, ["title"])
# Add the stop word filter to the pipeline (see #151)
builder.search_pipeline.before(stemmer.stemmer, stop_word_filter.stop_word_filter)
builder.search_pipeline.skip(stop_word_filter.stop_word_filter, ["title"])

index = lunr(
    ref="id",
    fields=["title", "body"],
    documents=[
        # The title is entirely stopwords, but will index them anyway
        {"id": "1", "title": "To be or not to be?", "body": "That is the question!"}
    ],
    builder=builder,
)
print(index.search("title:to"))  # Should print something, but doesn't
print(index.search("body:the"))  # Should print []
print(index.search("to"))        # Should print something, but doesn't

Because skipping fields isn't a super common thing to do, but also because of #151 (the stop word filter is never applied to the query anyway) this isn't always noticeable in normal use, which is probably why it never got fixed in lunr.js.

As with #151 this can't be fixed without breaking bug-compatibility with lunr.js (see https://github.com/olivernn/lunr.js/blob/master/lib/index.js#L173), but I wanted to document the workaround.

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

Successfully merging a pull request may close this issue.

1 participant