MCPcopy Create free account
hub / github.com/django-haystack/django-haystack / prepare

Method prepare

haystack/inputs.py:106–133  ·  view source on GitHub ↗
(self, query_obj)

Source from the content-addressed store, hash-verified

104 exact_match_re = re.compile(r'"(?P<phrase>.*?)"')
105
106 def prepare(self, query_obj):
107 query_string = super().prepare(query_obj)
108 exacts = self.exact_match_re.findall(query_string)
109 tokens = []
110 query_bits = []
111
112 for rough_token in self.exact_match_re.split(query_string):
113 if not rough_token:
114 continue
115 elif rough_token not in exacts:
116 # We have something that's not an exact match but may have more
117 # than on word in it.
118 tokens.extend(rough_token.split(" "))
119 else:
120 tokens.append(rough_token)
121
122 for token in tokens:
123 if not token:
124 continue
125 if token in exacts:
126 query_bits.append(Exact(token, clean=True).prepare(query_obj))
127 elif token.startswith("-") and len(token) > 1:
128 # This might break Xapian. Check on this.
129 query_bits.append(Not(token[1:]).prepare(query_obj))
130 else:
131 query_bits.append(Clean(token).prepare(query_obj))
132
133 return " ".join(query_bits)
134
135
136class AltParser(BaseInput):

Callers 6

Calls 4

ExactClass · 0.85
NotClass · 0.85
CleanClass · 0.85
prepareMethod · 0.45

Tested by 6