1. Matt Chaput
  2. whoosh


Matt Chaput  committed 0aec288

SegmentWriter's implementation of Writer.add_field() wasn't passing keyword args up.
Fixes issue #170.

  • Participants
  • Parent commits b0cb441
  • Branches default

Comments (0)

Files changed (3)

File src/whoosh/fields.py

View file
  • Ignore whitespace
         assert isinstance(self.format, formats.Format), type(self.format)
         return self.format.word_values(value, self.analyzer, mode="index", **kwargs)
+    def index_(self, fieldname, value, **kwargs):
+        for w, freq, weight, value in self.index(value, **kwargs):
+            yield fieldname, w, freq, weight, value
     def process_text(self, qstring, mode='', **kwargs):
         """Analyzes the given string and returns an iterator of token strings.

File src/whoosh/filedb/filewriting.py

View file
  • Ignore whitespace
         info = ix._read_toc()
         self.schema = info.schema
-        #self.ssnames = set(self.schema.special_spelling_names())
         self.segments = info.segments
         self.storage = ix.storage
         self.indexname = ix.indexname
         if self.is_closed:
             raise IndexingError("This writer is closed")
-    def add_field(self, fieldname, fieldspec):
+    def add_field(self, fieldname, fieldspec, **kwargs):
         if self._added:
             raise Exception("Can't modify schema after adding data to writer")
-        super(SegmentWriter, self).add_field(fieldname, fieldspec)
+        super(SegmentWriter, self).add_field(fieldname, fieldspec, **kwargs)
     def remove_field(self, fieldname):
         self._added = True
     def add_document(self, **fields):
-        #from whoosh.util import now
-        #t = now()
         schema = self.schema
-        #ssnames = self.ssnames
         docboost = self._doc_boost(fields)
         # Sort the keys
         self.docnum += 1
-    #def update_document(self, **fields):
     def add_spell_words(self, fieldname, words):
         # Get or make a set for the words in this field
         if fieldname not in self.wordsets:

File tests/test_writing.py

View file
  • Ignore whitespace
         with ix.reader() as r:
             pr = r.postings("a", "bravo")
             assert_equal(pr.id(), 1)
+def test_add_field():
+    schema = fields.Schema(a=fields.TEXT)
+    with TempIndex(schema, "addfield") as ix:
+        with ix.writer() as w:
+            w.add_document(a=u("alfa bravo charlie"))
+        with ix.writer() as w:
+            w.add_field("b", fields.ID(stored=True))
+            w.add_field("c*", fields.ID(stored=True), glob=True)
+            w.add_document(a=u("delta echo foxtrot"), b=u("india"), cat=u("juliet"))
+        with ix.searcher() as s:
+            fs = s.document(b=u("india"))
+            assert_equal(fs, {"b": "india", "cat": "juliet"})