def search(self): """ Construct the Search object. """ s = Search(doc_type=self.doc_types, using=es.client, index=es.index_name) # don't return any fields, just the metadata s = s.fields([]) # Sort from parameters s = s.sort(*self.sorts) # Paginate from parameters s = s[self.page_start:self.page_end] # Same construction as parent class # Allows to give the same signature as simple search # ie. Response(data) instead of Response(search, data) return s.response_class(partial(SearchResult, self))
def search(self): """ Construct the Search object. """ s = Search(doc_type=self.doc_types, index=self.index) return s.response_class(partial(ImprovedFacetedResponse, self))
def search_content( self, search_string: str, size: typing.Optional[int], page_nb: typing.Optional[int], content_types: typing.Optional[typing.List[str]] = None, show_deleted: bool = False, show_archived: bool = False, show_active: bool = True, ) -> ContentSearchResponse: """ Search content into elastic search server: - do no show archived/deleted content by default - filter content found according to workspace of current_user """ # FIXME BS 2019-06-10: Load ES model only when ES search (see #1892) from tracim_backend.lib.search.es_models import IndexedContent if not search_string: return EmptyContentSearchResponse() filtered_workspace_ids = self._get_user_workspaces_id( min_role=UserRoleInWorkspace.READER) # INFO - G.M - 2019-05-31 - search using simple_query_string, which mean user-friendly # syntax to match complex case, # see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html search = Search( using=self.es, doc_type=IndexedContent, index=self.index_document_alias ).query( "simple_query_string", query=search_string, # INFO - G.M - 2019-05-31 - "^5" means x5 boost on field, this will reorder result and # change score according to this boost. label is the most important, content is # important too, content of comment is less important. filename and file_extension is # only useful to allow matching "png" or "nameofmycontent.png". fields=[ "label^5", "filename", "file_extension", "raw_content^3", "comments.raw_content", "attachment.content^3", ], ) # INFO - G.M - 2019-05-14 - do not show deleted or archived content by default if not show_active: search = search.exclude("term", is_active=True) if not show_deleted: search = search.exclude("term", is_deleted=True) search = search.filter("term", deleted_through_parent_id=0) if not show_archived: search = search.exclude("term", is_archived=True) search = search.filter("term", archived_through_parent_id=0) search = search.response_class(ESContentSearchResponse) # INFO - G.M - 2019-05-21 - remove raw content of content of result in elasticsearch # result, because we do not need them and for performance reasons. search = search.source( exclude=["raw_content", "*.raw_content", "attachment.*", "file"]) # INFO - G.M - 2019-05-16 - None is different than empty list here, None mean we can # return all workspaces content, empty list mean return nothing. if size: search = search.extra(size=size) if page_nb: search = search.extra( from_=self.offset_from_pagination(size, page_nb)) if filtered_workspace_ids is not None: search = search.filter("terms", workspace_id=filtered_workspace_ids) if content_types: search = search.filter("terms", content_type=content_types) res = search.execute() return res
def search(self): es = get_query_client() s = Search(doc_type=self.doc_types, index=index_name(), using=es) s = s.params(size=BATCH_SIZE) return s.response_class(FacetedResponse)