Permalink
Browse files

default are escaped strings, if we need wildcards we need to set it b…

…y hand
  • Loading branch information...
1 parent 7d0f066 commit ed52b91dd44d76701d3c024ff0d96ddf3b823b2a @delijati delijati committed Oct 21, 2013
Showing with 12 additions and 4 deletions.
  1. +4 −2 sunburnt/search.py
  2. +8 −2 sunburnt/tests/test_search.py
View
@@ -104,8 +104,10 @@ def to_solr(self, value):
return unicode(value)
def to_query(self, value):
- ret = sunburnt.strings.RawString(self.to_solr(value)
- ).escape_for_lqs_term()
+ ret = sunburnt.strings.RawString(
+ self.to_solr(value)).escape_for_lqs_term()
+ if isinstance(value, sunburnt.strings.WildcardString):
+ ret = value.escape_for_lqs_term()
return ret
range_query_templates = {
@@ -17,7 +17,7 @@
SortOptions, FieldLimitOptions, FacetOptions,
GroupOptions, HighlightOptions,
MoreLikeThisOptions, params_from_dict)
-from sunburnt.strings import RawString
+from sunburnt.strings import WildcardString
from sunburnt.sunburnt import SolrInterface
from .test_sunburnt import MockConnection, MockResponse
from nose.tools import assert_equal
@@ -210,7 +210,7 @@ class MockInterface(object):
([], {'string_field': ['hello world', 'goodbye, cruel world']},
[("q", u"string_field:goodbye,\\ cruel\\ world AND string_field:hello\\ world")]),
# Raw strings
- ([], {'string_field': RawString("abc*???")},
+ ([], {'string_field': "abc*???"},
[("q", "string_field:abc\\*\\?\\?\\?")]),
],
}
@@ -419,6 +419,12 @@ def check_bad_option_data(OptionClass, kwargs):
[('q', u'blah AND (def OR ghi)^1.5')]),
(lambda q: q.query("blah").query(q.Q("def", ~q.Q("pqr") | q.Q("mno")) ** 1.5),
[('q', u'blah AND (def AND ((*:* AND NOT pqr) OR mno))^1.5')]),
+ #wildcard
+ (lambda q: q.query("blah").query(q.Q(WildcardString("def*"),
+ ~q.Q(miu=WildcardString("pqr*")) | q.Q("mno")) ** 1.5),
+ [('q', 'blah AND (def* AND ((*:* AND NOT miu:pqr*) OR mno))^1.5')]),
+ (lambda q: q.query("blah").query(q.Q("def*", ~q.Q(miu="pqr*") | q.Q("mno")) ** 1.5),
+ [('q', 'blah AND (def\\* AND ((*:* AND NOT miu:pqr\\*) OR mno))^1.5')]),
# And boost_relevancy
(lambda q: q.query("blah").boost_relevancy(1.5, int_field=3),
[('q', u'blah OR (blah AND int_field:3^1.5)')]),

0 comments on commit ed52b91

Please sign in to comment.