# HG changeset patch # User Arthur Lutz <arthur.lutz@logilab.fr> # Date 1464362891 -7200 # Fri May 27 17:28:11 2016 +0200 # Node ID 124768a2e21caa7bd127293f2865439100817faf # Parent 4c406b718a92546a3ba2cf2a93e0eb7704380978 [views] exact search on code (example with Did & unitid, and cote:search_term) should go into specific cube diff --git a/views.py b/views.py --- a/views.py +++ b/views.py @@ -44,11 +44,12 @@ class CWFacetedSearch(FacetedSearch): # fields that should be searched - fields = ["title^3", "name^3", "content^2", 'content', '_all'] + fields = ["unitid^6", "title^3", "unittitle^3", "name^3", "content^2", 'content', '_all'] facets = { # use bucket aggregations to define facets 'cw_etype': TermsFacet(field='cw_etype'), + 'unitid': TermsFacet(field='unitid'), 'creation_date': DateHistogramFacet(field='creation_date', interval='month'), 'commemoration_year': DateHistogramFacet(field='commemoration_year', interval='year'), 'year': DateHistogramFacet(field='year', interval='year'), @@ -98,6 +99,9 @@ start = (max(int(value) - 1, 0)) * 10 stop = start + 10 indexable = indexable_types(self._cw.vreg.schema) + if query_string.startswith('cote:'): + query_string = query_string.split(':')[1] + facet_selections['unitid'] = query_string search = CWFacetedSearch(query_string, facet_selections, doc_types=indexable)[start:stop] @@ -120,9 +124,10 @@ infos = result.to_dict() infos['_score'] = result.meta.score infos['keys'] = result.to_dict().keys() - infos.setdefault('title', infos.get('name', infos.get('reference', u'n/a'))) + infos['url'] = infos['cwuri'].startswith('_auto_generated') and infos['eid'] or infos['cwuri'] + infos.setdefault('title', infos.get('name', infos.get('reference', infos.get('unittitle', u'n/a')))) try: - self.w(u'<a href="%(cwuri)s">%(title)s</a> (%(_score).2f)<br/>' % (infos)) + self.w(u'<a href="%(url)s">%(title)s</a> (%(_score).2f)<br/>' % (infos)) if self._cw.form.get('debug-es'): self.w(u' [%(keys)s] <br/>' % infos) except KeyError: