def set_query(self, query): """ Set the query object @param query: @type query: str or pylastica.query.Query or pylastica.query.abstract.AbstractQuery @return: @rtype: self """ query = pylastica.query.Query.create(query) data = query.to_dict() return self.set_param('query', data['query'])
def set_query(self, query): """ Set the query object @param query: query @type query: str or pylastica.query.Query or pylastica.query.abstract.AbstractQuery @return: @rtype: self """ query = pylastica.query.Query.create(query) data = query.to_dict() return self.set_param('query', data['query'])
def count(self, query=None): """ Counts results for a query. If no query is set, a MatchAll query is used. @param query: dict with all query data or a Query object @type query: dict or pylastica.query.Query @return: number of docs matching the query @rtype: int """ self.set_options_and_query(None, query) query = self.query response = self.client.request(self.path, data=query.to_dict(), query={self.OPTION_SEARCH_TYPE: self.SEARCH_TYPE_COUNT}) return pylastica.resultset.ResultSet(response, query).get_total_hits()
def search(self, query=None, options=None): """ Search in the set indices and types @param query: @type query: mixed @param options: optional limit or dict of options @type options: int or dict @return: @rtype: pylastica.resultset.ResultSet """ self.set_options_and_query(options, query) query = self.query response = self.client.request(self.path, data=query.to_dict(), query=self.options) return pylastica.resultset.ResultSet(response, query)
def count(self, query=None): """ Counts results for a query. If no query is set, a MatchAll query is used. @param query: dict with all query data or a Query object @type query: dict or pylastica.query.Query @return: number of docs matching the query @rtype: int """ self.set_options_and_query(None, query) query = self.query response = self.client.request( self.path, data=query.to_dict(), query={self.OPTION_SEARCH_TYPE: self.SEARCH_TYPE_COUNT}) return pylastica.resultset.ResultSet(response, query).get_total_hits()