本文整理匯總了Python中haystack.backends.xapian_backend.SearchBackend.more_like_this方法的典型用法代碼示例。如果您正苦於以下問題:Python SearchBackend.more_like_this方法的具體用法?Python SearchBackend.more_like_this怎麽用?Python SearchBackend.more_like_this使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類haystack.backends.xapian_backend.SearchBackend
的用法示例。
在下文中一共展示了SearchBackend.more_like_this方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: XapianSearchBackendTestCase
# 需要導入模塊: from haystack.backends.xapian_backend import SearchBackend [as 別名]
# 或者: from haystack.backends.xapian_backend.SearchBackend import more_like_this [as 別名]
#.........這裏部分代碼省略.........
# self.assertEqual(self.sb.search('Index*', highlight=True)['hits'], 3)
# self.assertEqual([result.highlighted['text'][0] for result in self.sb.search('Index*', highlight=True)['results']], ['<em>Indexed</em>!\n3', '<em>Indexed</em>!\n2', '<em>Indexed</em>!\n1'])
#
self.assertEqual(self.sb.search('', facets=['name']), {'hits': 0, 'results': []})
results = self.sb.search('index', facets=['name'])
self.assertEqual(results['hits'], 3)
self.assertEqual(results['facets']['fields']['name'], [('david1', 1), ('david2', 1), ('david3', 1)])
# self.assertEqual(self.sb.search('', date_facets={'pub_date': {'start_date': datetime.date(2008, 2, 26), 'end_date': datetime.date(2008, 2, 26), 'gap': '/MONTH'}}), [])
# results = self.sb.search('Index*', date_facets={'pub_date': {'start_date': datetime.date(2008, 2, 26), 'end_date': datetime.date(2008, 2, 26), 'gap': '/MONTH'}})
# self.assertEqual(results['hits'], 3)
# self.assertEqual(results['facets'], {})
#
# self.assertEqual(self.sb.search('', query_facets={'name': '[* TO e]'}), [])
# results = self.sb.search('Index*', query_facets={'name': '[* TO e]'})
# self.assertEqual(results['hits'], 3)
# self.assertEqual(results['facets'], {})
self.assertEqual(self.sb.search('', narrow_queries=['name:david1']), {'hits': 0, 'results': []})
results = self.sb.search('index*', narrow_queries=['name:david1'])
self.assertEqual(results['hits'], 1)
def test_spelling_suggestion(self):
self.sb.update(self.msi, self.sample_objs)
self.assertEqual(len(self.xapian_search('')), 3)
self.assertEqual(self.sb.search('indxe')['hits'], 0)
self.assertEqual(self.sb.search('indxe')['spelling_suggestion'], 'indexed')
self.assertEqual(self.sb.search('indxed')['hits'], 0)
self.assertEqual(self.sb.search('indxed')['spelling_suggestion'], 'indexed')
def test_stemming(self):
self.sb.update(self.msi, self.sample_objs)
self.assertEqual(len(self.xapian_search('')), 3)
results = self.sb.search('index', facets=['name'])
self.assertEqual(results['hits'], 3)
results = self.sb.search('indexing', facets=['name'])
self.assertEqual(results['hits'], 3)
def test_more_like_this(self):
self.sb.update(self.msi, self.sample_objs)
self.assertEqual(len(self.xapian_search('')), 3)
results = self.sb.more_like_this(self.sample_objs[0])
self.assertEqual(results['hits'], 2)
self.assertEqual([result.pk for result in results['results']], [u'3', u'2'])
def test_document_count(self):
self.sb.update(self.msi, self.sample_objs)
self.assertEqual(self.sb.document_count(), 3)
def test_delete_index(self):
self.sb.update(self.msi, self.sample_objs)
self.assert_(self.sb.document_count() > 0)
self.sb.delete_index()
self.assertEqual(self.sb.document_count(), 0)
def test_order_by(self):
self.sb.update(self.msi, self.sample_objs)
results = self.sb.search('*', sort_by=['pub_date'])
self.assertEqual([result.pk for result in results['results']], [u'1', u'2', u'3'])
results = self.sb.search('*', sort_by=['-pub_date'])
self.assertEqual([result.pk for result in results['results']], [u'3', u'2', u'1'])
results = self.sb.search('*', sort_by=['id'])
self.assertEqual([result.pk for result in results['results']], [u'3', u'2', u'1'])
results = self.sb.search('*', sort_by=['-id'])
self.assertEqual([result.pk for result in results['results']], [u'1', u'2', u'3'])
results = self.sb.search('*', sort_by=['value'])
self.assertEqual([result.pk for result in results['results']], [u'3', u'2', u'1'])
results = self.sb.search('*', sort_by=['-value'])
self.assertEqual([result.pk for result in results['results']], [u'1', u'2', u'3'])
results = self.sb.search('*', sort_by=['flag', 'id'])
self.assertEqual([result.pk for result in results['results']], [u'3', u'1', u'2'])
results = self.sb.search('*', sort_by=['flag', '-id'])
self.assertEqual([result.pk for result in results['results']], [u'1', u'3', u'2'])
def test__from_python(self):
self.assertEqual(self.sb._from_python('abc'), u'abc')
self.assertEqual(self.sb._from_python(1), u'1')
self.assertEqual(self.sb._from_python(2653), u'2653')
self.assertEqual(self.sb._from_python(25.5), u'25.5')
self.assertEqual(self.sb._from_python([1, 2, 3]), u'[1, 2, 3]')
self.assertEqual(self.sb._from_python((1, 2, 3)), u'(1, 2, 3)')
self.assertEqual(self.sb._from_python({'a': 1, 'c': 3, 'b': 2}), u"{'a': 1, 'c': 3, 'b': 2}")
self.assertEqual(self.sb._from_python(datetime.datetime(2009, 5, 9, 16, 14)), u'2009-05-09T16:14:00')
self.assertEqual(self.sb._from_python(datetime.datetime(2009, 5, 9, 0, 0)), u'2009-05-09T00:00:00')
self.assertEqual(self.sb._from_python(datetime.datetime(1899, 5, 18, 0, 0)), u'1899-05-18T00:00:00')
self.assertEqual(self.sb._from_python(datetime.datetime(2009, 5, 18, 1, 16, 30, 250)), u'2009-05-18T01:16:30.000250')