def search( cls, query_string='', query_limit=20, offset=0, sort_options=None, returned_fields=None): """Searches for documents that match a given query string. Args: query_string: str, the query to match against documents in the index query_limit: int, the limit on number of documents to return in results. offset: int, the number of matched documents to skip before beginning to return results. sort_options: search.SortOptions, an object specifying a multi-dimensional sort over search results. returned_fields: List[str], an iterable of names of fields to return in search results. Returns: A SearchResults object containing a list of documents matched by the query. """ index = cls.get_index() try: query = search.Query( query_string=cls.format_query(query_string), options=search.QueryOptions( offset=offset, limit=query_limit, sort_options=sort_options, returned_fields=returned_fields), ) except search.QueryError: return search.SearchResults(number_found=0) return index.search(query)
def test_audit_remove_devices(self, mock_get_shelf, mock_model_device_search): shelf = self.device2_key.get() shelf.shelf = self.shelf.key shelf.put() mock_model_device_search.return_value = (search.SearchResults( results=[ search.ScoredDocument(doc_id=self.device2_key.urlsafe()), search.ScoredDocument(doc_id=self.device3_key.urlsafe()), search.ScoredDocument(doc_id=self.device4_key.urlsafe()) ], number_found=3)) mock_get_shelf.return_value = self.shelf request = shelf_messages.ShelfAuditRequest( shelf_request=shelf_messages.ShelfRequest( location=self.shelf.location), device_identifiers=[self.device3_key.get().serial_number]) self.service.audit(request) self.assertEqual(self.device3_key.get().shelf, self.shelf.key) self.assertEqual(self.device2_key.get().shelf, None) self.assertEqual(self.device4_key.get().shelf, None)
def search(cls, query_string='', query_limit=20, cursor=None, sort_options=None, returned_fields=None): """Searches for documents that match a given query string. Args: query_string: str, the query to match against documents in the index query_limit: int, the limit on number of documents to return in results. cursor: search.Cursor, a cursor describing where to get the next set of results, or to provide next cursors in SearchResults. sort_options: search.SortOptions, an object specifying a multi-dimensional sort over search results. returned_fields: list|str|, an iterable of names of fields to return in search results. Returns: A SearchResults object containing a list of documents matched by the query. """ index = cls.get_index() try: query = search.Query( query_string=cls.format_query(query_string), options=search.QueryOptions(cursor=cursor, limit=query_limit, sort_options=sort_options, returned_fields=returned_fields), ) except search.QueryError: return search.SearchResults(number_found=0) return index.search(query)