Matt Chaput avatar Matt Chaput committed bbdd77a

Calling Searcher.documents()/.document_numbers() with no arguments will now yield
all documents/numbers.

Fixes issue #198.

Comments (0)

Files changed (2)

src/whoosh/searching.py

         subqueries = []
         for key, value in iteritems(kw):
             subqueries.append(query.Term(key, value))
-        return query.And(subqueries).normalize()
+        if subqueries:
+            q = query.And(subqueries).normalize()
+        else:
+            q = query.Every()
+        return q
 
     def document_number(self, **kw):
         """Returns the document number of the document matching the given
         >>> docnums = list(searcher.document_numbers(emailto="matt@whoosh.ca"))
         """
 
-        if len(kw) == 0:
-            return []
-
         self._kw_to_text(kw)
         return self.docs_for_query(self._query_for_kw(kw))
 

tests/test_searching.py

 def test_docs_method():
     ix = make_index()
     with ix.searcher() as s:
-        assert_equal(_get_keys(s.documents(name="yellow")), [u("A"), u("E")])
-        assert_equal(_get_keys(s.documents(value="red")), [u("A"), u("D")])
+        assert_equal(_get_keys(s.documents(name="yellow")), ["A", "E"])
+        assert_equal(_get_keys(s.documents(value="red")), ["A", "D"])
+        assert_equal(_get_keys(s.documents()), ["A", "B", "C", "D", "E"])
 
 def test_term():
     _run_query(Term("name", u("yellow")), [u("A"), u("E")])
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 ProjectModifiedEvent.java.
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.