models.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:ecommerce_api 作者: nbschool 项目源码 文件源码
def search(cls, query, dataset, limit=-1,
               attributes=None, weights=None,
               threshold=search.config.THRESHOLD):
        """
        Search a list of resources with the callee class.

        Arguments:
            query (str): Query to lookup for
            dataset (iterable): sequence of resource objects to lookup into
            limit (int): maximum number of resources to return (default -1, all)
            attributes (list): model attribute names. Can be set as default
                inside the model definition or specified on the fly while
                searching.
            weights (list): attributes weights values,indexes should
                match the attribute position in the `attributes` argument.
                if length does not match it will be ignored.
            threshold (float): value between 0 and 1, identify the matching
                threshold for a result to be included.

        Returns:
            list: list of resources that may match the query.

        Raises:
            SearchAttributeMismatch:
                if ``attributes`` are missing, either as model
                default in ``<Model>._search_attributes`` or as param
                one of the object does not have one of the given attribute(s).

        Examples:

            .. code-block:: python

                results = Item.search('shoes', Item.select(), limit=20)
        """

        attributes = attributes or cls._search_attributes
        weights = weights or cls._search_weights

        if not attributes:
            raise SearchAttributeMismatch(
                'Attributes to look for not defined for {}. \
                Please update the Model or specify during search call.\
                '.format(cls.__name__))

        return search.search(query, attributes, dataset, limit, threshold, weights)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号