def annotations_index(context, request): """Do a search for all annotations on anything and return results. This will use the default limit, 20 at time of writing, and results are ordered most recent first. """ user = get_user(request) return Annotation.search(user=user)
def search(context, request): """Search the database for annotations matching with the given query.""" # The search results are filtered for the authenticated user user = get_user(request) # Compile search parameters search_params = _search_params(request.params, user=user) log.debug("Searching with user=%s, for uri=%s", user.id if user else 'None', search_params.get('uri')) results = Annotation.search(**search_params) total = Annotation.count(**search_params) return { 'rows': results, 'total': total, }
def _search(request_params, user=None): # Compile search parameters search_params = _search_params(request_params, user=user) log.debug("Searching with user=%s, for uri=%s", user.id if user else 'None', request_params.get('uri')) if 'any' in search_params['query']: # Handle any field parameters query = _add_any_field_params_into_query(search_params) results = Annotation.search_raw(query) params = {'search_type': 'count'} count = Annotation.search_raw(query, params, raw_result=True) total = count['hits']['total'] else: results = Annotation.search(**search_params) total = Annotation.count(**search_params) return { 'rows': results, 'total': total, }