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

Boosts are not being applied for Compound Prefix Queries #42

Open
Ainesh opened this issue May 24, 2023 · 0 comments
Open

Boosts are not being applied for Compound Prefix Queries #42

Ainesh opened this issue May 24, 2023 · 0 comments

Comments

@Ainesh
Copy link

Ainesh commented May 24, 2023

There seem to be a bug in the macher() implementation of MultiTerm class. The boosts applied to the Prefix queries do not propagate to the final score calculation. When qs is generated with Term queries using the input Prefix queries, boosts are not transferred to the newly generated queries. https://github.com/mchaput/whoosh/blob/d9a3fa2a4905e7326c9623c89e6395713c189161/src/whoosh/query/terms.py#LL210C9-L211C23

Working example:

from whoosh import fields, scoring
from whoosh.analysis import SimpleAnalyzer
from whoosh.filedb.filestore import RamStorage
from whoosh.query import Prefix, Or, Term

schema = fields.Schema(title=fields.TEXT(analyzer=SimpleAnalyzer()))

storage = RamStorage()
ix = storage.create_index(schema)

def get_weighting():
    def my_scorer(searcher, fieldname, text, matcher):
        return 1
    return scoring.FunctionWeighting(my_scorer)

with ix.writer() as writer:
    writer.add_document(title="apple")
    writer.add_document(title="banana")
    writer.add_document(title="orange")
    writer.add_document(title="grape")

with ix.searcher(weighting=get_weighting()) as searcher:
    prefix_queries = [Prefix("title", "app", boost=2.0)]
    # term_queries = [Term("title", "apple", boost=2.5)]

    query = Or(prefix_queries)
    results = searcher.search(query, scored=True, limit=None, terms=True)
    for result in results:
        print(f"Matched document: {result.docnum}; Score: {result.score}")

Here, changing the boost in Prefix("title", "app", boost=2.0) doesn't make a difference to the final score for the document. It is always 1. On the other hand, boost in the Term query works as expected. The final score changes based on the boost value.

ZeroCool940711 added a commit to cclauss/whoosh-1 that referenced this issue Feb 3, 2024
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

1 participant