本文整理汇总了Python中searcher.Searcher.count方法的典型用法代码示例。如果您正苦于以下问题:Python Searcher.count方法的具体用法?Python Searcher.count怎么用?Python Searcher.count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类searcher.Searcher
的用法示例。
在下文中一共展示了Searcher.count方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SearcherTests
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import count [as 别名]
class SearcherTests(unittest.TestCase):
"""
Test case for SearchEngine class.
"""
def setUp(self):
"""
Setup search engine that will be subjected to the tests.
"""
self.twitter = Twitter(CUR_DIR + "/test_crossfit.tweets", CUR_DIR + "/test_stop_words.txt")
self.twitter.load_tweets_and_build_index()
self.searcher = Searcher(self.twitter.tweets, self.twitter.stop_words)
def test_indexed_doc_count(self):
self.assertEqual(self.searcher.count(), 10)
def test_existent_term_search(self):
"""
Test if search is correctly performed.
"""
results = self.searcher.search("coach")
expected_results = 3
self.assertEqual(results[0].indexable.docid, expected_results)
def test_non_existent_term_search(self):
"""
Test if search is correctly performed.
"""
expected_results = []
results = self.searcher.search("asdasdasdas")
self.assertListEqual(results, expected_results)
def test_search_result_limit(self):
"""
Test if search results can be limited.
"""
results = self.searcher.search("crossfit", 1)
expected_results = 6
self.assertEqual(results[0].indexable.docid, expected_results)