本文整理汇总了Python中kitsune.wiki.models.DocumentMappingType.get_mapping_type_name方法的典型用法代码示例。如果您正苦于以下问题:Python DocumentMappingType.get_mapping_type_name方法的具体用法?Python DocumentMappingType.get_mapping_type_name怎么用?Python DocumentMappingType.get_mapping_type_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kitsune.wiki.models.DocumentMappingType
的用法示例。
在下文中一共展示了DocumentMappingType.get_mapping_type_name方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_doctypes
# 需要导入模块: from kitsune.wiki.models import DocumentMappingType [as 别名]
# 或者: from kitsune.wiki.models.DocumentMappingType import get_mapping_type_name [as 别名]
def get_doctypes(self):
return [DocumentMappingType.get_mapping_type_name()]
示例2: search
# 需要导入模块: from kitsune.wiki.models import DocumentMappingType [as 别名]
# 或者: from kitsune.wiki.models.DocumentMappingType import get_mapping_type_name [as 别名]
#.........这里部分代码省略.........
if filter_option == constants.INTERVAL_BEFORE:
before = {filter_name + '__gte': 0,
filter_name + '__lte': max(filter_date, 0)}
discussion_f &= F(**before)
question_f &= F(**before)
elif filter_option == constants.INTERVAL_AFTER:
after = {filter_name + '__gte': min(filter_date, unix_now),
filter_name + '__lte': unix_now}
discussion_f &= F(**after)
question_f &= F(**after)
# In basic search, we limit questions from the last
# SEARCH_DEFAULT_MAX_QUESTION_AGE seconds.
if a == '0':
start_date = unix_now - settings.SEARCH_DEFAULT_MAX_QUESTION_AGE
question_f &= F(created__gte=start_date)
# Note: num_voted (with a d) is a different field than num_votes
# (with an s). The former is a dropdown and the latter is an
# integer value.
if cleaned['num_voted'] == constants.INTERVAL_BEFORE:
question_f &= F(question_num_votes__lte=max(cleaned['num_votes'], 0))
elif cleaned['num_voted'] == constants.INTERVAL_AFTER:
question_f &= F(question_num_votes__gte=cleaned['num_votes'])
# Done with all the filtery stuff--time to generate results
# Combine all the filters and add to the searcher
doctypes = []
final_filter = F()
if cleaned['w'] & constants.WHERE_WIKI:
doctypes.append(DocumentMappingType.get_mapping_type_name())
final_filter |= wiki_f
if cleaned['w'] & constants.WHERE_SUPPORT:
doctypes.append(QuestionMappingType.get_mapping_type_name())
final_filter |= question_f
if cleaned['w'] & constants.WHERE_DISCUSSION:
doctypes.append(ThreadMappingType.get_mapping_type_name())
final_filter |= discussion_f
searcher = searcher.doctypes(*doctypes)
searcher = searcher.filter(final_filter)
if 'explain' in request.GET and request.GET['explain'] == '1':
searcher = searcher.explain()
documents = ComposedList()
try:
cleaned_q = cleaned['q']
# Set up the highlights. Show the entire field highlighted.
searcher = searcher.highlight(
'question_content', # support forum
'document_summary', # kb
'post_content', # contributor forum
pre_tags=['<b>'],
post_tags=['</b>'],
number_of_fragments=0)
# Set up boosts
searcher = searcher.boost(
示例3: advanced_search
# 需要导入模块: from kitsune.wiki.models import DocumentMappingType [as 别名]
# 或者: from kitsune.wiki.models.DocumentMappingType import get_mapping_type_name [as 别名]
#.........这里部分代码省略.........
if cleaned['w'] & constants.WHERE_WIKI:
wiki_f = F(model='wiki_document')
# Category filter
if cleaned['category']:
wiki_f &= F(document_category__in=cleaned['category'])
# Locale filter
wiki_f &= F(document_locale=language)
# Product filter
products = cleaned['product']
for p in products:
wiki_f &= F(product=p)
# Topics filter
topics = cleaned['topics']
for t in topics:
wiki_f &= F(topic=t)
# Archived bit
if not cleaned['include_archived']:
wiki_f &= F(document_is_archived=False)
# Apply sortby
sortby = cleaned['sortby_documents']
try:
searcher = searcher.order_by(*constants.SORT_DOCUMENTS[sortby])
except IndexError:
# Skip index errors because they imply the user is sending us sortby values
# that aren't valid.
pass
doctypes.append(DocumentMappingType.get_mapping_type_name())
final_filter |= wiki_f
# End - wiki search configuration
# Start - support questions configuration
if cleaned['w'] & constants.WHERE_SUPPORT:
question_f = F(model='questions_question')
# These filters are ternary, they can be either YES, NO, or OFF
ternary_filters = ('is_locked', 'is_solved', 'has_answers',
'has_helpful', 'is_archived')
d = dict(('question_%s' % filter_name,
_ternary_filter(cleaned[filter_name]))
for filter_name in ternary_filters if cleaned[filter_name])
if d:
question_f &= F(**d)
if cleaned['asked_by']:
question_f &= F(question_creator=cleaned['asked_by'])
if cleaned['answered_by']:
question_f &= F(question_answer_creator=cleaned['answered_by'])
q_tags = [t.strip() for t in cleaned['q_tags'].split(',')]
for t in q_tags:
if t:
question_f &= F(question_tag=t)
# Product filter
products = cleaned['product']
for p in products:
示例4: generate_simple_search
# 需要导入模块: from kitsune.wiki.models import DocumentMappingType [as 别名]
# 或者: from kitsune.wiki.models.DocumentMappingType import get_mapping_type_name [as 别名]
def generate_simple_search(search_form, language, with_highlights=False):
"""Generates an S given a form
:arg search_form: a validated SimpleSearch form
:arg language: the language code
:arg with_highlights: whether or not to ask for highlights
:returns: a fully formed S
"""
# We use a regular S here because we want to search across
# multiple doctypes.
searcher = (
es_utils.AnalyzerS().es(
urls=settings.ES_URLS,
timeout=settings.ES_TIMEOUT,
use_ssl=settings.ES_USE_SSL,
http_auth=settings.ES_HTTP_AUTH,
)
.indexes(es_utils.read_index('default'))
)
cleaned = search_form.cleaned_data
doctypes = []
final_filter = es_utils.F()
cleaned_q = cleaned['q']
products = cleaned['product']
# Handle wiki filters
if cleaned['w'] & constants.WHERE_WIKI:
wiki_f = es_utils.F(model='wiki_document',
document_category__in=settings.SEARCH_DEFAULT_CATEGORIES,
document_locale=language,
document_is_archived=False)
for p in products:
wiki_f &= es_utils.F(product=p)
doctypes.append(DocumentMappingType.get_mapping_type_name())
final_filter |= wiki_f
# Handle question filters
if cleaned['w'] & constants.WHERE_SUPPORT:
question_f = es_utils.F(model='questions_question',
question_is_archived=False,
question_has_helpful=True)
for p in products:
question_f &= es_utils.F(product=p)
doctypes.append(QuestionMappingType.get_mapping_type_name())
final_filter |= question_f
# Build a filter for those filters and add the other bits to
# finish the search
searcher = searcher.doctypes(*doctypes)
searcher = searcher.filter(final_filter)
if cleaned['explain']:
searcher = searcher.explain()
if with_highlights:
# Set up the highlights. Show the entire field highlighted.
searcher = searcher.highlight(
'question_content', # support forum
'document_summary', # kb
pre_tags=['<b>'],
post_tags=['</b>'],
number_of_fragments=0
)
searcher = apply_boosts(searcher)
# Build the query
query_fields = chain(*[
cls.get_query_fields() for cls in [
DocumentMappingType,
QuestionMappingType
]
])
query = {}
# Create match and match_phrase queries for every field
# we want to search.
for field in query_fields:
for query_type in ['match', 'match_phrase']:
query['%s__%s' % (field, query_type)] = cleaned_q
# Transform the query to use locale aware analyzers.
query = es_utils.es_query_with_analyzer(query, language)
searcher = searcher.query(should=True, **query)
return searcher
示例5: simple_search
# 需要导入模块: from kitsune.wiki.models import DocumentMappingType [as 别名]
# 或者: from kitsune.wiki.models.DocumentMappingType import get_mapping_type_name [as 别名]
#.........这里部分代码省略.........
wiki_f &= F(document_is_archived=False)
# End - wiki filters
# Start - support questions filters
if cleaned['w'] & constants.WHERE_SUPPORT:
# Has helpful answers is set by default if using basic search
cleaned['has_helpful'] = constants.TERNARY_YES
# No archived questions in default search.
cleaned['is_archived'] = constants.TERNARY_NO
# These filters are ternary, they can be either YES, NO, or OFF
ternary_filters = ('has_helpful', 'is_archived')
d = dict(('question_{0!s}'.format(filter_name),
_ternary_filter(cleaned[filter_name]))
for filter_name in ternary_filters if cleaned[filter_name])
if d:
question_f &= F(**d)
# Product filter
for p in products:
question_f &= F(product=p)
# End - support questions filters
# Done with all the filtery stuff--time to generate results
# Combine all the filters and add to the searcher
doctypes = []
final_filter = F()
if cleaned['w'] & constants.WHERE_WIKI:
doctypes.append(DocumentMappingType.get_mapping_type_name())
final_filter |= wiki_f
if cleaned['w'] & constants.WHERE_SUPPORT:
doctypes.append(QuestionMappingType.get_mapping_type_name())
final_filter |= question_f
searcher = searcher.doctypes(*doctypes)
searcher = searcher.filter(final_filter)
if 'explain' in request.GET and request.GET['explain'] == '1':
searcher = searcher.explain()
documents = ComposedList()
try:
# Set up the highlights. Show the entire field highlighted.
searcher = searcher.highlight(
'question_content', # support forum
'document_summary', # kb
pre_tags=['<b>'],
post_tags=['</b>'],
number_of_fragments=0)
# Set up boosts
searcher = searcher.boost(
question_title=4.0,
question_content=3.0,
question_answer_content=3.0,
document_title=6.0,
document_content=1.0,
document_keywords=8.0,
document_summary=2.0,
示例6: simple_search
# 需要导入模块: from kitsune.wiki.models import DocumentMappingType [as 别名]
# 或者: from kitsune.wiki.models.DocumentMappingType import get_mapping_type_name [as 别名]
#.........这里部分代码省略.........
# End - wiki filters
# Start - support questions filters
if cleaned["w"] & constants.WHERE_SUPPORT:
# Has helpful answers is set by default if using basic search
cleaned["has_helpful"] = constants.TERNARY_YES
# No archived questions in default search.
cleaned["is_archived"] = constants.TERNARY_NO
# These filters are ternary, they can be either YES, NO, or OFF
ternary_filters = ("has_helpful", "is_archived")
d = dict(
("question_%s" % filter_name, _ternary_filter(cleaned[filter_name]))
for filter_name in ternary_filters
if cleaned[filter_name]
)
if d:
question_f &= F(**d)
# Product filter
for p in products:
question_f &= F(product=p)
# End - support questions filters
# Done with all the filtery stuff--time to generate results
# Combine all the filters and add to the searcher
doctypes = []
final_filter = F()
if cleaned["w"] & constants.WHERE_WIKI:
doctypes.append(DocumentMappingType.get_mapping_type_name())
final_filter |= wiki_f
if cleaned["w"] & constants.WHERE_SUPPORT:
doctypes.append(QuestionMappingType.get_mapping_type_name())
final_filter |= question_f
searcher = searcher.doctypes(*doctypes)
searcher = searcher.filter(final_filter)
if "explain" in request.GET and request.GET["explain"] == "1":
searcher = searcher.explain()
documents = ComposedList()
try:
# Set up the highlights. Show the entire field highlighted.
searcher = searcher.highlight(
"question_content", # support forum
"document_summary", # kb
pre_tags=["<b>"],
post_tags=["</b>"],
number_of_fragments=0,
)
# Set up boosts
searcher = searcher.boost(
question_title=4.0,
question_content=3.0,
question_answer_content=3.0,
document_title=6.0,
document_content=1.0,
document_keywords=8.0,
示例7: advanced_search
# 需要导入模块: from kitsune.wiki.models import DocumentMappingType [as 别名]
# 或者: from kitsune.wiki.models.DocumentMappingType import get_mapping_type_name [as 别名]
#.........这里部分代码省略.........
# Created filter
unix_now = int(time.time())
interval_filters = (
("created", cleaned["created"], cleaned["created_date"]),
("updated", cleaned["updated"], cleaned["updated_date"]),
)
for filter_name, filter_option, filter_date in interval_filters:
if filter_option == constants.INTERVAL_BEFORE:
before = {filter_name + "__gte": 0, filter_name + "__lte": max(filter_date, 0)}
discussion_f &= F(**before)
question_f &= F(**before)
elif filter_option == constants.INTERVAL_AFTER:
after = {filter_name + "__gte": min(filter_date, unix_now), filter_name + "__lte": unix_now}
discussion_f &= F(**after)
question_f &= F(**after)
# Note: num_voted (with a d) is a different field than num_votes
# (with an s). The former is a dropdown and the latter is an
# integer value.
if cleaned["num_voted"] == constants.INTERVAL_BEFORE:
question_f &= F(question_num_votes__lte=max(cleaned["num_votes"], 0))
elif cleaned["num_voted"] == constants.INTERVAL_AFTER:
question_f &= F(question_num_votes__gte=cleaned["num_votes"])
# Done with all the filtery stuff--time to generate results
# Combine all the filters and add to the searcher
doctypes = []
final_filter = F()
if cleaned["w"] & constants.WHERE_WIKI:
doctypes.append(DocumentMappingType.get_mapping_type_name())
final_filter |= wiki_f
if cleaned["w"] & constants.WHERE_SUPPORT:
doctypes.append(QuestionMappingType.get_mapping_type_name())
final_filter |= question_f
if cleaned["w"] & constants.WHERE_DISCUSSION:
doctypes.append(ThreadMappingType.get_mapping_type_name())
final_filter |= discussion_f
searcher = searcher.doctypes(*doctypes)
searcher = searcher.filter(final_filter)
if "explain" in request.GET and request.GET["explain"] == "1":
searcher = searcher.explain()
documents = ComposedList()
try:
cleaned_q = cleaned["q"]
# Set up the highlights. Show the entire field highlighted.
searcher = searcher.highlight(
"question_content", # support forum
"document_summary", # kb
"post_content", # contributor forum
pre_tags=["<b>"],
post_tags=["</b>"],
number_of_fragments=0,
)
# Set up boosts