当前位置: 首页>>代码示例>>Python>>正文


Python Question.get_mapping_type方法代码示例

本文整理汇总了Python中questions.models.Question.get_mapping_type方法的典型用法代码示例。如果您正苦于以下问题:Python Question.get_mapping_type方法的具体用法?Python Question.get_mapping_type怎么用?Python Question.get_mapping_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在questions.models.Question的用法示例。


在下文中一共展示了Question.get_mapping_type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: related_questions

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import get_mapping_type [as 别名]
    def related_questions(self):
        """Return questions that are 'morelikethis' document."""
        # Only documents in default IA categories have related.
        if (self.redirect_url() or not self.current_revision or
            self.category not in settings.IA_DEFAULT_CATEGORIES):
            return []

        # First try to get the results from the cache
        key = 'wiki_document:related_questions:%s' % self.id
        questions = cache.get(key)
        if questions is not None:
            statsd.incr('wiki.related_questions.cache.hit')
            log.debug('Getting MLT questions for {doc} from cache.'
                .format(doc=repr(self)))
            return questions

        try:
            statsd.incr('wiki.related_questions.cache.miss')
            max_age = settings.SEARCH_DEFAULT_MAX_QUESTION_AGE
            start_date = int(time.time()) - max_age

            s = Question.get_mapping_type().search()
            questions = s.values_dict('id', 'question_title', 'url').filter(
                    question_locale=self.locale,
                    product__in=[p.slug for p in self.get_products()],
                    question_has_helpful=True,
                    created__gte=start_date
                ).query(
                    __mlt={
                        'fields': ['question_title', 'question_content'],
                        'like_text': self.title,
                        'min_term_freq': 1,
                        'min_doc_freq': 1,
                    }
                )[:3]
            questions = list(questions)
            cache.add(key, questions)
        except ES_EXCEPTIONS as exc:
            statsd.incr('wiki.related_questions.esexception')
            log.error('ES MLT {err} related_questions for {doc}'.format(
                    doc=repr(self), err=str(exc)))
            questions = []

        return questions
开发者ID:DWDRAEGER,项目名称:kitsune,代码行数:46,代码来源:models.py


注:本文中的questions.models.Question.get_mapping_type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。