本文整理汇总了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)
示例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)
示例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)
示例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()