# HG changeset patch # User Arthur Lutz <arthur.lutz@logilab.fr> # Date 1472572391 -7200 # Tue Aug 30 17:53:11 2016 +0200 # Node ID 5021a39f390e28d843c855513bd1c6071057d304 # Parent b2a9d053f34724b5115e3f6837a55cdd31659de0 search for containers diff --git a/views.py b/views.py --- a/views.py +++ b/views.py @@ -39,16 +39,25 @@ '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 + self.parents_for = parents_for + self.children_for = children_for 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,14 +91,22 @@ 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 + 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 - 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): '''