Reorganise get_inner_query

# Conflicts:
#	wagtail/search/backends/elasticsearch2.py
This commit is contained in:
Karl Hobley 2017-12-15 11:51:23 +00:00 committed by Bertrand Bordage
parent 7915a8b127
commit 52691766c5

View file

@ -375,41 +375,42 @@ class Elasticsearch2SearchQueryCompiler(BaseSearchQueryCompiler):
def get_inner_query(self):
if isinstance(self.query, MatchAll):
return {'match_all': {}}
elif isinstance(self.query, PlainText):
fields = self.remapped_fields or ['_all', '_partials']
operator = self.query.operator
if not isinstance(self.query, PlainText):
if len(fields) == 1:
if operator == 'or':
return {
'match': {
fields[0]: self.query.query_string,
}
}
return {
'match': {
fields[0]: {
'query': self.query.query_string,
'operator': operator,
}
}
}
query = {
'multi_match': {
'query': self.query.query_string,
'fields': fields,
}
}
if operator != 'or':
query['multi_match']['operator'] = operator
return query
else:
raise NotImplementedError(
'`%s` is not supported by the Elasticsearch search backend.'
% self.query.__class__.__name__)
fields = self.remapped_fields or ['_all', '_partials']
operator = self.query.operator
if len(fields) == 1:
if operator == 'or':
return {
'match': {
fields[0]: self.query.query_string,
}
}
return {
'match': {
fields[0]: {
'query': self.query.query_string,
'operator': operator,
}
}
}
query = {
'multi_match': {
'query': self.query.query_string,
'fields': fields,
}
}
if operator != 'or':
query['multi_match']['operator'] = operator
return query
def get_content_type_filter(self):
# Query content_type using a "match" query. See comment in
# Elasticsearch2Mapping.get_document for more details