matches per every keyword

5 views
Skip to first unread message

Assem Chelli

unread,
Jul 18, 2010, 2:06:16 AM7/18/10
to who...@googlegroups.com
hello,



is there any method to know the number of matches for every keyword?

Matt Chaput

unread,
Jul 18, 2010, 11:34:23 AM7/18/10
to who...@googlegroups.com
> is there any method to know the number of matches for every keyword?

There currently isn't a FAST or MEMORY EFFICIENT method. I could add one in the future, though it would require you to forego certain optimizations.

The best way to do this currently is simply to create sets of the documents containing each keyword, and intersect them with the set of documents in the results:


s = myindex.searcher()

# Run the query
results = s.search(myquery)

# Get a set of document numbers for the results
results_set = set(results.docs)

# Intersect the results set with the sets for each term

from whoosh.query import Term

for term in myquery.existing_terms(s.reader()):
term_set = set(Term(fieldname, term).docs(s))
intersection = results_set & term_set
print "Term:", term, "found in:", len(intersection), "of the results"


Cheers,

Matt

Reply all
Reply to author
Forward
0 new messages