Skip to content
Snippets Groups Projects
Commit 5021a39f390e authored by Arthur Lutz's avatar Arthur Lutz
Browse files

search for containers

parent b2a9d053f347
No related branches found
No related tags found
No related merge requests found
......@@ -39,8 +39,11 @@
'creation_date': DateHistogramFacet(field='creation_date', interval='month'),
}
def __init__(self, query=None, filters={}, doc_types=None, index=None):
def __init__(self, query=None, filters={},
doc_types=None, index=None,
parents_for=None,
children_for=None):
if index:
self.index = index
if doc_types:
self.doc_types = doc_types
......@@ -43,8 +46,10 @@
if index:
self.index = index
if doc_types:
self.doc_types = doc_types
self.parents_for = parents_for
self.children_for = children_for
super(CWFacetedSearch, self).__init__(query, filters)
def query(self, search, query):
if query:
......@@ -47,8 +52,12 @@
super(CWFacetedSearch, self).__init__(query, filters)
def query(self, search, query):
if query:
return compose_search(search, query=query, fields=self.fields)
return compose_search(search,
query=query,
fields=self.fields,
parents_for=self.parents_for,
children_for=self.children_for)
# return search.query('multi_match', fields=self.fields,
# query=query)
return search
......@@ -82,6 +91,7 @@
indexer.get_connection()
facet_selections = {}
start, stop = 0, 10
parents_for = children_for = None
for key, value in self._cw.form.items():
if key.startswith('es_'):
facet_selections[key.replace('es_', '')] = value
......@@ -85,6 +95,10 @@
for key, value in self._cw.form.items():
if key.startswith('es_'):
facet_selections[key.replace('es_', '')] = value
if key == 'parents_for':
parents_for = value
if key == 'children_for':
children_for = value
if key == 'page':
start = (max(int(value) - 1, 0)) * 10
stop = start + 10
......@@ -88,8 +102,11 @@
if key == 'page':
start = (max(int(value) - 1, 0)) * 10
stop = start + 10
search = self.customize_search(query_string, facet_selections,
start, stop)
search = self.customize_search(query_string,
facet_selections,
start, stop,
parents_for=parents_for,
children_for=children_for)
# force search to be executed on our index, otherwise FacetSearch
# uses '_all'
search.index = self._cw.vreg.config['index-name']
......@@ -104,7 +121,7 @@
self.display_results(response)
def customize_search(self, query_string, facet_selections,
start=0, stop=10):
start=0, stop=10, **kwargs):
'''
This is where one can customize the search by modifying the
query string and facet selection in an inherited class.
......@@ -119,7 +136,8 @@
return CWFacetedSearch(query_string,
facet_selections,
index=self._cw.vreg.config.get('index-name'),
doc_types=indexable)[start:stop]
doc_types=indexable,
**kwargs)[start:stop]
def display_results(self, response):
'''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment