Skip to content
This repository was archived by the owner on Nov 21, 2017. It is now read-only.

Commit ec2f866

Browse files
committed
Schemas cleanup: Handle IntNodes properly
IntNodes were getting caught by the StandardAnalyzer for small values. This could probably be avoided by using whoosh.fields.INT in the schema declaration as well (and that should get done eventually). However, a SimpleAnalyzer as the default is better for l2cs' case anyway, because the CloudSearch server will handle stop words and query optimizations. Additionally, IntNodes are now properly generating unicode elements.
1 parent b9a2a88 commit ec2f866

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

l2cs.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import sys
1111

12+
import whoosh.analysis
1213
import whoosh.fields
1314
import whoosh.qparser.default
1415
import whoosh.qparser.plugins
@@ -17,7 +18,7 @@
1718
import whoosh.query
1819

1920

20-
__version__ = "2.0.1"
21+
__version__ = "2.0.2"
2122

2223

2324
HANDLERS = {}
@@ -102,7 +103,7 @@ def walk_clause(clause):
102103
class IntNode(whoosh.qparser.syntax.WordNode):
103104
def __init__(self, value):
104105
self.__int_value = int(value)
105-
whoosh.qparser.syntax.WordNode.__init__(self, unicode(self.__int_value))
106+
whoosh.qparser.syntax.WordNode.__init__(self, value)
106107

107108
def query(self, parser):
108109
q = whoosh.qparser.syntax.WordNode.query(self, parser)
@@ -144,10 +145,10 @@ def modify_node(self, fieldname, node):
144145
class YesNoPlugin(PseudoFieldPlugin):
145146
def modify_node(self, fieldname, node):
146147
if node.has_text:
147-
if node.text in ("yes", "y", "1"):
148-
new_node = IntNode(1)
148+
if node.text in (u"yes", u"y", u"1"):
149+
new_node = IntNode(u'1')
149150
else:
150-
new_node = IntNode(0)
151+
new_node = IntNode(u'0')
151152
new_node.set_fieldname(fieldname)
152153
return new_node
153154
else:
@@ -276,11 +277,15 @@ def make_schema(fields, datefields=()):
276277
additionally create DATETIME fields with those names
277278
278279
'''
279-
fields = dict.fromkeys(fields, whoosh.fields.TEXT)
280+
text_field = whoosh.fields.TEXT(analyzer=whoosh.analysis.SimpleAnalyzer())
281+
fields = dict.fromkeys(fields, text_field)
280282
if datefields:
281283
datefields = dict.fromkeys(datefields, whoosh.fields.DATETIME)
282284
fields.update(datefields)
283-
return whoosh.fields.Schema(**fields)
285+
schema = whoosh.fields.Schema()
286+
for fieldname in fields:
287+
schema.add(fieldname, fields[fieldname])
288+
return schema
284289

285290

286291
def convert(query, parser):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use_setuptools()
88
from setuptools import setup
99

10-
version = "2.0.1"
10+
version = "2.0.2"
1111

1212
setup(
1313
name='l2cs',

test_l2cs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ def test_unicode_intnodes1(self):
165165
self._run_test(u"count:1", u"count:1", self.schema_parser)
166166
except AssertionError as e:
167167
self.fail(e)
168+
169+
def test_intnode_empty1(self):
170+
self._run_test(u"count:''", u"")
168171

169172

170173
if __name__ == '__main__':

0 commit comments

Comments
 (0)