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

Commit d9a40b5

Browse files
committed
Revert "Fix issue #16: Incorrect quoting of phrases"
This reverts commit 76eff93. The "fix" creates two meanings for double-quotes: * encapsulating a query against a field, e.g.: foo:"bar baz" * grouping exact phrases, e.g.: "jon smith" The two must be disambiguated to avoid confusion or loss of features
1 parent 76eff93 commit d9a40b5

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

l2cs.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import whoosh.query
1717

1818

19-
__version__ = "1.0.7"
19+
__version__ = "1.0.8"
2020

2121

2222
HANDLERS = {}
@@ -38,10 +38,6 @@ def build_null(clause):
3838
yield ""
3939

4040

41-
def _fix_quotes(phrase):
42-
return phrase.replace(r"'", r"\'").replace(r'"', r'\"')
43-
44-
4541
@handler(whoosh.query.Term, whoosh.query.Phrase, whoosh.query.Prefix)
4642
def build_field(clause):
4743
integer_field = getattr(clause, "integer_field", False)
@@ -50,17 +46,15 @@ def build_field(clause):
5046
yield clause.fieldname
5147
yield " '"
5248
if isinstance(clause, whoosh.query.Term):
53-
yield _fix_quotes(clause.text)
49+
yield clause.text.replace(r"'", r"\'")
5450
elif isinstance(clause, whoosh.query.Prefix):
55-
yield _fix_quotes(clause.text)
51+
yield clause.text.replace(r"'", r"\'")
5652
yield '*'
5753
elif isinstance(clause, whoosh.query.Phrase):
58-
yield '"'
5954
for word in clause.words[:-1]:
60-
yield _fix_quotes(word)
55+
yield word.replace(r"'", r"\'")
6156
yield " "
6257
yield clause.words[-1]
63-
yield '"'
6458
yield "')"
6559
else:
6660
yield clause.fieldname

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 = "1.0.7"
10+
version = "1.0.8"
1111

1212
setup(
1313
name='l2cs',

test_l2cs.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_fields2(self):
3434

3535
# phrases
3636
def test_phrases1(self):
37-
self._run_test('"foo bar baz"', "(field text '\"foo bar baz\"')")
37+
self._run_test('"foo bar baz"', "(field text 'foo bar baz')")
3838

3939
# AND clauses
4040
def test_and1(self):
@@ -75,12 +75,9 @@ def test_not9(self):
7575

7676
# quotes
7777
def test_quote1(self):
78-
self._run_test("hello:\"goodbye you're sir\"", "(field hello '\"goodbye you\\'re sir\"')")
78+
self._run_test("hello:\"goodbye you're sir\"", "(field hello 'goodbye you\\'re sir')")
7979
def test_quote2(self):
80-
self._run_test("hello:\"goodbye you''re sir\"", "(field hello '\"goodbye you\\'\\'re sir\"')")
81-
def test_quote3(self):
82-
'''Stray double-quotes get escaped'''
83-
self._run_test('"foo bar" baz"', '(and (field text \'"foo bar"\') (field text \'baz\\"\'))')
80+
self._run_test("hello:\"goodbye you''re sir\"", "(field hello 'goodbye you\\'\\'re sir')")
8481

8582
# int fields
8683
def test_int1(self):

0 commit comments

Comments
 (0)