MCPcopy Index your code
hub / github.com/django-haystack/django-haystack / AutoQuery

Class AutoQuery

haystack/inputs.py:94–133  ·  view source on GitHub ↗

A convenience class that handles common user queries. In addition to cleaning all tokens, it handles double quote bits as exact matches & terms with '-' in front as NOT queries.

Source from the content-addressed store, hash-verified

92
93
94class AutoQuery(BaseInput):
95 """
96 A convenience class that handles common user queries.
97
98 In addition to cleaning all tokens, it handles double quote bits as
99 exact matches & terms with '-' in front as NOT queries.
100 """
101
102 input_type_name = "auto_query"
103 post_process = False
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

auto_queryMethod · 0.90
test_query_generationMethod · 0.90
test_query_generationMethod · 0.90
test_query_generationMethod · 0.90
test_query_generationMethod · 0.90
test_query_generationMethod · 0.90

Calls

no outgoing calls

Tested by 5

test_query_generationMethod · 0.72
test_query_generationMethod · 0.72
test_query_generationMethod · 0.72
test_query_generationMethod · 0.72
test_query_generationMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…