Problems with solr 4

279 views
Skip to first unread message

Gustavo Carvalho

unread,
Oct 26, 2012, 1:34:36 PM10/26/12
to python-...@googlegroups.com
Hi,

I'm stumped on a weird problem.
I developed using sunburnt and solr 3.6, but was forced to use solr 4 in production.
I had a few issues, but most were easily sorted... except one.
A filter_exclude causes a "ParseException: Cannot parse <query fields>". I noticed that sunburnt escapes all ":" everywhere, except in the filter_exclude.
Is this a bug in sunburnt? Is there a quick solution?

Cheers,

Gus

Gustavo Carvalho

unread,
Oct 26, 2012, 5:12:50 PM10/26/12
to python-...@googlegroups.com
Ok, I've tracked it down to the treatment done to values in fields, in my case an fq.
Specifically, the following, in strings.py :
===
    def escape_for_lqs_term(self):
        if self in ["AND", "OR", "NOT", ""]:
            return u'"%s"' % self
        chars = []
        for c in self.chars:
            if isinstance(c, basestring) and c in self.lucene_special_chars:
                chars.append(u'\%s'%c)
            else:
                chars.append(u'%s'%c)
        return u''.join(chars)
===

It seems that solr 4 is not dealing with using an '\' to escape special chars.
it works if I grab the url generated by sunburnt and just use the original value between double quotes (and url-encode, of course)

Is anyone else getting this problem?

Gustavo Carvalho

unread,
Oct 26, 2012, 6:28:53 PM10/26/12
to python-...@googlegroups.com
If anyone ever trips on this issue, the solution seems to be KISS simple: just add the "/" char to the lucene_special_chars constant.
===
lucene_special_chars = '+-&|!(){}[]^"~*?: \t\v\\/'
===
I have no idea why it worked before and I suspect it's probably a change in urllib rather than a sunburnt problem, but I really have no time investigate any deeper.

cheers,

gus


On Friday, October 26, 2012 6:34:36 PM UTC+1, Gustavo Carvalho wrote:

David Beitey

unread,
Dec 16, 2012, 9:51:38 PM12/16/12
to python-...@googlegroups.com
The change here is because of the special characters handling in Solr 4.  The forward slash is now a special character and needs to be escaped accordingly in queries.  I've submitted a pull request to fix this within Sunburnt: https://github.com/tow/sunburnt/pull/64

Details regarding this (for the interested) are at http://wiki.apache.org/solr/SolrQuerySyntax#Default_QParserPlugin:_LuceneQParserPlugin with links to the relevant query syntax for each different version.

Cheers,
David
Reply all
Reply to author
Forward
0 new messages