Commits

Matt Chaput committed 529db53

Added type check to NUMERIC initializer. Fixed test failures.

  • Participants
  • Parent commits fd5348f

Comments (0)

Files changed (4)

File src/whoosh/fields.py

     (by truncating, not rounding) and imposes the same maximum value limits as
     ``int``/``long``, but these may be acceptable for certain applications.
     
-    >>> position = NUMERIC(int, decimal_places=4)
+    >>> from decimal import Decimal
+    >>> schema = Schema(path=STORED, position=NUMERIC(int, decimal_places=4))
+    >>> ix = storage.create_index(schema)
+    >>> w = ix.writer()
+    >>> w.add_document(path="/a", position=Decimal("123.45")
+    >>> w.commit()
     """
     
     def __init__(self, type=int, stored=False, unique=False, field_boost=1.0,
         :param stored: Whether the value of this field is stored with the
             document.
         :param unique: Whether the value of this field is unique per-document.
-        :param decimal_places: if ``type`` is ``Decimal``, this specifies the
-            number of decimal places to save.
+        :param decimal_places: specifies the number of decimal places to save
+            when storing Decimal instances as ``int`` or ``float``.
         """
         
         self.type = type
         elif self.type is float:
             self._to_text =  float_to_text
             self._from_text = text_to_float
+        elif self.type is Decimal:
+            raise TypeError("To store Decimal instances, set type to int or "
+                            "float and use the decimal_places argument")
+        else:
+            raise TypeError("%s field type can't store %r" % (self.__class__,
+                                                              self.type))
         
         self.stored = stored
         self.unique = unique

File src/whoosh/query.py

 
     def simplify(self, ixreader):
         existing = [Term(self.fieldname, word, boost=self.boost)
-                    for word in set(self._words(ixreader))]
+                    for word in sorted(set(self._words(ixreader)))]
         if len(existing) == 1:
             return existing[0]
         elif existing:

File tests/test_queries.py

         
         r = ix.reader()
         q1 = And([Prefix("v", "b", boost=2.0), Term("v", "juliet")])
-        q2 = And([Or([Term('v', u'bear', boost=2.0), Term('v', u'bee', boost=2.0), Term('v', u'brie', boost=2.0)]), Term('v', 'juliet')])
+        q2 = And([Or([Term('v', u'bear', boost=2.0), Term('v', u'bee', boost=2.0),
+                      Term('v', u'brie', boost=2.0)]), Term('v', 'juliet')])
         self.assertEqual(q1.simplify(r), q2)
 
 

File tests/test_results.py

 
 from whoosh import analysis, fields, formats, qparser, query, searching
 from whoosh.filedb.filestore import RamStorage
+from whoosh.util import permutations
 
 
 class TestResults(unittest.TestCase):