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


Python DocumentMappingType.get_query_fields方法代码示例

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


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

示例1: opensearch_suggestions

# 需要导入模块: from kitsune.wiki.models import DocumentMappingType [as 别名]
# 或者: from kitsune.wiki.models.DocumentMappingType import get_query_fields [as 别名]
def opensearch_suggestions(request):
    """A simple search view that returns OpenSearch suggestions."""
    content_type = "application/x-suggestions+json"

    term = request.GET.get("q")
    if not term:
        return HttpResponseBadRequest(content_type=content_type)

    locale = locale_or_default(request.LANGUAGE_CODE)

    # FIXME: Rewrite this using the simple search search business
    # logic. This currently returns templates (amongst other things)
    # which is totally wrong.
    try:
        query = dict(("%s__match" % field, term) for field in DocumentMappingType.get_query_fields())
        # Upgrade the query to an analyzer-aware one.
        query = es_utils.es_query_with_analyzer(query, locale)

        wiki_s = (
            DocumentMappingType.search()
            .filter(document_is_archived=False)
            .filter(document_locale=locale)
            .values_dict("document_title", "url")
            .query(or_=query)[:5]
        )

        query = dict(("%s__match" % field, term) for field in QuestionMappingType.get_query_fields())
        question_s = (
            QuestionMappingType.search()
            .filter(question_has_helpful=True)
            .values_dict("question_title", "url")
            .query(or_=query)[:5]
        )

        results = list(chain(question_s, wiki_s))
    except ES_EXCEPTIONS:
        # If we have ES problems, we just send back an empty result
        # set.
        results = []

    def urlize(r):
        return u"%s://%s%s" % ("https" if request.is_secure() else "http", request.get_host(), r["url"][0])

    def titleize(r):
        # NB: Elasticsearch returns an array of strings as the value,
        # so we mimic that and then pull out the first (and only)
        # string.
        return r.get("document_title", r.get("question_title", [_("No title")]))[0]

    data = [term, [titleize(r) for r in results], [], [urlize(r) for r in results]]
    return HttpResponse(json.dumps(data), content_type=content_type)
开发者ID:zctyhj,项目名称:kitsune,代码行数:53,代码来源:views.py

示例2: suggestions

# 需要导入模块: from kitsune.wiki.models import DocumentMappingType [as 别名]
# 或者: from kitsune.wiki.models.DocumentMappingType import get_query_fields [as 别名]
def suggestions(request):
    """A simple search view that returns OpenSearch suggestions."""
    content_type = 'application/x-suggestions+json'

    term = request.GET.get('q')
    if not term:
        return HttpResponseBadRequest(content_type=content_type)

    site = Site.objects.get_current()
    locale = locale_or_default(request.LANGUAGE_CODE)
    try:
        query = dict(('{0!s}__match'.format(field), term)
                     for field in DocumentMappingType.get_query_fields())
        # Upgrade the query to an analyzer-aware one.
        query = es_utils.es_query_with_analyzer(query, locale)

        wiki_s = (DocumentMappingType.search()
                  .filter(document_is_archived=False)
                  .filter(document_locale=locale)
                  .values_dict('document_title', 'url')
                  .query(or_=query)[:5])

        query = dict(('{0!s}__match'.format(field), term)
                     for field in QuestionMappingType.get_query_fields())
        question_s = (QuestionMappingType.search()
                      .filter(question_has_helpful=True)
                      .values_dict('question_title', 'url')
                      .query(or_=query)[:5])

        results = list(chain(question_s, wiki_s))
    except ES_EXCEPTIONS:
        # If we have ES problems, we just send back an empty result
        # set.
        results = []

    def urlize(r):
        return u'https://{0!s}{1!s}'.format(site, r['url'])

    def titleize(r):
        return r.get('document_title', r.get('document_title'))

    data = [term,
            [titleize(r) for r in results],
            [],
            [urlize(r) for r in results]]
    return HttpResponse(json.dumps(data), content_type=content_type)
开发者ID:runt18,项目名称:kitsune,代码行数:48,代码来源:views.py

示例3: suggestions

# 需要导入模块: from kitsune.wiki.models import DocumentMappingType [as 别名]
# 或者: from kitsune.wiki.models.DocumentMappingType import get_query_fields [as 别名]
def suggestions(request):
    """A simple search view that returns OpenSearch suggestions."""
    mimetype = 'application/x-suggestions+json'

    term = request.GET.get('q')
    if not term:
        return HttpResponseBadRequest(mimetype=mimetype)

    site = Site.objects.get_current()
    locale = locale_or_default(request.LANGUAGE_CODE)
    try:
        query = dict(('%s__text' % field, term)
                     for field in DocumentMappingType.get_query_fields())
        wiki_s = (DocumentMappingType.search()
                  .filter(document_is_archived=False)
                  .filter(document_locale=locale)
                  .values_dict('document_title', 'url')
                  .query(or_=query)[:5])

        query = dict(('%s__text' % field, term)
                     for field in QuestionMappingType.get_query_fields())
        question_s = (QuestionMappingType.search()
                      .filter(question_has_helpful=True)
                      .values_dict('question_title', 'url')
                      .query(or_=query)[:5])

        results = list(chain(question_s, wiki_s))
    except ES_EXCEPTIONS:
        # If we have ES problems, we just send back an empty result
        # set.
        results = []

    urlize = lambda r: u'https://%s%s' % (site, r['url'])
    titleize = lambda r: (r['document_title'] if 'document_title' in r
                          else r['question_title'])
    data = [term,
            [titleize(r) for r in results],
            [],
            [urlize(r) for r in results]]
    return HttpResponse(json.dumps(data), mimetype=mimetype)
开发者ID:jayvdb,项目名称:kitsune,代码行数:42,代码来源:views.py

示例4: get_query_fields

# 需要导入模块: from kitsune.wiki.models import DocumentMappingType [as 别名]
# 或者: from kitsune.wiki.models.DocumentMappingType import get_query_fields [as 别名]
 def get_query_fields(self):
     return DocumentMappingType.get_query_fields()
开发者ID:rivaxel,项目名称:kitsune,代码行数:4,代码来源:api.py


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