本文整理汇总了Python中autocompleter.Autocompleter.store_all方法的典型用法代码示例。如果您正苦于以下问题:Python Autocompleter.store_all方法的具体用法?Python Autocompleter.store_all怎么用?Python Autocompleter.store_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autocompleter.Autocompleter
的用法示例。
在下文中一共展示了Autocompleter.store_all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MultiExactMatchTestCase
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [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)
示例2: MixedFacetProvidersMatchingTestCase
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [as 别名]
class MixedFacetProvidersMatchingTestCase(AutocompleterTestCase):
fixtures = ['stock_test_data_small.json', 'indicator_test_data_small.json']
def setUp(self):
super(MixedFacetProvidersMatchingTestCase, self).setUp()
self.autocomp = Autocompleter('facet_stock_no_facet_ind')
self.autocomp.store_all()
def test_autocompleter_with_facet_and_non_facet_providers(self):
"""
Autocompleter with facet and non-facet providers works correctly
"""
registry.set_autocompleter_setting('facet_stock_no_facet_ind', 'MAX_RESULTS', 100)
facets = [
{
'type': 'and',
'facets': [{'key': 'sector', 'value': 'Financial Services'}]
}
]
matches = self.autocomp.suggest('a')
facet_matches = self.autocomp.suggest('a', facets=facets)
# because we are using the faceted stock provider in the 'facet_stock_no_facet_ind' AC,
# we expect using facets will decrease the amount of results when searching.
self.assertEqual(len(matches['faceted_stock']), 25)
self.assertEqual(len(facet_matches['faceted_stock']), 2)
# since the indicator provider does not support facets,
# we expect the search results from both a facet and non-facet search to be the same.
self.assertEqual(len(matches['ind']), 16)
self.assertEqual(len(matches['ind']), len(facet_matches['ind']))
registry.del_autocompleter_setting('facet_stock_no_facet_ind', 'MAX_RESULTS')
示例3: test_dict_store_and_remove_all_basic_with_caching
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [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)
示例4: MultiMatchingPerfTestCase
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [as 别名]
class MultiMatchingPerfTestCase(AutocompleterTestCase):
fixtures = ['stock_test_data.json', 'indicator_test_data.json']
num_iterations = 1000
def setUp(self):
self.autocomp = Autocompleter("mixed")
self.autocomp.store_all()
def tearDown(self):
self.autocomp.remove_all()
def test_repeated_matches(self):
"""
Matching is fast
"""
setattr(auto_settings, 'MATCH_OUT_OF_ORDER_WORDS', True)
setattr(auto_settings, 'MOVE_EXACT_MATCHES_TO_TOP', True)
for i in range(1, self.num_iterations):
self.autocomp.suggest('ma')
for i in range(1, self.num_iterations):
self.autocomp.suggest('price consumer')
for i in range(1, self.num_iterations):
self.autocomp.suggest('a')
for i in range(1, self.num_iterations):
self.autocomp.suggest('non revolving')
# Must set the setting back to where it was as it will persist
setattr(auto_settings, 'MATCH_OUT_OF_ORDER_WORDS', False)
setattr(auto_settings, 'MOVE_EXACT_MATCHES_TO_TOP', True)
示例5: test_store_and_remove_all_basic_with_caching
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [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)
示例6: test_facet_match_with_move_exact_matches
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [as 别名]
def test_facet_match_with_move_exact_matches(self):
"""
Exact matching still works with facet suggest
"""
setattr(auto_settings, 'MAX_EXACT_MATCH_WORDS', 10)
temp_autocomp = Autocompleter('faceted_stock')
temp_autocomp.store_all()
facets = [
{
'type': 'or',
'facets': [
{'key': 'sector', 'value': 'Technology'},
{'key': 'industry', 'value': 'Software'}
]
}
]
matches = temp_autocomp.suggest('Ma', facets=facets)
setattr(auto_settings, 'MOVE_EXACT_MATCHES_TO_TOP', True)
matches2 = temp_autocomp.suggest('Ma', facets=facets)
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)
temp_autocomp.remove_all()
示例7: IndicatorAliasedMatchTestCase
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [as 别名]
class IndicatorAliasedMatchTestCase(AutocompleterTestCase):
fixtures = ['indicator_test_data_small.json']
def setUp(self):
self.autocomp = Autocompleter("indicator_aliased")
self.autocomp.store_all()
super(IndicatorAliasedMatchTestCase, self).setUp()
def tearDown(self):
self.autocomp.remove_all()
def test_aliasing(self):
"""
Various permutations of aliased matching work
"""
matches = self.autocomp.suggest('us consumer price index')
self.assertNotEqual(len(matches), 0)
matches = self.autocomp.suggest('united states consumer price index')
self.assertNotEqual(len(matches), 0)
matches = self.autocomp.suggest('us cpi')
self.assertNotEqual(len(matches), 0)
matches = self.autocomp.suggest('united states consumer price index')
self.assertNotEqual(len(matches), 0)
示例8: IndicatorAliasedMatchTestCase
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [as 别名]
class IndicatorAliasedMatchTestCase(AutocompleterTestCase):
fixtures = ['indicator_test_data_small.json']
def setUp(self):
super(IndicatorAliasedMatchTestCase, self).setUp()
self.autocomp = Autocompleter("indicator_aliased")
self.autocomp.store_all()
def tearDown(self):
self.autocomp.remove_all()
def test_basic_aliasing(self):
"""
Various permutations of aliased matching work
"""
matches = self.autocomp.suggest('us consumer price index')
self.assertNotEqual(len(matches), 0)
matches = self.autocomp.suggest('united states consumer price index')
self.assertNotEqual(len(matches), 0)
matches = self.autocomp.suggest('us cpi')
self.assertNotEqual(len(matches), 0)
matches = self.autocomp.suggest('united states consumer price index')
self.assertNotEqual(len(matches), 0)
matches = self.autocomp.suggest('u s a consumer price index')
self.assertNotEqual(len(matches), 0)
def test_alias_list_creation(self):
"""
Alias lists have replacement char variations
"""
provider = registry._providers_by_ac["indicator_aliased"][0]
aliases = provider.get_norm_phrase_aliases()
usa_aliases = aliases['usa']
self.assertTrue('u sa' in usa_aliases)
self.assertTrue('us a' in usa_aliases)
self.assertTrue('u s a' in usa_aliases)
self.assertFalse('usa' in usa_aliases)
def test_multi_term_aliasing(self):
matches = self.autocomp.suggest('us consumer price index')
self.assertNotEqual(len(matches), 0)
matches = self.autocomp.suggest('usa consumer price index')
self.assertNotEqual(len(matches), 0)
matches = self.autocomp.suggest('america consumer price index')
self.assertNotEqual(len(matches), 0)
def test_double_aliasing(self):
"""
Double aliasing does not happen.
California -> CA -> Canada
"""
matches = self.autocomp.suggest('california unemployment')
self.assertEqual(len(matches), 1)
示例9: StockExactMatchTestCase
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [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)
示例10: MultiMatchingTestCase
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [as 别名]
class MultiMatchingTestCase(AutocompleterTestCase):
fixtures = ['stock_test_data_small.json', 'indicator_test_data_small.json']
def setUp(self):
super(MultiMatchingTestCase, self).setUp()
self.autocomp = Autocompleter("mixed")
self.autocomp.store_all()
def tearDown(self):
self.autocomp.remove_all()
def test_basic_match(self):
"""
A single autocompleter can return results from multiple models.
"""
matches = self.autocomp.suggest('Aapl')
self.assertEqual(len(matches['stock']), 1)
matches = self.autocomp.suggest('US Initial Claims')
self.assertEqual(len(matches['ind']), 1)
matches = self.autocomp.suggest('m')
self.assertEqual(len(matches), 3)
matches = self.autocomp.suggest('a')
self.assertEqual(len(matches['stock']), 10)
self.assertEqual(len(matches['ind']), 10)
def test_min_letters_setting(self):
"""
MIN_LETTERS is respected in multi-type search case.
"""
matches = self.autocomp.suggest('a')
self.assertEqual(len(matches['stock']), 10)
self.assertEqual(len(matches['ind']), 10)
setattr(auto_settings, 'MIN_LETTERS', 2)
matches = self.autocomp.suggest('a')
self.assertEqual(matches, {})
setattr(auto_settings, 'MIN_LETTERS', 1)
def test_ac_provider_specific_min_letters_setting(self):
"""
Autocompleter/Provider specific MIN_LETTERS is respected in multi-type search case.
"""
matches = self.autocomp.suggest('a')
self.assertEqual(len(matches['stock']), 10)
self.assertEqual(len(matches['ind']), 10)
registry.set_ac_provider_setting("mixed", IndicatorAutocompleteProvider, 'MIN_LETTERS', 2)
registry.set_ac_provider_setting("mixed", CalcAutocompleteProvider, 'MIN_LETTERS', 2)
matches = self.autocomp.suggest('a')
self.assertEqual(len(matches), 10)
self.assertEqual('ind' not in matches, True)
registry.del_ac_provider_setting("mixed", IndicatorAutocompleteProvider, 'MIN_LETTERS')
registry.del_ac_provider_setting("mixed", CalcAutocompleteProvider, 'MIN_LETTERS')
示例11: test_remove_intermediate_results_suggest
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [as 别名]
def test_remove_intermediate_results_suggest(self):
"""
After suggest call, all intermediate result sets are removed
"""
autocomp = Autocompleter('stock')
autocomp.store_all()
autocomp.suggest('aapl')
keys = self.redis.keys('djac.results.*')
self.assertEqual(len(keys), 0)
示例12: test_exact_matches_not_stored_by_default
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [as 别名]
def test_exact_matches_not_stored_by_default(self):
"""
Exact matches are not stored by default
"""
autocomp = Autocompleter("stock")
autocomp.store_all()
keys = self.redis.keys('djac.test.stock.e.*')
self.assertEqual(len(keys), 0)
self.assertFalse(self.redis.exists('djac.test.stock.es'))
autocomp.remove_all()
示例13: DictProviderMatchingTestCase
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [as 别名]
class DictProviderMatchingTestCase(AutocompleterTestCase):
def setUp(self):
super(DictProviderMatchingTestCase, self).setUp()
self.autocomp = Autocompleter("metric")
self.autocomp.store_all()
def tearDown(self):
self.autocomp.remove_all()
def test_basic_match(self):
matches = self.autocomp.suggest('m')
self.assertEqual(len(matches), 1)
示例14: test_store_and_remove_all_basic
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [as 别名]
def test_store_and_remove_all_basic(self):
"""
Storing and removing items all at once works for a dictionary obj autocompleter.
"""
autocomp = Autocompleter("stock")
autocomp.store_all()
keys = self.redis.hkeys('djac.test.stock')
self.assertEqual(len(keys), 104)
autocomp.remove_all()
keys = self.redis.keys('djac.test.stock*')
self.assertEqual(len(keys), 0)
示例15: test_store_all_facet_data
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import store_all [as 别名]
def test_store_all_facet_data(self):
"""
Calling store_all stores all facet data
"""
autocomp = Autocompleter("faceted_stock")
autocomp.store_all()
facet_set_name = base.FACET_SET_BASE_NAME % ('faceted_stock', 'sector', 'Technology',)
set_length = self.redis.zcard(facet_set_name)
self.assertEqual(set_length, 12)
facet_map_name = base.FACET_MAP_BASE_NAME % ('faceted_stock',)
keys = self.redis.hkeys(facet_map_name)
self.assertEqual(len(keys), 104)