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


Python api.BloodhoundSearchApi类代码示例

本文整理汇总了Python中bhsearch.api.BloodhoundSearchApi的典型用法代码示例。如果您正苦于以下问题:Python BloodhoundSearchApi类的具体用法?Python BloodhoundSearchApi怎么用?Python BloodhoundSearchApi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: ChangesetIndexerEventsTestCase

class ChangesetIndexerEventsTestCase(BaseBloodhoundSearchTest):
    def setUp(self):
        super(ChangesetIndexerEventsTestCase, self).setUp()
        self.whoosh_backend = WhooshBackend(self.env)
        self.whoosh_backend.recreate_index()
        self.search_api = BloodhoundSearchApi(self.env)
        self.repository_manager = RepositoryManager(self.env)
        self.inject_dummy_repository()

    def test_can_index_added_changeset(self):
        rev = self.insert_changeset("Changed document 1.")

        results = self.search_api.query("*:*")

        self.assertEqual(1, results.hits)
        doc = results.docs[0]
        self.assertEqual('%s/dummy' % rev, doc["id"])
        self.assertEqual('dummy', doc["repository"])
        self.assertEqual('1', doc["revision"])
        self.assertEqual("Changed document 1.", doc["message"])

    def test_can_index_modified_changeset(self):
        rev = self.insert_changeset("Changed document 1.")
        self.modify_changeset(rev, "Added document 1.")

        results = self.search_api.query("*:*")

        self.assertEqual(1, results.hits)
        doc = results.docs[0]
        self.assertEqual('%s/dummy' % rev, doc["id"])
        self.assertEqual('dummy', doc["repository"])
        self.assertEqual('1', doc["revision"])
        self.assertEqual("Added document 1.", doc["message"])

    def insert_changeset(self, message, author=None, date=None, revision=None):
        rev = self.repository.add_changeset(revision, message, author, date)
        self.repository_manager.notify("changeset_added", 'dummy', [rev])
        return rev

    def modify_changeset(self, rev, message=None, author=None, date=None):
        changeset = self.repository.get_changeset(rev)
        if message is not None:
            changeset.message = message
        if author is not None:
            changeset.author = author
        if date is not None:
            changeset.date = date
        self.repository_manager.notify("changeset_modified", "dummy", [rev])

    def inject_dummy_repository(self):
        # pylint: disable=protected-access,attribute-defined-outside-init
        self.repository = DummyRepositry()
        self.repository_connector = DummyRepositoryConnector(self.env)
        self.repository_connector.repository = self.repository
        self.repository_manager._all_repositories = {
            'dummy': dict(dir='dirname', type='dummy')}
        self.repository_manager._connectors = {
            'dummy': (self.repository_connector, 100)}
开发者ID:thimalk,项目名称:bloodhound,代码行数:58,代码来源:changeset_search.py

示例2: milestone_deleted

 def milestone_deleted(self, milestone):
     try:
         search_api = BloodhoundSearchApi(self.env)
         search_api.delete_doc(MILESTONE_TYPE, milestone.name)
     except Exception, e:
         if self.silence_on_error:
             self.log.error("Error occurs during milestone indexing. \
                 The error will not be propagated. Exception: %s", e)
         else:
             raise
开发者ID:domaemon,项目名称:bloodhound-qa,代码行数:10,代码来源:milestone_search.py

示例3: _index_milestone

 def _index_milestone(self, milestone):
     try:
         doc = self.build_doc(milestone)
         search_api = BloodhoundSearchApi(self.env)
         search_api.add_doc(doc)
     except Exception, e:
         if self.silence_on_error:
             self.log.error("Error occurs during wiki indexing. \
                 The error will not be propagated. Exception: %s", e)
         else:
             raise
开发者ID:thimalk,项目名称:bloodhound,代码行数:11,代码来源:milestone_search.py

示例4: ticket_deleted

 def ticket_deleted(self, ticket):
     """Called when a ticket is deleted."""
     try:
         search_api = BloodhoundSearchApi(self.env)
         search_api.delete_doc(TICKET_TYPE, ticket.id)
     except Exception, e:
         if self.silence_on_error:
             self.log.error("Error occurs during deleting ticket. \
                 The error will not be propagated. Exception: %s", e)
         else:
             raise
开发者ID:domaemon,项目名称:bloodhound-qa,代码行数:11,代码来源:ticket_search.py

示例5: _index_ticket

 def _index_ticket(self, ticket, search_api=None, operation_context=None):
     try:
         if not search_api:
             search_api = BloodhoundSearchApi(self.env)
         doc = self.build_doc(ticket)
         search_api.add_doc(doc, operation_context)
     except Exception, e:
         if self.silence_on_error:
             self.log.error("Error occurs during ticket indexing. \
                 The error will not be propagated. Exception: %s", e)
         else:
             raise
开发者ID:mohsadki,项目名称:dargest,代码行数:12,代码来源:ticket_search.py

示例6: wiki_page_deleted

 def wiki_page_deleted(self, page):
     """Called when a ticket is deleted."""
     try:
         search_api = BloodhoundSearchApi(self.env)
         search_api.delete_doc(
             get_product(self.env).prefix, WIKI_TYPE, page.name)
     except Exception, e:
         if self.silence_on_error.lower() == "true":
             self.log.error("Error occurs during wiki indexing. \
                 The error will not be propagated. Exception: %s", e)
         else:
             raise
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:12,代码来源:wiki_search.py

示例7: resource_deleted

 def resource_deleted(self, resource, context):
     # pylint: disable=unused-argument
     try:
         search_api = BloodhoundSearchApi(self.env)
         search_api.delete_doc(
             get_product(self.env).prefix, MILESTONE_TYPE, resource.name)
     except Exception, e:
         if self.silence_on_error:
             self.log.error("Error occurs during milestone indexing. \
                 The error will not be propagated. Exception: %s", e)
         else:
             raise
开发者ID:thimalk,项目名称:bloodhound,代码行数:12,代码来源:milestone_search.py

示例8: wiki_page_renamed

 def wiki_page_renamed(self, page, old_name):
     """Called when a page has been renamed."""
     try:
         doc = self.build_doc(page)
         search_api = BloodhoundSearchApi(self.env)
         search_api.change_doc_id(doc, old_name)
     except Exception, e:
         if self.silence_on_error:
             self.log.error("Error occurs during renaming wiki from %s \
                 to %s. The error will not be propagated. Exception: %s",
             old_name, page.name, e)
         else:
             raise
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:13,代码来源:wiki_search.py

示例9: _index_wiki

 def _index_wiki(self, page):
     try:
         doc = self.build_doc(page)
         search_api = BloodhoundSearchApi(self.env)
         search_api.add_doc(doc)
     except Exception, e:
         page_name = None
         if page is not None:
             page_name = page.name
         if self.silence_on_error:
             self.log.error("Error occurs during wiki indexing: %s. \
                 The error will not be propagated. Exception: %s",
                 page_name, e)
         else:
             raise
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:15,代码来源:wiki_search.py

示例10: _rename_milestone

 def _rename_milestone(self, milestone, old_name):
     try:
         doc = self.build_doc(milestone)
         search_api = BloodhoundSearchApi(self.env)
         with search_api.start_operation() as operation_context:
             search_api.change_doc_id(doc, old_name, operation_context)
             TicketIndexer(self.env).reindex_tickets(
                 search_api, operation_context, milestone=milestone.name)
     except Exception, e:
         if self.silence_on_error:
             self.log.error("Error occurs during renaming milestone from \
              %s to %s. The error will not be propagated. Exception: %s",
             old_name, milestone.name, e)
         else:
             raise
开发者ID:thimalk,项目名称:bloodhound,代码行数:15,代码来源:milestone_search.py

示例11: setUp

 def setUp(self):
     super(TicketIndexerTestCase, self).setUp()
     self.whoosh_backend = WhooshBackend(self.env)
     self.whoosh_backend.recreate_index()
     self.ticket_indexer = TicketIndexer(self.env)
     self.search_api = BloodhoundSearchApi(self.env)
     self.env.config.set('bhsearch', 'silence_on_error', "False")
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:7,代码来源:ticket_search.py

示例12: setUp

 def setUp(self):
     super(ChangesetIndexerEventsTestCase, self).setUp()
     self.whoosh_backend = WhooshBackend(self.env)
     self.whoosh_backend.recreate_index()
     self.search_api = BloodhoundSearchApi(self.env)
     self.repository_manager = RepositoryManager(self.env)
     self.inject_dummy_repository()
开发者ID:thimalk,项目名称:bloodhound,代码行数:7,代码来源:changeset_search.py

示例13: setUp

 def setUp(self):
     super(WikiIndexerEventsTestCase, self).setUp()
     self.wiki_system = WikiSystem(self.env)
     self.whoosh_backend = WhooshBackend(self.env)
     self.whoosh_backend.recreate_index()
     self.search_api = BloodhoundSearchApi(self.env)
     self.wiki_participant = WikiSearchParticipant(self.env)
     self.query_parser = DefaultQueryParser(self.env)
开发者ID:mohsadki,项目名称:dargest,代码行数:8,代码来源:wiki_search.py

示例14: _component_changed

 def _component_changed(self, component, old_values):
     if "name" in old_values:
         old_name = old_values["name"]
         try:
             search_api = BloodhoundSearchApi(self.env)
             with search_api.start_operation() as operation_context:
                 TicketIndexer(self.env).reindex_tickets(
                     search_api,
                     operation_context,
                     component=component.name)
         except Exception, e:
             if self.silence_on_error:
                 self.log.error("Error occurs during renaming Component \
                 from %s to %s. The error will not be propagated. \
                 Exception: %s",
                 old_name, component.name, e)
             else:
                 raise
开发者ID:mohsadki,项目名称:dargest,代码行数:18,代码来源:ticket_search.py

示例15: QuerySuggestionTestCase

class QuerySuggestionTestCase(BaseBloodhoundSearchTest):
    def setUp(self):
        super(QuerySuggestionTestCase, self).setUp(create_req=True)
        self.whoosh_backend = WhooshBackend(self.env)
        self.whoosh_backend.recreate_index()

        self.search_api = BloodhoundSearchApi(self.env)

    def test_fills_suggestion_field(self):
        self.insert_ticket("test")
        self.insert_milestone("test")
        self.insert_wiki("name", "test")

        results = self.search_api.query("%s:test" % SuggestionFields.BASKET)

        self.assertEqual(results.hits, 3)

    def test_provides_suggestions(self):
        self.insert_ticket("test")
        self.req.args[RequestParameters.QUERY] = "tesk"

        data = self.process_request()

        self.assertIn(RequestContext.DATA_QUERY_SUGGESTION, data)
        suggestion = data[RequestContext.DATA_QUERY_SUGGESTION]
        self.assertEqual(suggestion['query'], 'test')
        self.assertIn('q=test', suggestion['href'])

    def test_provides_suggestions_for_multi_term_queries(self):
        self.insert_ticket("another test")
        self.req.args[RequestParameters.QUERY] = "another tesk"

        data = self.process_request()

        suggestion = data[RequestContext.DATA_QUERY_SUGGESTION]
        self.assertEqual(suggestion['query'], 'another test')

    def test_provides_suggestions_for_queries_with_unknown_words(self):
        self.insert_ticket("test")
        self.req.args[RequestParameters.QUERY] = "another tesk"

        data = self.process_request()

        suggestion = data[RequestContext.DATA_QUERY_SUGGESTION]
        self.assertEqual(suggestion['query'], 'another test')

    def test_suggestion_href_contains_used_filters(self):
        self.insert_ticket("test")
        self.req.args[RequestParameters.QUERY] = "tesk"
        self.req.args[RequestParameters.FILTER_QUERY] = ['filter']

        data = self.process_request()

        suggestion = data[RequestContext.DATA_QUERY_SUGGESTION]
        self.assertIn('fq=filter', suggestion['href'])
开发者ID:thimalk,项目名称:bloodhound-789,代码行数:55,代码来源:query_suggestion.py


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