Permalink
Browse files

Merge pull request #64 from davidjb/solr4-fixes

Escape forward slash characters in Solr strings for Solr 4+
  • Loading branch information...
2 parents 1d2a040 + 542273e commit 769053a54ccde90b1015c84edaf47b6a64759401 @tow committed Dec 19, 2012
Showing with 13 additions and 1 deletion.
  1. +1 −0 Changelog
  2. +1 −1 sunburnt/strings.py
  3. +11 −0 sunburnt/test_strings.py
View
@@ -1,4 +1,5 @@
* 0.7 : unreleased
+ - Escape forward slash characters for compatibility with Solr 4.0 (@davidjb)
- Fix handling of queries with ``boost_relevancy`` applied - boost was
previously lost in some cases. (@davidjb)
- Ensure 'more like this' results are transformed using a query's
View
@@ -5,7 +5,7 @@ class SolrString(unicode):
# The behaviour below is only really relevant for String fields rather
# than Text fields - most queryparsers will strip these characters out
# for a text field anyway.
- lucene_special_chars = '+-&|!(){}[]^"~*?: \t\v\\'
+ lucene_special_chars = '+-&|!(){}[]^"~*?: \t\v\\/'
def escape_for_lqs_term(self):
if self in ["AND", "OR", "NOT", ""]:
return u'"%s"' % self
View
@@ -0,0 +1,11 @@
+from .strings import RawString
+
+
+def test_string_escape():
+ """ Ensure that string characters are escaped correctly for Solr queries.
+ """
+ test_str = u'+-&|!(){}[]^"~*?: \t\v\\/'
+ escaped = RawString(test_str).escape_for_lqs_term()
+ assert escaped == u'\\+\\-\\&\\|\\!\\(\\)\\{\\}\\[\\]\\^\\"\\~\\*\\?\\:\\ \\\t\\\x0b\\\\\\/'
+
+

0 comments on commit 769053a

Please sign in to comment.