Matt Chaput avatar Matt Chaput committed 5cf3983

Fixed Field.spellable_words() to work with a list of pre-analyzed words.
Fixes issue #372.

Comments (0)

Files changed (2)

src/whoosh/fields.py

         this behavior.
         """
 
-        wordset = sorted(set(token.text for token
-                             in self.analyzer(value, no_morph=True)))
-        return iter(wordset)
+        if isinstance(value, (list, tuple)):
+            words = value
+        else:
+            words = [token.text for token
+                     in self.analyzer(value, no_morph=True)]
+
+        return iter(sorted(set(words)))
 
     def has_morph(self):
         """Returns True if this field by default performs morphological

tests/test_writing.py

         assert s.doc_count_all() == 1
         assert list(s.reader().lexicon("a")) == [b("bar"), b("baz"), b("foo")]
 
+
+def test_spellable_list():
+    # Make sure a spellable field works with a list of pre-analyzed tokens
+
+    ana = analysis.StemmingAnalyzer()
+    schema = fields.Schema(Location=fields.STORED,Lang=fields.STORED,
+                           Title=fields.TEXT(spelling=True, analyzer=ana))
+    ix = RamStorage().create_index(schema)
+
+    doc = {'Location': '1000/123', 'Lang': 'E',
+           'Title': ['Introduction', 'Numerical', 'Analysis']}
+
+    with ix.writer() as w:
+        w.add_document(**doc)
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.