Commits

Matt Chaput  committed 92ca283

Just return an empty list for documents without terms in matched_terms()
Fixes issue #364.

  • Participants
  • Parent commits a733ff9

Comments (0)

Files changed (3)

File src/whoosh/highlight.py

         # Convert bytes to unicode
         words = frozenset(from_bytes(term[1]) for term in bterms)
 
-        # if not words:
-        #     # No terms matches in this field
-        #     return self.formatter.format([])
-
         # If we can do "pinpoint" highlighting...
         if self.can_load_chars(results, fieldname):
             # Build the docnum->[(startchar, endchar),] map

File src/whoosh/searching.py

 
         if not self.has_matched_terms():
             raise NoTermsException
-
         return set(self.termdocs.keys())
 
     def _get_fragmenter(self):
 
         if not self.results.has_matched_terms():
             raise NoTermsException
-        return self.results.docterms[self.docnum]
+        return self.results.docterms.get(self.docnum, [])
 
     def highlights(self, fieldname, text=None, top=3, minscore=1):
         """Returns highlighted snippets from the given field::

File tests/test_results.py

         assert len(r) == 2
         kts = " ".join(t for t, score in r.key_terms("text"))
         assert kts == "alfa bravo charlie foxtrot delta"
+
+
+def test_every_keywords():
+    schema = fields.Schema(title=fields.TEXT, content=fields.TEXT(stored=True))
+    ix = RamStorage().create_index(schema)
+    with ix.writer() as w:
+        w.add_document(title=u("alfa"), content=u("bravo"))
+        w.add_document(title=u("charlie"), content=u("delta"))
+
+    with ix.searcher() as s:
+        q = qparser.QueryParser("content", ix.schema).parse("*")
+        assert isinstance(q, query.Every)
+
+        r = s.search(q, terms=True)
+        assert len(r) == 2
+        hit = r[0]
+        assert hit["content"] == "bravo"
+        assert hit.highlights("content") == ""