Skip to content

Commit

Permalink
fix bug (#793)
Browse files Browse the repository at this point in the history
fix key not found in idf dict
  • Loading branch information
MXueguang authored Oct 1, 2021
1 parent f2e7f90 commit bebe9de
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pyserini/search/_impact_searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def search(self, q: str, k: int = 10, fields=dict()) -> List[JImpactSearcherResu
encoded_query = self.query_encoder.encode(q)
jquery = JHashMap()
for (token, weight) in encoded_query.items():
if self.idf[token] > self.min_idf:
if token in self.idf and self.idf[token] > self.min_idf:
jquery.put(JString(token.encode('utf8')), JFloat(weight))

if not fields:
Expand Down Expand Up @@ -153,7 +153,7 @@ def batch_search(self, queries: List[str], qids: List[str],
encoded_query = self.query_encoder.encode(q)
jquery = JHashMap()
for (token, weight) in encoded_query.items():
if self.idf[token] > self.min_idf:
if token in self.idf and self.idf[token] > self.min_idf:
jquery.put(JString(token.encode('utf8')), JFloat(weight))
query_lst.add(jquery)

Expand Down

0 comments on commit bebe9de

Please sign in to comment.