Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #64 from davidjb/solr4-fixes

Escape forward slash characters in Solr strings for Solr 4+
  • Loading branch information...
commit 769053a54ccde90b1015c84edaf47b6a64759401 2 parents 1d2a040 + 542273e
Toby White authored
Showing with 13 additions and 1 deletion.
  1. +1 −0  Changelog
  2. +1 −1  sunburnt/strings.py
  3. +11 −0 sunburnt/test_strings.py
1  Changelog
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
2  sunburnt/strings.py
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
11 sunburnt/test_strings.py
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\\\\\\/'
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.