本文整理汇总了Python中bhsearch.api.BloodhoundSearchApi.rebuild_index方法的典型用法代码示例。如果您正苦于以下问题:Python BloodhoundSearchApi.rebuild_index方法的具体用法?Python BloodhoundSearchApi.rebuild_index怎么用?Python BloodhoundSearchApi.rebuild_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bhsearch.api.BloodhoundSearchApi
的用法示例。
在下文中一共展示了BloodhoundSearchApi.rebuild_index方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IndexWhooshTestCase
# 需要导入模块: from bhsearch.api import BloodhoundSearchApi [as 别名]
# 或者: from bhsearch.api.BloodhoundSearchApi import rebuild_index [as 别名]
class IndexWhooshTestCase(BaseBloodhoundSearchTest):
def setUp(self):
super(IndexWhooshTestCase, self).setUp()
self.whoosh_backend = WhooshBackend(self.env)
self.whoosh_backend.recreate_index()
self.search_api = BloodhoundSearchApi(self.env)
def tearDown(self):
shutil.rmtree(self.env.path)
self.env.reset_db()
def test_can_index_ticket(self):
ticket = self.create_dummy_ticket()
TicketIndexer(self.env).resource_created(ticket, None)
results = self.search_api.query("*:*")
self.print_result(results)
self.assertEqual(1, results.hits)
def test_that_ticket_indexed_when_inserted_in_db(self):
ticket = self.create_dummy_ticket()
ticket.insert()
results = self.search_api.query("*:*")
self.print_result(results)
self.assertEqual(1, results.hits)
def test_can_reindex_twice(self):
self.insert_ticket("t1")
self.whoosh_backend.recreate_index()
#act
self.search_api.rebuild_index()
#just to test that index was re-created
self.search_api.rebuild_index()
#assert
results = self.search_api.query("*:*")
self.assertEqual(1, results.hits)
def test_can_reindex_tickets(self):
self.insert_ticket("t1")
self.insert_ticket("t2")
self.insert_ticket("t3")
self.whoosh_backend.recreate_index()
#act
self.search_api.rebuild_index()
#assert
results = self.search_api.query("*:*")
self.print_result(results)
self.assertEqual(3, results.hits)
def test_can_reindex_wiki(self):
self.insert_wiki("page1", "some text")
self.insert_wiki("page2", "some text")
self.whoosh_backend.recreate_index()
#act
self.search_api.rebuild_index()
#assert
results = self.search_api.query("*:*")
self.print_result(results)
self.assertEqual(2, results.hits)
def test_can_reindex_mixed_types(self):
self.insert_wiki("page1", "some text")
self.insert_ticket("t1")
self.whoosh_backend.recreate_index()
#act
self.search_api.rebuild_index()
#assert
results = self.search_api.query("*:*")
self.print_result(results)
self.assertEqual(2, results.hits)
def test_can_reindex_milestones(self):
MilestoneIndexer(self.env)
self.insert_milestone("M1")
self.insert_milestone("M2")
self.whoosh_backend.recreate_index()
#act
self.search_api.rebuild_index()
#assert
results = self.search_api.query("*:*")
self.print_result(results)
self.assertEqual(2, results.hits)
示例2: MilestoneIndexerEventsTestCase
# 需要导入模块: from bhsearch.api import BloodhoundSearchApi [as 别名]
# 或者: from bhsearch.api.BloodhoundSearchApi import rebuild_index [as 别名]
class MilestoneIndexerEventsTestCase(BaseBloodhoundSearchTest):
DUMMY_MILESTONE_NAME = "dummyName"
def setUp(self):
super(MilestoneIndexerEventsTestCase, self).setUp()
self.whoosh_backend = WhooshBackend(self.env)
self.whoosh_backend.recreate_index()
self.search_api = BloodhoundSearchApi(self.env)
def test_can_index_created_milestone(self):
#arrange
self.insert_milestone(self.DUMMY_MILESTONE_NAME, "dummy text")
#act
results = self.search_api.query("*:*")
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
doc = results.docs[0]
self.assertEqual(self.DUMMY_MILESTONE_NAME, doc["id"])
self.assertEqual("dummy text", doc["content"])
self.assertEqual("milestone", doc["type"])
self.assertNotIn("due", doc )
def test_can_index_minimal_milestone(self):
#arrange
self.insert_milestone(self.DUMMY_MILESTONE_NAME)
#act
results = self.search_api.query("*:*")
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
doc = results.docs[0]
self.assertEqual(self.DUMMY_MILESTONE_NAME, doc["id"])
self.assertNotIn("content", doc)
def test_can_index_renamed_milestone(self):
#arrange
self.insert_milestone(self.DUMMY_MILESTONE_NAME, "dummy text")
self.change_milestone(
self.DUMMY_MILESTONE_NAME,
name="updated name",
description="updated description",
)
#act
results = self.search_api.query("*:*")
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
doc = results.docs[0]
self.assertEqual("updated name", doc["id"])
self.assertEqual("updated description", doc["content"])
def test_can_index_changed_milestone(self):
#arrange
self.insert_milestone(self.DUMMY_MILESTONE_NAME, "dummy text")
self.change_milestone(
self.DUMMY_MILESTONE_NAME,
description="updated description",
)
#act
results = self.search_api.query("*:*")
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
doc = results.docs[0]
self.assertEqual(self.DUMMY_MILESTONE_NAME, doc["id"])
self.assertEqual("updated description", doc["content"])
def test_can_index_delete(self):
#arrange
self.insert_milestone(self.DUMMY_MILESTONE_NAME)
results = self.search_api.query("*")
self.assertEqual(1, results.hits)
#act
Milestone(self.env, self.DUMMY_MILESTONE_NAME).delete()
#assert
results = self.search_api.query("*")
self.print_result(results)
self.assertEqual(0, results.hits)
def test_can_reindex_minimal_milestone(self):
#arrange
self.insert_milestone(self.DUMMY_MILESTONE_NAME)
self.whoosh_backend.recreate_index()
#act
self.search_api.rebuild_index()
#assert
results = self.search_api.query("*:*")
self.print_result(results)
self.assertEqual(1, results.hits)
doc = results.docs[0]
self.assertEqual(self.DUMMY_MILESTONE_NAME, doc["id"])
self.assertEqual("milestone", doc["type"])
def test_that_tickets_updated_after_milestone_renaming(self):
#asser
INITIAL_MILESTONE = "initial_milestone"
RENAMED_MILESTONE = "renamed_name"
milestone = self.insert_milestone(INITIAL_MILESTONE)
#.........这里部分代码省略.........
示例3: ApiQueryWithWhooshTestCase
# 需要导入模块: from bhsearch.api import BloodhoundSearchApi [as 别名]
# 或者: from bhsearch.api.BloodhoundSearchApi import rebuild_index [as 别名]
#.........这里部分代码省略.........
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
def test_can_query_strict_summary(self):
#arrange
self.insert_ticket("summary1 keyword")
self.insert_ticket("summary2", description = "bla keyword")
#act
results = self.search_api.query("summary:keyword")
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
def test_that_summary_hit_is_higher_than_description(self):
#arrange
self.insert_ticket("summary1 keyword")
self.insert_ticket("summary2", description = "bla keyword")
#act
results = self.search_api.query("keyword")
self.print_result(results)
#assert
self.assertEqual(2, results.hits)
docs = results.docs
self.assertEqual("summary1 keyword", docs[0]["summary"])
self.assertEqual("summary2", docs[1]["summary"])
def test_other_conditions_applied(self):
#arrange
self.insert_ticket("summary1 keyword", status="closed")
self.insert_ticket("summary2", description = "bla keyword")
self.insert_ticket("summary3", status="closed")
#act
results = self.search_api.query("keyword status:closed")
self.print_result(results)
#assert
self.assertEqual(1, results.hits)
docs = results.docs
self.assertEqual("summary1 keyword", docs[0]["summary"])
def test_that_filter_queries_applied(self):
#arrange
self.insert_ticket("t1", status="closed", component = "c1")
self.insert_ticket("t2", status="closed", component = "c1")
self.insert_ticket("t3", status="closed",
component = "NotInFilterCriteria")
#act
results = self.search_api.query(
"*",
filter= ['status:"closed"', 'component:"c1"'],
sort= [SortInstruction("id", ASC)]
)
self.print_result(results)
#assert
self.assertEqual(2, results.hits)
docs = results.docs
self.assertEqual("t1", docs[0]["summary"])
self.assertEqual("t2", docs[1]["summary"])
def test_that_upgrading_environment_adds_documents_to_index(self):
self.insert_ticket("t1")
self.insert_ticket("t2")
self.search_api.upgrade_environment(self.env.db_transaction)
results = self.search_api.query("type:ticket")
self.assertEqual(2, results.hits)
def test_can_index_wiki_with_same_id_from_different_products(self):
with self.product('p1'):
self.insert_wiki('title', 'content')
with self.product('p2'):
self.insert_wiki('title', 'content 2')
results = self.search_api.query("type:wiki")
self.assertEqual(results.hits, 2)
def test_upgrade_index_with_no_product(self):
"""See #773"""
class NoProductIndexer(BaseIndexer):
implements(IIndexParticipant)
def get_entries_for_index(self):
yield {
IndexFields.TYPE: 'noproduct',
IndexFields.ID: '1'
}
self.search_api.rebuild_index()
self.unregister(NoProductIndexer)
@staticmethod
def unregister(component):
ComponentMeta._components.remove(component)
for interface in component.__dict__.get('_implements', ()):
ComponentMeta._registry.get(interface).remove(component)