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


Python Autocompleter.suggest方法代码示例

本文整理汇总了Python中autocompleter.Autocompleter.suggest方法的典型用法代码示例。如果您正苦于以下问题:Python Autocompleter.suggest方法的具体用法?Python Autocompleter.suggest怎么用?Python Autocompleter.suggest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在autocompleter.Autocompleter的用法示例。


在下文中一共展示了Autocompleter.suggest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_facet_match_with_move_exact_matches

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import suggest [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()
开发者ID:ycharts,项目名称:django-autocompleter,代码行数:28,代码来源:test_matching.py

示例2: test_dict_store_and_remove_all_basic_with_caching

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import 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

示例3: IndicatorAliasedMatchTestCase

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import suggest [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)
开发者ID:pombredanne,项目名称:django-autocompleter,代码行数:28,代码来源:test_matching.py

示例4: MultiExactMatchTestCase

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import 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

示例5: test_signal_based_update

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import suggest [as 别名]
    def test_signal_based_update(self):
        """
        Turning on signals will automatically update objects in the autocompleter
        """
        signal_registry.register(Stock)

        aapl = Stock(symbol='AAPL', name='Apple', market_cap=50)
        aapl.save()

        autocomp = Autocompleter("stock")
        matches = autocomp.suggest('aapl')

        self.assertEqual(len(matches), 1)

        aapl.symbol = 'XYZ'
        aapl.name = 'XYZ & Co.'
        aapl.save()

        matches = autocomp.suggest('aapl')
        self.assertEqual(len(matches), 0)
        matches = autocomp.suggest('xyz')
        self.assertEqual(len(matches), 1)

        aapl.delete()
        keys = self.redis.keys('djac.stock*')
        self.assertEqual(len(keys), 0)

        signal_registry.unregister(Stock)
开发者ID:pombredanne,项目名称:django-autocompleter,代码行数:30,代码来源:test_storage.py

示例6: MixedFacetProvidersMatchingTestCase

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import suggest [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')
开发者ID:ycharts,项目名称:django-autocompleter,代码行数:35,代码来源:test_matching.py

示例7: test_store_and_remove_all_basic_with_caching

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import 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

示例8: StockExactMatchTestCase

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import 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

示例9: test_remove_intermediate_results_suggest

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import suggest [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)
开发者ID:ycharts,项目名称:django-autocompleter,代码行数:12,代码来源:test_storage.py

示例10: IndicatorAliasedMatchTestCase

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import suggest [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)
开发者ID:KFoxder,项目名称:django-autocompleter,代码行数:61,代码来源:test_aliasing.py

示例11: MultiMatchingPerfTestCase

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import suggest [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)
开发者ID:pombredanne,项目名称:django-autocompleter,代码行数:35,代码来源:test_perf.py

示例12: test_selective_add_and_remove

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import suggest [as 别名]
    def test_selective_add_and_remove(self):
        """
        We can exclude certain objects from the autocompleter selectively.
        """
        autocomp = Autocompleter("indicator")
        autocomp.store_all()
        matches = autocomp.suggest('us unemployment rate')
        self.assertEqual(len(matches), 1)
        autocomp.remove_all()

        autocomp = Autocompleter("indicator_selective")
        autocomp.store_all()
        matches = autocomp.suggest('us unemployment rate')
        self.assertEqual(len(matches), 0)
        autocomp.remove_all()
开发者ID:jb076,项目名称:django-autocompleter,代码行数:17,代码来源:test_storage.py

示例13: MultiMatchingTestCase

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import suggest [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')
开发者ID:jb076,项目名称:django-autocompleter,代码行数:60,代码来源:test_matching.py

示例14: get

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import suggest [as 别名]
    def get(self, request, name):
        if settings.SUGGEST_PARAMETER_NAME in request.GET:
            term = request.GET[settings.SUGGEST_PARAMETER_NAME]
            ac = Autocompleter(name)
            if settings.FACET_PARAMETER_NAME in request.GET:
                facets = request.GET[settings.FACET_PARAMETER_NAME]
                facets = json.loads(facets)
                if not self.validate_facets(facets):
                    return HttpResponseBadRequest('Malformed facet parameter.')
                results = ac.suggest(term, facets=facets)
            else:
                results = ac.suggest(term)

            json_response = json.dumps(results)
            return HttpResponse(json_response, content_type='application/json')
        return HttpResponseServerError('Search parameter not found.')
开发者ID:ycharts,项目名称:django-autocompleter,代码行数:18,代码来源:views.py

示例15: suggest

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import suggest [as 别名]
def suggest(request, name):
    if settings.SUGGEST_PARAMETER_NAME in request.GET:
        term = request.GET[settings.SUGGEST_PARAMETER_NAME]
        ac = Autocompleter(name)
        results = ac.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


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