Commits

Matt Chaput  committed a28cded

Fixed reversed logic in BOOLEAN field. Fixes issue #64.

  • Participants
  • Parent commits 40323c5

Comments (0)

Files changed (3)

File src/whoosh/__init__.py

 # limitations under the License.
 #===============================================================================
 
-__version__ = (1, 3, 2)
+__version__ = (1, 3, 3)
 
 
 def versionstring(build=True, extra=True):

File src/whoosh/fields.py

     >>> w.commit()
     """
     
-    strings = (u"t", u"f")
+    strings = (u"f", u"t")
     trues = frozenset((u"t", u"true", u"yes", u"1"))
     falses = frozenset((u"f", u"false", u"no", u"0"))
     
         if qstring == "*":
             return query.Every(fieldname, boost=boost)
         
-        if qstring in self.falses:
-            text = self.strings[0]
-        elif qstring in self.trues:
-            text = self.strings[1]
+        try:
+            text = self.to_text(qstring)
+        except ValueError:
+            return query.NullQuery
         
-        if text is None:
-            return query.NullQuery
-        else:
-            return query.Term(fieldname, text, boost=boost)
+        return query.Term(fieldname, text, boost=boost)
     
 
 class STORED(FieldType):

File tests/test_fields.py

         self.assertEqual(sorted([d["id"] for d in r]), ["b", "d"])
         self.assertTrue(all_false(d["done"] for d in r))
 
+    def test_boolean2(self):
+        schema = fields.Schema(t=fields.TEXT(stored=True), b=fields.BOOLEAN(stored=True))
+        ix = RamStorage().create_index(schema)
+        writer = ix.writer()
+        writer.add_document(t=u'some kind of text', b=False)
+        writer.add_document(t=u'some other kind of text', b=False)
+        writer.add_document(t=u'some more text', b=False)
+        writer.add_document(t=u'some again', b=True)
+        writer.commit()
+        
+        s = ix.searcher()
+        qf = qparser.QueryParser('b').parse(u'f')
+        qt = qparser.QueryParser('b').parse(u't')
+        r = s.search(qf)
+        self.assertEqual(len(r), 3)
+        
+        self.assertEqual([d["b"] for d in s.search(qt)], [True])
+        self.assertEqual([d["b"] for d in s.search(qf)], [False] * 3)
+        
     def test_missing_field(self):
         schema = fields.Schema()
         ix = RamStorage().create_index(schema)