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

Random access scoring #22

Open
SnowyCoder opened this issue Feb 10, 2022 · 0 comments
Open

Random access scoring #22

SnowyCoder opened this issue Feb 10, 2022 · 0 comments

Comments

@SnowyCoder
Copy link

SnowyCoder commented Feb 10, 2022

Hello, thanks for this library!

In my project I'm trying to create a query aggregator using multiple indexes (take a query, run it on multiple searchers, aggregate the results).
It would be really useful to have a way to access a score from an index in a random-access way (ex. given a document id, a query and a searcher, what's the resulting score?).
The solution I came up with having not much experience with the code-base is this:

from whoosh.matching import IntersectionMatcher, ListMatcher
from whoosh.query import Query
from whoosh.searching import Searcher

def random_access_score(query: Query, searcher: Searcher, docid: int) -> tuple[int, float]:
    for subsearcher, offset in searcher.leaf_searchers():
        m = query.matcher(subsearcher, context=searcher.context())
        m = IntersectionMatcher(ListMatcher([docid], [0]), m)
        if m.is_active():
            return m.id(), m.score()
    # necessary in case of no hit for docid
    return -1, 0

Is this correct? is there a more efficient way to do this? (I expect this to iterate over all of the posting lists, right?).

Thank you in advance!

cclauss pushed a commit to cclauss/whoosh-1 that referenced this issue Jan 4, 2024
Another update to the Python versions in PyPI classifiers
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