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


Python WhooshBackend.add_doc方法代码示例

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


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

示例1: test_can_survive_after_restart

# 需要导入模块: from bhsearch.whoosh_backend import WhooshBackend [as 别名]
# 或者: from bhsearch.whoosh_backend.WhooshBackend import add_doc [as 别名]
 def test_can_survive_after_restart(self):
     self.whoosh_backend.add_doc(dict(id="1", type="ticket"))
     whoosh_backend2 = WhooshBackend(self.env)
     whoosh_backend2.add_doc(dict(id="2", type="ticket"))
     result = whoosh_backend2.query(query.Every())
     self.assertEqual(2, result.hits)
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:8,代码来源:whoosh_backend.py

示例2: WhooshBackendTestCase

# 需要导入模块: from bhsearch.whoosh_backend import WhooshBackend [as 别名]
# 或者: from bhsearch.whoosh_backend.WhooshBackend import add_doc [as 别名]
class WhooshBackendTestCase(BaseBloodhoundSearchTest):
    def setUp(self):
        super(WhooshBackendTestCase, self).setUp()
        self.whoosh_backend = WhooshBackend(self.env)
        self.whoosh_backend.recreate_index()
        self.parser = DefaultQueryParser(self.env)

    def test_can_retrieve_docs(self):
        self.whoosh_backend.add_doc(dict(id="1", type="ticket"))
        self.whoosh_backend.add_doc(dict(id="2", type="ticket"))
        result = self.whoosh_backend.query(
            query.Every(),
            sort = [SortInstruction("id", ASC)],
        )
        self.print_result(result)
        self.assertEqual(2, result.hits)
        docs = result.docs
        self.assertEqual(
            {'id': u'1', 'type': u'ticket', 'unique_id': u'empty:ticket:1',
             'score': u'1'},
            docs[0])
        self.assertEqual(
            {'id': u'2', 'type': u'ticket', 'unique_id': u'empty:ticket:2',
             'score': u'2'},
            docs[1])

    def test_can_return_all_fields(self):
        self.whoosh_backend.add_doc(dict(id="1", type="ticket"))
        result = self.whoosh_backend.query(query.Every())
        self.print_result(result)
        docs = result.docs
        self.assertEqual(
            {'id': u'1', 'type': u'ticket', 'unique_id': u'empty:ticket:1',
                "score": 1.0},
            docs[0])

    def test_can_select_fields(self):
        self.whoosh_backend.add_doc(dict(id="1", type="ticket"))
        result = self.whoosh_backend.query(query.Every(),
            fields=("id", "type"))
        self.print_result(result)
        docs = result.docs
        self.assertEqual(
            {'id': '1', 'type': 'ticket'},
            docs[0])

    def test_can_survive_after_restart(self):
        self.whoosh_backend.add_doc(dict(id="1", type="ticket"))
        whoosh_backend2 = WhooshBackend(self.env)
        whoosh_backend2.add_doc(dict(id="2", type="ticket"))
        result = whoosh_backend2.query(query.Every())
        self.assertEqual(2, result.hits)

    def test_can_apply_multiple_sort_conditions_asc(self):
        self.whoosh_backend.add_doc(dict(id="2", type="ticket2"))
        self.whoosh_backend.add_doc(dict(id="3", type="ticket1"))
        self.whoosh_backend.add_doc(dict(id="4", type="ticket3"))
        self.whoosh_backend.add_doc(dict(id="1", type="ticket1"))
        result = self.whoosh_backend.query(
            query.Every(),
            sort = [SortInstruction("type", ASC), SortInstruction("id", ASC)],
            fields=("id", "type"),
        )
        self.print_result(result)
        self.assertEqual([{'type': 'ticket1', 'id': '1'},
                          {'type': 'ticket1', 'id': '3'},
                          {'type': 'ticket2', 'id': '2'},
                          {'type': 'ticket3', 'id': '4'}],
            result.docs)

    def test_can_apply_multiple_sort_conditions_desc(self):
        self.whoosh_backend.add_doc(dict(id="2", type="ticket2"))
        self.whoosh_backend.add_doc(dict(id="3", type="ticket1"))
        self.whoosh_backend.add_doc(dict(id="4", type="ticket3"))
        self.whoosh_backend.add_doc(dict(id="1", type="ticket1"))
        result = self.whoosh_backend.query(
            query.Every(),
            sort = [SortInstruction("type", ASC), SortInstruction("id", DESC)],
            fields=("id", "type"),
        )
        self.print_result(result)
        self.assertEqual([{'type': 'ticket1', 'id': '3'},
                          {'type': 'ticket1', 'id': '1'},
                          {'type': 'ticket2', 'id': '2'},
                          {'type': 'ticket3', 'id': '4'}],
            result.docs)

    def test_can_sort_by_score_and_date(self):
        the_first_date = datetime(2012, 12, 1)
        the_second_date = datetime(2012, 12, 2)
        the_third_date = datetime(2012, 12, 3)

        exact_match_string = "texttofind"
        not_exact_match_string = "texttofind bla"

        self.whoosh_backend.add_doc(dict(
            id="1",
            type="ticket",
            summary=not_exact_match_string,
            time=the_first_date,
#.........这里部分代码省略.........
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:103,代码来源:whoosh_backend.py


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