本文整理汇总了Python中wiki.models.Document.search方法的典型用法代码示例。如果您正苦于以下问题:Python Document.search方法的具体用法?Python Document.search怎么用?Python Document.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wiki.models.Document
的用法示例。
在下文中一共展示了Document.search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_recent_helpful_votes
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def test_recent_helpful_votes(self):
"""Recent helpful votes are indexed properly."""
# Create a document and verify it doesn't show up in a
# query for recent_helpful_votes__gt=0.
r = revision(is_approved=True, save=True)
self.refresh()
eq_(Document.search().filter(
document_recent_helpful_votes__gt=0).count(), 0)
# Add an unhelpful vote, it still shouldn't show up.
helpful_vote(revision=r, helpful=False, save=True)
r.document.save() # Votes don't trigger a reindex.
self.refresh()
eq_(Document.search().filter(
document_recent_helpful_votes__gt=0).count(), 0)
# Add an helpful vote created 31 days ago, it still shouldn't show up.
created = datetime.now() - timedelta(days=31)
helpful_vote(revision=r, helpful=True, created=created, save=True)
r.document.save() # Votes don't trigger a reindex.
self.refresh()
eq_(Document.search().filter(
document_recent_helpful_votes__gt=0).count(), 0)
# Add an helpful vote created 29 days ago, it should show up now.
created = datetime.now() - timedelta(days=29)
helpful_vote(revision=r, helpful=True, created=created, save=True)
r.document.save() # Votes don't trigger a reindex.
self.refresh()
eq_(Document.search().filter(
document_recent_helpful_votes__gt=0).count(), 1)
示例2: test_add_and_delete
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def test_add_and_delete(self):
"""Adding a doc should add it to the search index; deleting should
delete it."""
doc = document(save=True)
revision(document=doc, is_approved=True, save=True)
self.refresh()
eq_(Document.search().count(), 1)
doc.delete()
self.refresh()
eq_(Document.search().count(), 0)
示例3: test_wiki_no_revisions
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def test_wiki_no_revisions(self):
"""Don't index documents without approved revisions"""
# Create a document with no revisions and make sure the
# document is not in the index.
doc = document(save=True)
self.refresh()
eq_(Document.search().count(), 0)
# Create a revision that's not approved and make sure the
# document is still not in the index.
revision(document=doc, is_approved=False, save=True)
self.refresh()
eq_(Document.search().count(), 0)
示例4: test_wiki_redirects
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def test_wiki_redirects(self):
"""Make sure we don't index redirects"""
# First create a revision that doesn't have a redirect and
# make sure it's in the index.
doc = document(title=u"wool hats")
doc.save()
revision(document=doc, is_approved=True, save=True)
self.refresh()
eq_(Document.search().query("wool").count(), 1)
# Now create a revision that is a redirect and make sure the
# document is removed from the index.
revision(document=doc, content=REDIRECT_CONTENT, is_approved=True, save=True)
self.refresh()
eq_(Document.search().query("wool").count(), 0)
示例5: test_wiki_keywords
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def test_wiki_keywords(self):
"""Make sure updating keywords updates the index."""
# Create a document with a revision with no keywords. It
# shouldn't show up with a document_keywords term query for
# 'wool' since it has no keywords.
doc = document(title=u'wool hats')
doc.save()
revision(document=doc, is_approved=True, save=True)
self.refresh()
eq_(Document.search().query(document_keywords='wool').count(), 0)
revision(document=doc, is_approved=True, keywords='wool', save=True)
self.refresh()
eq_(Document.search().query(document_keywords='wool').count(), 1)
示例6: _es_documents_for
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def _es_documents_for(locale, topics, products):
"""ES implementation of documents_for."""
s = Document.search().values_dict(
'id', 'document_title', 'url').filter(document_locale=locale)
for topic in topics:
s = s.filter(document_topic=topic.slug)
for product in products or []:
s = s.filter(document_product=product.slug)
return list(s.order_by('-document_recent_helpful_votes')[:100])
示例7: test_wiki_products
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def test_wiki_products(self):
"""Make sure that adding products to a Document causes it to
refresh the index.
"""
p = product(slug=u'desktop', save=True)
eq_(Document.search().filter(product=p.slug).count(), 0)
doc = document(save=True)
revision(document=doc, is_approved=True, save=True)
self.refresh()
eq_(Document.search().filter(product=p.slug).count(), 0)
doc.products.add(p)
self.refresh()
eq_(Document.search().filter(product=p.slug).count(), 1)
doc.products.remove(p)
self.refresh()
# Make sure the document itself is still there and that we didn't
# accidentally delete it through screwed up signal handling:
eq_(Document.search().filter().count(), 1)
eq_(Document.search().filter(product=p.slug).count(), 0)
示例8: _es_documents_for
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def _es_documents_for(locale, topics, products=None):
"""ES implementation of documents_for."""
s = (Document.search()
.values_dict('id', 'document_title', 'url', 'document_parent_id')
.filter(document_locale=locale, document_is_archived=False,
document_category__in=settings.IA_DEFAULT_CATEGORIES))
for topic in topics:
s = s.filter(document_topic=topic.slug)
for product in products or []:
s = s.filter(document_product=product.slug)
return list(s.order_by('-document_recent_helpful_votes')[:100])
示例9: test_wiki_topics
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def test_wiki_topics(self):
"""Make sure that adding topics to a Document causes it to
refresh the index.
"""
t = topic(slug=u"hiphop", save=True)
eq_(Document.search().filter(document_topic=t.slug).count(), 0)
doc = document(save=True)
revision(document=doc, is_approved=True, save=True)
self.refresh()
eq_(Document.search().filter(document_topic=t.slug).count(), 0)
doc.topics.add(t)
self.refresh()
eq_(Document.search().filter(document_topic=t.slug).count(), 1)
doc.topics.clear()
self.refresh()
# Make sure the document itself is still there and that we didn't
# accidentally delete it through screwed up signal handling:
eq_(Document.search().filter().count(), 1)
eq_(Document.search().filter(document_topic=t.slug).count(), 0)
示例10: test_wiki_tags
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def test_wiki_tags(self):
"""Make sure that adding tags to a Document causes it to
refresh the index.
"""
tag = u'hiphop'
eq_(Document.search().filter(tag=tag).count(), 0)
doc = document(save=True)
revision(document=doc, is_approved=True, save=True)
self.refresh()
eq_(Document.search().filter(tag=tag).count(), 0)
doc.tags.add(tag)
self.refresh()
eq_(Document.search().filter(tag=tag).count(), 1)
doc.tags.remove(tag)
self.refresh()
# Make sure the document itself is still there and that we didn't
# accidentally delete it through screwed up signal handling:
eq_(Document.search().filter().count(), 1)
eq_(Document.search().filter(tag=tag).count(), 0)
示例11: troubleshooting_view
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def troubleshooting_view(request):
# Build a list of the most recently indexed 50 wiki documents.
last_50_indexed = list(_fix_value_dicts(Document.search().values_dict().order_by("-indexed_on")[:50]))
last_50_reviewed = list(
Document.uncached.filter(current_revision__is_approved=True).order_by("-current_revision__reviewed")[:50]
)
diff_list = diff_it_for_realz(last_50_indexed, last_50_reviewed)
return render_to_response(
"search/admin/troubleshooting.html",
{"title": "Index Troubleshooting", "diffs": diff_list},
RequestContext(request, {}),
)
示例12: troubleshooting_view
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def troubleshooting_view(request):
# Build a list of the most recently indexed 50 wiki documents.
last_50_indexed = _fix_value_dicts(Document.search()
.values_dict()
.order_by('-indexed_on')[:50])
last_50_reviewed = (Document.uncached
.filter(current_revision__is_approved=True)
.order_by('-current_revision__reviewed')[:50])
return render_to_response(
'search/admin/troubleshooting.html',
{'title': 'Index Troubleshooting',
'last_50_indexed': last_50_indexed,
'last_50_reviewed': last_50_reviewed
},
RequestContext(request, {}))
示例13: products_for
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def products_for(topics):
"""Returns a list of products that apply to passed in topics.
:arg topics: a list of Topic instances
"""
product_field = 'document_product'
s = Document.search().values_dict('id')
for topic in topics:
s = s.filter(document_topic=topic.slug)
s = s.facet(product_field, filtered=True)
facet_counts = s.facet_counts()[product_field]
products = Product.objects.filter(
slug__in=[f['term'] for f in facet_counts]).filter(visible=True)
return products
示例14: topics_for
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def topics_for(products):
"""Returns a list of topics that apply to passed in products.
:arg topics: a list of Product instances
"""
topic_field = 'document_topic'
s = Document.search().values_dict('id')
for product in products:
s = s.filter(document_product=product.slug)
s = s.facet(topic_field, filtered=True)
facet_counts = s.facet_counts()[topic_field]
topics = Topic.objects.filter(
slug__in=[f['term'] for f in facet_counts]).filter(visible=True)
return topics
示例15: troubleshooting_view
# 需要导入模块: from wiki.models import Document [as 别名]
# 或者: from wiki.models.Document import search [as 别名]
def troubleshooting_view(request):
# Build a list of the most recently indexed 50 wiki documents.
last_50_indexed = list(_fix_value_dicts(Document.search()
.values_dict()
.order_by('-indexed_on')[:50]))
last_50_reviewed = list(Document.uncached
.filter(current_revision__is_approved=True)
.order_by('-current_revision__reviewed')[:50])
diff_list = diff_it_for_realz(last_50_indexed, last_50_reviewed)
return render(
request,
'admin/search_troubleshooting.html',
{'title': 'Index Troubleshooting',
'diffs': diff_list,
})