Matt Chaput avatar Matt Chaput committed 92ca283

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

Comments (0)

Files changed (3)


         # 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


         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::


         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 =, terms=True)
+        assert len(r) == 2
+        hit = r[0]
+        assert hit["content"] == "bravo"
+        assert hit.highlights("content") == ""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.