本文整理汇总了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)}
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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")
示例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()
示例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)
示例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
示例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'])