本文整理汇总了Python中bhsearch.whoosh_backend.WhooshBackend.query方法的典型用法代码示例。如果您正苦于以下问题:Python WhooshBackend.query方法的具体用法?Python WhooshBackend.query怎么用?Python WhooshBackend.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bhsearch.whoosh_backend.WhooshBackend
的用法示例。
在下文中一共展示了WhooshBackend.query方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RealIndexTestCase
# 需要导入模块: from bhsearch.whoosh_backend import WhooshBackend [as 别名]
# 或者: from bhsearch.whoosh_backend.WhooshBackend import query [as 别名]
class RealIndexTestCase(BaseBloodhoundSearchTest):
"""
This test case is not supposed to be run from CI tool.
The purpose of the class is to work with real Bloodhound Search Index and
should be used for debugging purposes only
"""
def setUp(self):
self.env = EnvironmentStub(enable=['bhsearch.*'])
current_current_dir = os.getcwd()
real_env_path = os.path.join(
current_current_dir,
"../../../installer/bloodhound/environments/main")
self.env.path = real_env_path
self.whoosh_backend = WhooshBackend(self.env)
self.req = Mock(
perm=MockPerm(),
chrome={'logo': {}},
href=Href("/main"),
args=arg_list_to_args([]),
)
def test_read_all(self):
result = self.whoosh_backend.query(
query.Every()
)
self.print_result(result)
result = self.whoosh_backend.query(
query.Every()
)
self.print_result(result)
self.assertLessEqual(1, result.hits)
def test_read_with_type_facet(self):
result = self.whoosh_backend.query(
query.Every()
)
self.print_result(result)
result = self.whoosh_backend.query(
query.Every(),
facets=["type"]
)
self.print_result(result)
self.assertLessEqual(1, result.hits)
def test_read_from_search_module(self):
self.req.args[RequestParameters.QUERY] = "*"
self.process_request()
示例2: WhooshEmptyFacetErrorWorkaroundTestCase
# 需要导入模块: from bhsearch.whoosh_backend import WhooshBackend [as 别名]
# 或者: from bhsearch.whoosh_backend.WhooshBackend import query [as 别名]
class WhooshEmptyFacetErrorWorkaroundTestCase(BaseBloodhoundSearchTest):
def setUp(self):
super(WhooshEmptyFacetErrorWorkaroundTestCase, self).setUp()
self.whoosh_backend = WhooshBackend(self.env)
self.whoosh_backend.recreate_index()
self.parser = DefaultQueryParser(self.env)
self.empty_facet_workaround = WhooshEmptyFacetErrorWorkaround(self.env)
def tearDown(self):
shutil.rmtree(self.env.path)
self.env.reset_db()
def test_set_should_not_be_empty_fields(self):
self.insert_ticket("test x")
result = self.whoosh_backend.query(query.Every())
self.print_result(result)
doc = result.docs[0]
null_marker = WhooshEmptyFacetErrorWorkaround.NULL_MARKER
self.assertEqual(null_marker, doc["component"])
self.assertEqual(null_marker, doc["status"])
self.assertEqual(null_marker, doc["milestone"])
def test_can_fix_query_filter(self):
parsed_filter = self.parser.parse_filters(
["type:ticket", "NOT (milestone:*)"])
query_parameters = dict(filter=parsed_filter)
self.empty_facet_workaround.query_pre_process(
query_parameters)
result_filter = query_parameters["filter"]
self.assertEquals('(type:ticket AND milestone:empty)',
str(result_filter))
def test_does_interfere_query_filter_if_not_needed(self):
parsed_filter = self.parser.parse_filters(
["type:ticket", "milestone:aaa"])
query_parameters = dict(filter=parsed_filter)
self.empty_facet_workaround.query_pre_process(
query_parameters)
result_filter = query_parameters["filter"]
self.assertEquals('(type:ticket AND milestone:aaa)',
str(result_filter))
示例3: test_can_survive_after_restart
# 需要导入模块: from bhsearch.whoosh_backend import WhooshBackend [as 别名]
# 或者: from bhsearch.whoosh_backend.WhooshBackend import query [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)
示例4: WhooshBackendTestCase
# 需要导入模块: from bhsearch.whoosh_backend import WhooshBackend [as 别名]
# 或者: from bhsearch.whoosh_backend.WhooshBackend import query [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,
#.........这里部分代码省略.........