Пример #1
0
    def query(self, *args, **kwargs):
        """
        if argument is a string, it means default:'argument'
        if argument is a k=v pair, it means k:'v'
        and it always use AND to join conditions, if you want to use complex condition, you could use Q
        :param args:
        :param kwargs:
        :return:
        """

        if self.__query is None:
            self.__query = list()

        query_temp_list = []
        for item in args:
            if type(item) == list:
                query_temp_list.extend(item)
            else:
                query_temp_list.append(item)

        kwargs_query = ["%s:'%s'" % (item[0], item[1]) for item in kwargs.items()]
        query_temp_list.extend(kwargs_query)

        for item in query_temp_list:
            if type(item) is Q:
                self.__query.append(item.query_string)
            else:
                if ":" not in item:
                    log.warning("there is no query index %s, it will be set to default" % item)
                    self.__query.append("default:'%s'" % item)
                else:
                    self.__query.append(item)

        return self
Пример #2
0
    def rank(self, *args, **kwargs):
        """
        this method will help query to RANK, but you must assign a query first
        :param args:
        :param kwargs:
        :return:
        """
        if len(args) > 0:
            tmp = args[0]
            if ":" not in tmp:
                log.warning("there is no index, it will be set default index")
                query_string = "default:'%s'" % tmp
            else:
                query_string = tmp
        elif len(kwargs) > 0:
            boost = kwargs.get("boost")
            if boost is not None:
                kwargs.pop("boost")

            if len(kwargs) == 0:
                raise ValueError("cannot only assign a boost parameter")

            query_string = "%s:'%s'" % (kwargs.items()[0][0], kwargs.items()[0][1])
        self.__rank = query_string

        return self
Пример #3
0
    def get_log(self, app_name, page, page_size, sort_mod="DESC"):

        log.debug("get error log of %s" % (app_name))

        self._check_client()

        if not app_name:
            raise ValueError("app_name must be assigned")

        if type(page_size) is not int or page_size < 1:
            raise ValueError("invalid page_size, please set a integer bigger than 0")

        if page_size > 100:
            log.warning("page_size bigger than 100, this may not be a good idea")

        if type(page) is not int or page < 1:
            raise ValueError("invalid page, please set a integer bigger than 0")

        params = dict()
        params['page'] = str(page)
        params['page_size'] = str(page_size)
        params['sort_mode'] = sort_mod

        url = "%s/%s" % (ErrorLog.BASE_URL, app_name)

        resp = self.__client.send_message(url, method='GET', params=params)
        resp_info = self.wrap_result(resp)

        return resp_info
Пример #4
0
    def __init__(self, *args, **kwargs):

        boost = None

        # only support the first one
        if len(args) > 0:
            tmp = args[0]
            if ":" not in tmp:
                log.warning("there is no index, it will be set default index")
                self.query_string = "default:'%s'" % tmp
            else:
                self.query_string = tmp
        elif len(kwargs) > 0:
            boost = kwargs.get("boost")
            if boost is not None:
                kwargs.pop("boost")

            if len(kwargs) == 0:
                raise ValueError("cannot only assign a boost parameter")

            self.query_string = "%s:'%s'" % (kwargs.items()[0][0], kwargs.items()[0][1])

        if boost is not None:
            self.query_string = "%s^%s" % (self.query_string, boost)