lugensa / scorched

Sunburnt offspring solr client
MIT License
27 stars 19 forks source link

Wildcard strings with spaces not being handled properly #21

Open upman opened 8 years ago

upman commented 8 years ago
 q = scorched.strings.WildcardString('abc abc*')
 si.query(q)

raises scorched.exc.SolrError: <Response [400]>

upman commented 8 years ago

I was able to fix this with a little change to strings.py

def get_wildcards(self, s):
        backslash = False
        i = 0
        chars = []
        for c in s:
            if backslash:
                backslash = False
                chars.append(c)
                continue
            i += 1
            if c == u'\\':
                backslash = True
            elif c == u'*':
                chars.append(self.Asterisk())
            elif c == u'?':
                chars.append(self.QuestionMark())
            elif c == ' ':
                ###
                ### Escape the spaces explicitly
                ###
                chars.append('\\ ')
            else:
                chars.append(c)
        if backslash:
            chars.append(u'\\')
        return chars

Don't think this is a good fix though. I think the other special characters '+-&|!(){}[]^"~: \t\v\/' have to be escaped as well?

bdew70 commented 8 years ago

+1