Exemplo n.º 1
0
 def accept(self, visitor):
     """Store intermediate results to the cache."""
     results = get_results_cache(str(self.query), self.collection)
     if results is None:
         results = self.query.accept(visitor)
         set_results_cache(results, str(self.query), self.collection)
     return results
Exemplo n.º 2
0
def search(self, user_info=None, collection=None):
    """FIXME new API."""
    from invenio.modules.search.utils import get_records_that_can_be_displayed
    from invenio.modules.search.walkers.search_unit import SearchUnit
    results = get_results_cache(self._query, collection)
    if results is None:
        results = self.query.accept(SearchUnit())
        set_results_cache(results, self._query, collection)

    if 'filter' in request.values:
        from invenio.modules.search.facet_builders import \
            faceted_results_filter
        from invenio.modules.search.registry import facets
        try:
            filter_data = json.loads(request.values.get('filter', '[]'))
            results = faceted_results_filter(results, filter_data, facets)
        except Exception:
            flash(_('Invalid filter data'), 'error')

    return get_records_that_can_be_displayed(
        user_info.get('precached_permitted_restricted_collections', []),
        hitset_in_any_collection=results,
        current_coll=collection
    )