本文整理汇总了Python中search.forms.SearchForm.apply_query方法的典型用法代码示例。如果您正苦于以下问题:Python SearchForm.apply_query方法的具体用法?Python SearchForm.apply_query怎么用?Python SearchForm.apply_query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类search.forms.SearchForm
的用法示例。
在下文中一共展示了SearchForm.apply_query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_search1
# 需要导入模块: from search.forms import SearchForm [as 别名]
# 或者: from search.forms.SearchForm import apply_query [as 别名]
def test_search1(self):
for title in self.titles:
video = Video.objects.all()[0]
sqs = SearchQuerySet().models(Video)
video.title = title
video.save()
reset_solr()
result = SearchForm.apply_query(video.title, sqs)
self.assertTrue(video in [item.object for item in result], u"Failed to find video by title: %s" % title)
result = SearchForm.apply_query(u'BBC', sqs)
self.assertTrue(video in [item.object for item in result], u"Failed to find video by 'BBC' with title: %s" % title)
示例2: search
# 需要导入模块: from search.forms import SearchForm [as 别名]
# 或者: from search.forms.SearchForm import apply_query [as 别名]
def search(self, rdata, user, testing=False):
sqs = SearchQuerySet().result_class(VideoSearchResult) \
.models(Video)
rdata['q'] = rdata['q'] or u' '
q = rdata.get('q')
if q:
sqs = SearchForm.apply_query(q, sqs)
form = SearchForm(rdata, sqs=sqs)
else:
form = SearchForm(rdata)
if form.is_valid():
qs = form.search_qs(sqs)
else:
qs = SearchQuerySet().none()
#result = [item.object for item in qs]
#qs1 = Video.objects.filter(title__contains=rdata['q'])
#for o in qs1:
# if not o in result:
# print o.title
display_views = form.get_display_views()
output = render_page(rdata.get('page', 1), qs, 20, display_views=display_views)
output['sidebar'] = render_to_string('search/_sidebar.html', dict(form=form, rdata=rdata))
if testing:
output['sqs'] = qs
return output
示例3: test_search
# 需要导入模块: from search.forms import SearchForm [as 别名]
# 或者: from search.forms.SearchForm import apply_query [as 别名]
def test_search(self):
reset_solr()
sqs = SearchQuerySet().models(Video)
qs = Video.objects.exclude(title='')
self.assertTrue(qs.count())
for video in qs:
result = SearchForm.apply_query(video.title, sqs)
self.assertTrue(video in [item.object for item in result])