class WildcardString(unicode):
    def __new__(cls, s):
        return unicode.__new__(cls, s)

    def __init__(self, s):
        self.chars = self.get_wildcards(s)

    class SpecialChar(object):
        def __unicode__(self):
            return unicode(self.char)
    class Asterisk(SpecialChar):
        char = '*'
    class QuestionMark(SpecialChar):
        char = '?'

    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 == '\\':
                backslash = True
            elif c == '*':
                chars.append(self.Asterisk())
            elif c == '?':
                chars.append(self.QuestionMark())
            else:
                chars.append(c)
        if backslash:
            chars.append('\\')
        return chars

    # If any of your queries rely on the exact behaviour below, you'd better
    # either have a very specialized queryparser, or you're not going to get
    # the results you expect. Any halfway normal Solr query parser will end up
    # losing most of these special characters before they hit Lucene anyway.
    lucene_special_chars = '+-&|!(){}[]^"~*?: \t\v\\'
    def escape_for_lqs_term(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 ''.join(chars)

@@ -960,303 +960,174 @@
   # 
-If any of your queries rely on the exact behaviour below, you'd better%0A    # either have a very specialized queryparser, or you're not going to get%0A    # the results you expect. Any halfway normal Solr
+The behaviour below is only really relevant for String fields rather%0A    # than Text fields - most
  query
- 
 parser
+s
  will 
-end up%0A    # losing most of these special characters before they hit Lucene
+strip these characters out%0A    # for a text field
  any
@@ -1212,32 +1212,106 @@
 lqs_term(self):%0A
+        if self in %5B%22AND%22, %22OR%22, %22NOT%22%5D:%0A            return '%22%25s%22' %25 self%0A
         chars = 

Fix use of AND, OR, NOT as search terms