当前位置: 首页>>代码示例>>Python>>正文


Python SearchBackend.delete_index方法代码示例

本文整理汇总了Python中haystack.backends.xapian_backend.SearchBackend.delete_index方法的典型用法代码示例。如果您正苦于以下问题:Python SearchBackend.delete_index方法的具体用法?Python SearchBackend.delete_index怎么用?Python SearchBackend.delete_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在haystack.backends.xapian_backend.SearchBackend的用法示例。


在下文中一共展示了SearchBackend.delete_index方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: XapianSearchBackendTestCase

# 需要导入模块: from haystack.backends.xapian_backend import SearchBackend [as 别名]
# 或者: from haystack.backends.xapian_backend.SearchBackend import delete_index [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')
开发者ID:djinn,项目名称:xapian-haystack,代码行数:104,代码来源:xapian_backend.py


注:本文中的haystack.backends.xapian_backend.SearchBackend.delete_index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。