本文整理汇总了Python中autocompleter.Autocompleter.exact_suggest方法的典型用法代码示例。如果您正苦于以下问题:Python Autocompleter.exact_suggest方法的具体用法?Python Autocompleter.exact_suggest怎么用?Python Autocompleter.exact_suggest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autocompleter.Autocompleter
的用法示例。
在下文中一共展示了Autocompleter.exact_suggest方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dict_store_and_remove_all_basic_with_caching
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import exact_suggest [as 别名]
def test_dict_store_and_remove_all_basic_with_caching(self):
"""
Storing and removing items all at once works with caching turned on on dict ac
"""
# Let's turn on caching because that will store things in Redis and we want to make
# sure we clean them up.
setattr(auto_settings, 'CACHE_TIMEOUT', 3600)
autocomp = Autocompleter("metric")
autocomp.store_all()
keys = self.redis.hkeys('djac.test.metric')
self.assertEqual(len(keys), 8)
autocomp = Autocompleter("metric")
for i in range(0, 3):
autocomp.suggest('m')
autocomp.suggest('e')
autocomp.exact_suggest('PE Ratio TTM')
autocomp.exact_suggest('Market Cap')
autocomp.remove_all()
keys = self.redis.keys('djac.test.metric*')
self.assertEqual(len(keys), 0)
# Must set the setting back to where it was as it will persist
setattr(auto_settings, 'CACHE_TIMEOUT', 0)
示例2: test_store_and_remove_all_basic_with_caching
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import exact_suggest [as 别名]
def test_store_and_remove_all_basic_with_caching(self):
"""
Storing and removing items all the once works with caching turned on
"""
# Let's turn on caching because that will store things in Redis and we want to make
# sure we clean them up.
setattr(auto_settings, 'CACHE_TIMEOUT', 3600)
autocomp = Autocompleter("stock")
autocomp.store_all()
keys = self.redis.hkeys('djac.stock')
self.assertEqual(len(keys), 101)
autocomp = Autocompleter("stock")
for i in range(0, 3):
autocomp.suggest('a')
autocomp.suggest('z')
autocomp.exact_suggest('aapl')
autocomp.exact_suggest('xyz')
autocomp.remove_all()
keys = self.redis.keys('djac.stock*')
self.assertEqual(len(keys), 0)
# Must set the setting back to where it was as it will persist
setattr(auto_settings, 'CACHE_TIMEOUT', 0)
示例3: MultiExactMatchTestCase
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import exact_suggest [as 别名]
class MultiExactMatchTestCase(AutocompleterTestCase):
fixtures = ['stock_test_data_small.json', 'indicator_test_data_small.json']
def setUp(self):
super(MultiExactMatchTestCase, self).setUp()
setattr(auto_settings, 'MAX_EXACT_MATCH_WORDS', 10)
self.autocomp = Autocompleter("mixed")
self.autocomp.store_all()
def tearDown(self):
setattr(auto_settings, 'MAX_EXACT_MATCH_WORDS', 0)
self.autocomp.remove_all()
def test_exact_suggest(self):
"""
Exact matching works in multi-provider autocompleters
"""
matches = self.autocomp.exact_suggest('ma')
self.assertEqual(len(matches['stock']), 1)
matches = self.autocomp.exact_suggest('US Unemployment Rate')
self.assertEqual(len(matches['ind']), 1)
def test_move_exact_matches_to_top(self):
"""
MOVE_EXACT_MATCHES_TO_TOP works in multi-provider autocompleters
"""
matches = self.autocomp.suggest('Ma')
setattr(auto_settings, 'MOVE_EXACT_MATCHES_TO_TOP', True)
matches2 = self.autocomp.suggest('Ma')
self.assertNotEqual(matches['stock'][0]['search_name'], matches2['stock'][0]['search_name'])
setattr(auto_settings, 'MOVE_EXACT_MATCHES_TO_TOP', False)
示例4: StockExactMatchTestCase
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import exact_suggest [as 别名]
class StockExactMatchTestCase(AutocompleterTestCase):
fixtures = ['stock_test_data_small.json']
def setUp(self):
super(StockExactMatchTestCase, self).setUp()
setattr(auto_settings, 'MAX_EXACT_MATCH_WORDS', 10)
self.autocomp = Autocompleter("stock")
self.autocomp.store_all()
def tearDown(self):
setattr(auto_settings, 'MAX_EXACT_MATCH_WORDS', 0)
self.autocomp.remove_all()
def test_exact_suggest(self):
"""
Exact matching works
"""
matches_symbol = self.autocomp.exact_suggest('ma')
self.assertEqual(len(matches_symbol), 1)
def test_move_exact_matches_to_top_setting(self):
"""
MOVE_EXACT_MATCHES_TO_TOP works
"""
matches = self.autocomp.suggest('Ma')
setattr(auto_settings, 'MOVE_EXACT_MATCHES_TO_TOP', True)
matches2 = self.autocomp.suggest('Ma')
self.assertNotEqual(matches[0]['search_name'], matches2[0]['search_name'])
# Must set the setting back to where it was as it will persist
setattr(auto_settings, 'MOVE_EXACT_MATCHES_TO_TOP', False)
def test_move_exact_matches_overridable_at_ac_level(self):
"""
MOVE_EXACT_MATCHES_TO_TOP can be set at the autocompleter level
"""
matches = self.autocomp.suggest('Ma')
registry.set_autocompleter_setting(self.autocomp.name, 'MOVE_EXACT_MATCHES_TO_TOP', True)
matches2 = self.autocomp.suggest('Ma')
registry.del_autocompleter_setting(self.autocomp.name, 'MOVE_EXACT_MATCHES_TO_TOP')
self.assertNotEqual(matches[0]['search_name'], matches2[0]['search_name'])
def test_exact_caching(self):
"""
Exact caching works
"""
matches = self.autocomp.exact_suggest('aapl')
setattr(auto_settings, 'CACHE_TIMEOUT', 3600)
for i in range(0, 10):
matches2 = self.autocomp.exact_suggest('aapl')
self.assertEqual(len(matches), len(matches2))
# Must set the setting back to where it was as it will persist
setattr(auto_settings, 'CACHE_TIMEOUT', 0)
示例5: test_remove_intermediate_results_exact_suggest
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import exact_suggest [as 别名]
def test_remove_intermediate_results_exact_suggest(self):
"""
After exact_suggest call, all intermediate result sets are removed
"""
setattr(auto_settings, 'MAX_EXACT_MATCH_WORDS', 2)
autocomp = Autocompleter('stock')
autocomp.store_all()
autocomp.exact_suggest('aapl')
keys = self.redis.keys('djac.results.*')
self.assertEqual(len(keys), 0)
setattr(auto_settings, 'MAX_EXACT_MATCH_WORDS', 0)
示例6: exact_suggest
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import exact_suggest [as 别名]
def exact_suggest(request, name):
if settings.SUGGEST_PARAMETER_NAME in request.GET:
term = request.GET[settings.SUGGEST_PARAMETER_NAME]
ac = Autocompleter(name)
results = ac.exact_suggest(term)
json_response = json.dumps(results)
return HttpResponse(json_response, content_type='application/json')
return HttpResponseServerError("Search parameter not found.")
示例7: test_exact_matches_respect_max_words
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import exact_suggest [as 别名]
def test_exact_matches_respect_max_words(self):
"""
We don't store exact matches greater than the number of words in MAX_EXACT_MATCH_WORDS
"""
setattr(auto_settings, 'MAX_EXACT_MATCH_WORDS', 10)
autocomp = Autocompleter("stock")
autocomp.store_all()
matches = autocomp.exact_suggest('International Business Machines Corporation')
self.assertEqual(len(matches), 1)
autocomp.remove_all()
setattr(auto_settings, 'MAX_EXACT_MATCH_WORDS', 2)
autocomp = Autocompleter("stock")
autocomp.store_all()
matches = autocomp.exact_suggest('International Business Machines Corporation')
self.assertEqual(len(matches), 0)
autocomp.remove_all()
# Must set the setting back to where it was as it will persist
setattr(auto_settings, 'MAX_EXACT_MATCH_WORDS', 0)
示例8: TestExactSuggestView
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import exact_suggest [as 别名]
class TestExactSuggestView(AutocompleterTestCase):
fixtures = ['stock_test_data_small.json']
def setUp(self):
super(TestExactSuggestView, self).setUp()
setattr(settings, 'MAX_EXACT_MATCH_WORDS', 10)
self.autocomp = Autocompleter('stock')
self.autocomp.store_all()
def tearDown(self):
setattr(settings, 'MAX_EXACT_MATCH_WORDS', 0)
self.autocomp.remove_all()
def test_simple_exact_suggest_match(self):
"""
ExactSuggestView returns 200 status code and correct number of results on match
"""
exact_suggest_url = reverse('exact_suggest', kwargs={'name': 'stock'})
matches_symbol = self.autocomp.exact_suggest('ma')
response = self.client.get(exact_suggest_url, data={settings.SUGGEST_PARAMETER_NAME: 'ma'})
self.assertEqual(response.status_code, 200)
json_response = json.loads(response.content.decode('utf-8'))
self.assertGreaterEqual(len(json_response), 1)
self.assertEqual(len(json_response), len(matches_symbol))
def test_no_exact_suggest_match(self):
"""
ExactSuggestView returns 200 status code when there is no match
"""
url = reverse('exact_suggest', kwargs={'name': 'stock'})
matches_symbol = self.autocomp.exact_suggest('gobblygook')
response = self.client.get(url, data={settings.SUGGEST_PARAMETER_NAME: 'gobblygook'})
self.assertEqual(response.status_code, 200)
json_response = json.loads(response.content.decode('utf-8'))
self.assertEqual(len(json_response), len(matches_symbol))
示例9: StockMatchTestCase
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import exact_suggest [as 别名]
class StockMatchTestCase(AutocompleterTestCase):
fixtures = ['stock_test_data_small.json']
def setUp(self):
self.autocomp = Autocompleter("stock")
self.autocomp.store_all()
super(StockMatchTestCase, self).setUp()
def tearDown(self):
self.autocomp.remove_all()
def test_simple_match(self):
"""
Basic matching works
"""
matches_symbol = self.autocomp.suggest('a')
self.assertEqual(len(matches_symbol), 10)
def test_exact_match(self):
"""
Exact matching works
"""
matches_symbol = self.autocomp.exact_suggest('ma')
self.assertEqual(len(matches_symbol), 1)
def test_no_match(self):
"""
Phrases that match nothing work
"""
matches_symbol = self.autocomp.suggest('gobblygook')
self.assertEqual(len(matches_symbol), 0)
def test_dual_term_matches(self):
"""
Items in autocompleter can match against multiple unique terms
"""
matches_symbol = self.autocomp.suggest('AAPL')
self.assertEqual(len(matches_symbol), 1)
matches_name = self.autocomp.suggest('Apple')
self.assertEqual(len(matches_name), 1)
def test_accented_matches(self):
"""
Accented phrases match against both their orignal accented form, and their non-accented basic form.
"""
matches = self.autocomp.suggest('estee lauder')
self.assertEqual(len(matches), 1)
self.assertEqual(matches[0]['search_name'], 'EL')
matches = self.autocomp.suggest(u'estée lauder')
self.assertEqual(len(matches), 1)
self.assertEqual(matches[0]['search_name'], 'EL')
def test_exact_matches_setting(self):
"""
MOVE_EXACT_MATCHES_TO_TOP works
"""
matches = self.autocomp.suggest('Ma')
setattr(auto_settings, 'MOVE_EXACT_MATCHES_TO_TOP', True)
matches2 = self.autocomp.suggest('Ma')
self.assertNotEqual(matches[0]['search_name'], matches2[0]['search_name'])
# Must set the setting back to where it was as it will persist
setattr(auto_settings, 'MOVE_EXACT_MATCHES_TO_TOP', False)
def test_max_results_setting(self):
"""
MAX_RESULTS is respected.
"""
matches = self.autocomp.suggest('a')
self.assertEqual(len(matches), 10)
setattr(auto_settings, 'MAX_RESULTS', 2)
matches = self.autocomp.suggest('a')
self.assertEqual(len(matches), 2)
# Must set the setting back to where it was as it will persist
setattr(auto_settings, 'MAX_RESULTS', 10)
def test_ac_provider_specific_max_results_setting(self):
"""
Autocompleter/Provider specific MAX_RESULTS is respected
"""
matches = self.autocomp.suggest('a')
self.assertEqual(len(matches), 10)
registry.set_ac_provider_setting("stock", StockAutocompleteProvider, 'MAX_RESULTS', 5)
matches = self.autocomp.suggest('a')
self.assertEqual(len(matches), 5)
# Must set the setting back to where it was as it will persist
registry.del_ac_provider_setting("stock", StockAutocompleteProvider, 'MAX_RESULTS')
def test_caching(self):
"""
Caching works
"""
matches = self.autocomp.suggest('a')
setattr(auto_settings, 'CACHE_TIMEOUT', 3600)
#.........这里部分代码省略.........