Skip to content

Commit 7cc97b8

Browse files
committed
Merge pull request django-haystack#840 from postatum/fix_issue_807
Fixed issue django-haystack#807
2 parents 85f41ae + e1b7269 commit 7cc97b8

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,4 @@ Thanks to
8484
* Pablo SEMINARIO (pabluk) for a docs fix.
8585
* Eric Thurgood (ethurgood) for a import fix in the Elasticssearch backend.
8686
* Revolution Systems & The Python Software Foundation for funding a significant portion of the port to Python 3!
87+
* Artem Kostiuk (postatum) for patch allowing to search for slash character in ElasticSearch since Lucene 4.0.

haystack/backends/elasticsearch_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ElasticsearchSearchBackend(BaseSearchBackend):
4343
# The '\\' must come first, so as not to overwrite the other slash replacements.
4444
RESERVED_CHARACTERS = (
4545
'\\', '+', '-', '&&', '||', '!', '(', ')', '{', '}',
46-
'[', ']', '^', '"', '~', '*', '?', ':',
46+
'[', ']', '^', '"', '~', '*', '?', ':', '/',
4747
)
4848

4949
# Settings to add an n-gram & edge n-gram analyzer.

tests/elasticsearch_tests/tests/elasticsearch_query.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def test_build_query_boolean(self):
2323
self.sq.add_filter(SQ(content=True))
2424
self.assertEqual(self.sq.build_query(), '(True)')
2525

26+
def test_regression_slash_search(self):
27+
self.sq.add_filter(SQ(content='hello/'))
28+
self.assertEqual(self.sq.build_query(), '(hello\\/)')
29+
2630
def test_build_query_datetime(self):
2731
self.sq.add_filter(SQ(content=datetime.datetime(2009, 5, 8, 11, 28)))
2832
self.assertEqual(self.sq.build_query(), '(2009-05-08T11:28:00)')
@@ -105,7 +109,7 @@ def test_build_query_wildcard_filter_types(self):
105109
def test_clean(self):
106110
self.assertEqual(self.sq.clean('hello world'), 'hello world')
107111
self.assertEqual(self.sq.clean('hello AND world'), 'hello and world')
108-
self.assertEqual(self.sq.clean('hello AND OR NOT TO + - && || ! ( ) { } [ ] ^ " ~ * ? : \ world'), 'hello and or not to \\+ \\- \\&& \\|| \\! \\( \\) \\{ \\} \\[ \\] \\^ \\" \\~ \\* \\? \\: \\\\ world')
112+
self.assertEqual(self.sq.clean('hello AND OR NOT TO + - && || ! ( ) { } [ ] ^ " ~ * ? : \ / world'), 'hello and or not to \\+ \\- \\&& \\|| \\! \\( \\) \\{ \\} \\[ \\] \\^ \\" \\~ \\* \\? \\: \\\\ \\/ world')
109113
self.assertEqual(self.sq.clean('so please NOTe i am in a bAND and bORed'), 'so please NOTe i am in a bAND and bORed')
110114

111115
def test_build_query_with_models(self):

0 commit comments

Comments
 (0)