mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-11 16:53:10 +00:00
Reorganise get_inner_query
# Conflicts: # wagtail/search/backends/elasticsearch2.py
This commit is contained in:
parent
7915a8b127
commit
52691766c5
1 changed files with 31 additions and 30 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue