当前位置: 首页>>代码示例>>Python>>正文


Python Autocompleter.exact_suggest方法代码示例

本文整理汇总了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)
开发者ID:jb076,项目名称:django-autocompleter,代码行数:30,代码来源:test_storage.py

示例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)
开发者ID:pombredanne,项目名称:django-autocompleter,代码行数:29,代码来源:test_storage.py

示例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)
开发者ID:jb076,项目名称:django-autocompleter,代码行数:36,代码来源:test_exact.py

示例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)
开发者ID:ycharts,项目名称:django-autocompleter,代码行数:60,代码来源:test_exact.py

示例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)
开发者ID:ycharts,项目名称:django-autocompleter,代码行数:15,代码来源:test_storage.py

示例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.")
开发者ID:KFoxder,项目名称:django-autocompleter,代码行数:11,代码来源:views.py

示例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)
开发者ID:jb076,项目名称:django-autocompleter,代码行数:22,代码来源:test_exact.py

示例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))
开发者ID:ycharts,项目名称:django-autocompleter,代码行数:39,代码来源:test_views.py

示例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)
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:django-autocompleter,代码行数:103,代码来源:test_matching.py


注:本文中的autocompleter.Autocompleter.exact_suggest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。