Commits

Matt Chaput  committed 101a448

Added parser as an argument to plugins' tokens() and filters() methods. Fixed tests.

  • Participants
  • Parent commits 4c3ece4

Comments (0)

Files changed (2)

File src/whoosh/qparser/default.py

     """Base class for parser plugins.
     """
             
-    def tokens(self):
+    def tokens(self, parser):
         """Returns a list of ``(token_class, priority)`` tuples to add to the
         syntax the parser understands.
         """
         
         return ()
     
-    def filters(self):
+    def filters(self, parser):
         """Returns a list of ``(filter_function, priority)`` tuples to add to
         parser.
         """
     This plugin is included in the default parser configuration.
     """
     
-    def tokens(self):
+    def tokens(self, parser):
         return ((RangePlugin.Range, 0), )
     
     class Range(Token):
     This plugin is included in the default parser configuration.
     """
     
-    def tokens(self):
+    def tokens(self, parser):
         return ((PhrasePlugin.Quotes, 0), )
     
     class Quotes(BasicSyntax):
     This plugin is included in the default parser configuration.
     """
      
-    def tokens(self):
+    def tokens(self, parser):
         return ((SingleQuotesPlugin.SingleQuotes, 0), )
     
     class SingleQuotes(Token):
     including the wildcard plugin, you should not include this plugin as well.
     """
     
-    def tokens(self):
+    def tokens(self, parser):
         return ((PrefixPlugin.Prefix, 0), )
     
     class Prefix(BasicSyntax):
     This plugin is included in the default parser configuration.
     """
     
-    def tokens(self):
+    def tokens(self, parser):
         return ((WildcardPlugin.Wild, 0), )
     
     class Wild(BasicSyntax):
     This plugin is always automatically included by the QueryParser.
     """
     
-    def tokens(self):
+    def tokens(self, parser):
         return ((Word, 900), )
 
 
     This plugin is always automatically included by the QueryParser.
     """
     
-    def tokens(self):
+    def tokens(self, parser):
         return ((White, 100), )
     
-    def filters(self):
+    def filters(self, parser):
         return ((WhitespacePlugin.do_whitespace, 500), )
     
     @staticmethod
     This plugin is included in the default parser configuration.
     """
     
-    def tokens(self):
+    def tokens(self, parser):
         return ((GroupPlugin.Open, 0), (GroupPlugin.Close, 0))
     
-    def filters(self):
+    def filters(self, parser):
         return ((GroupPlugin.do_groups, 0), )
     
     @staticmethod
     This plugin is included in the default parser configuration.
     """
     
-    def tokens(self):
+    def tokens(self, parser):
         return ((FieldsPlugin.Field, 0), )
     
-    def filters(self):
+    def filters(self, parser):
         return ((FieldsPlugin.do_fieldnames, 100), )
 
     @staticmethod
     This plugin is included in the default parser configuration.
     """
     
-    def tokens(self):
+    def tokens(self, parser):
         return ((CompoundsPlugin.AndNot, -10), (CompoundsPlugin.And, 0),
                 (CompoundsPlugin.Or, 0))
     
-    def filters(self):
+    def filters(self, parser):
         return ((CompoundsPlugin.do_compounds, 600), )
 
     @staticmethod
     This plugin is included in the default parser configuration.
     """
     
-    def tokens(self):
+    def tokens(self, parser):
         return ((BoostPlugin.Boost, 0), )
     
-    def filters(self):
+    def filters(self, parser):
         return ((BoostPlugin.clean_boost, 0), (BoostPlugin.do_boost, 700))
 
     @staticmethod
     This plugin is included in the default parser configuration.
     """
     
-    def tokens(self):
+    def tokens(self, parser):
         return ((NotPlugin.Not, 0), )
     
-    def filters(self):
+    def filters(self, parser):
         return ((NotPlugin.do_not, 800), )
     
     @staticmethod
     prefer this to using ``NOT``.
     """
     
-    def tokens(self):
+    def tokens(self, parser):
         return ((PlusMinusPlugin.Minus, 0), )
     
-    def filters(self):
+    def filters(self, parser):
         return ((MinusNotPlugin.do_minus, 510), )
     
     @staticmethod
     ``SimpleParser()``.
     """
     
-    def tokens(self):
+    def tokens(self, parser):
         return ((PlusMinusPlugin.Plus, 0), (PlusMinusPlugin.Minus, 0))
     
-    def filters(self):
+    def filters(self, parser):
         return ((PlusMinusPlugin.do_plusminus, 510), )
     
     @staticmethod
         self.fieldnames = fieldnames
         self.boosts = fieldboosts or {}
     
-    def filters(self):
+    def filters(self, parser):
         return ((self.do_multifield, 110), )
     
     def do_multifield(self, parser, stream):
         self.fieldboosts = fieldboosts.items()
         self.tiebreak = tiebreak
     
-    def filters(self):
+    def filters(self, parser):
         return ((self.do_dismax, 110), )
     
     def do_dismax(self, parser, stream):
             for value in values:
                 self.reverse[value] = key
         
-    def filters(self):
+    def filters(self, parser):
         return ((self.do_aliases, 90), )
     
     def do_aliases(self, parser, stream):
         self.dateparser = dateparser
         self.callback = callback
     
-    def filters(self):
+    def tokens(self, parser):
+        return ()
+    
+    def filters(self, parser):
         # Run the filter after the FieldsPlugin assigns field names
         return ((self.do_dates, 110), )
     
     def _priorized(self, methodname):
         items_and_priorities = []
         for plugin in self.plugins:
-            for item in getattr(plugin, methodname)():
+            method = getattr(plugin, methodname)
+            for item in method(self):
                 items_and_priorities.append(item)
         items_and_priorities.sort(key=lambda x: x[1])
         return [item for item, pri in items_and_priorities]

File tests/test_fields.py

 
 from whoosh import fields, qparser, query
 from whoosh.filedb.filestore import RamStorage
-from whoosh.support import numeric
+from whoosh.support import numeric, times
 
 
 class TestSchema(unittest.TestCase):
         startdt = datetime(2010, 5, 1, 0, 0, 0, 0)
         enddt = datetime(2010, 8, 31, 23, 59, 59, 999999)
         self.assertEqual(q.__class__, query.NumericRange)
-        self.assertEqual(q.start, dtf.datetime_to_long(startdt))
-        self.assertEqual(q.end, dtf.datetime_to_long(enddt))
-    
-    
+        self.assertEqual(q.start, times.datetime_to_long(startdt))
+        self.assertEqual(q.end, times.datetime_to_long(enddt))
     
     def test_boolean(self):
         schema = fields.Schema(id=fields.ID(stored=True),