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


Python autocompleter.Autocompleter类代码示例

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


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

示例1: test_hashing_order

    def test_hashing_order(self):
        """
        Facets with identical key/values in different order should still have same hash
        """
        facet_1 = [
            {
                'type': 'or',
                'facets': [
                    {'key': 'sector', 'value': 'Technology'},
                    {'key': 'industry', 'value': 'Software'}
                ]
            }
        ]

        facet_2 = [
            {
                'type': 'or',
                'facets': [
                    {'key': 'industry', 'value': 'Software'},
                    {'key': 'sector', 'value': 'Technology'}
                ]
            }
        ]

        facet_1_hash = Autocompleter.hash_facets(facet_1)
        facet_2_hash = Autocompleter.hash_facets(facet_2)
        self.assertEqual(facet_1_hash, facet_2_hash)
开发者ID:ycharts,项目名称:django-autocompleter,代码行数:27,代码来源:test_utils.py

示例2: test_signal_based_update

    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,代码行数:28,代码来源:test_storage.py

示例3: MixedFacetProvidersMatchingTestCase

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,代码行数:33,代码来源:test_matching.py

示例4: get

    def get(self):
        # logging.info("request start \n{}".format(time.clock() * 1000 % 1000))
        self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
        query = self.request.get('q')
        logging.info(u"Autocomplete search for '{}'".format(query))
        autocompleter = Autocompleter()
        # logging.info("before autocompleter.get_results \n{}".format(time.clock() * 1000 % 1000))
        results = autocompleter.get_results(query)
        # logging.info("after autocompleter.get_results \n{}".format(time.clock() * 1000 % 1000))
        json_results = []
        for book in results:
            if book is None:
                logging.warning(u"Autocompleter result for '{}' returned None."
                                .format(query))
                continue
            assert isinstance(book, BookRecord)
            suggestion_map = {'author': book.author, 'title': book.title,
                              'year': book.year, 'count': book.count,
                              'item_ids': book.key.string_id()}
            json_results.append(suggestion_map)

        json_object = {
            'query': query,
            'version': AutocompleteJson.CURRENT_VERSION,
            'status': 'completed',
            'suggestions': json_results
        }
        # logging.info("before json.dump \n{}".format(time.clock() * 1000 % 1000))
        self.response.write(json.dumps(json_object, indent=2))
开发者ID:gdg-garage,项目名称:knihovna-db,代码行数:29,代码来源:main.py

示例5: test_hash_identical_values_different_facet_type

    def test_hash_identical_values_different_facet_type(self):
        """
        Facets with same key/values but different facet type in different order shouldn't have same hash
        """
        facet_1 = [
            {
                'type': 'and',
                'facets': [
                    {'key': 'sector', 'value': 'Technology'},
                    {'key': 'industry', 'value': 'Software'}
                ]
            }
        ]

        facet_2 = [
            {
                'type': 'or',
                'facets': [
                    {'key': 'industry', 'value': 'Software'},
                    {'key': 'sector', 'value': 'Technology'}
                ]
            }
        ]

        facet_1_hash = Autocompleter.hash_facets(facet_1)
        facet_2_hash = Autocompleter.hash_facets(facet_2)
        self.assertNotEqual(facet_1_hash, facet_2_hash)
开发者ID:ycharts,项目名称:django-autocompleter,代码行数:27,代码来源:test_utils.py

示例6: test_rounding_works_correctly

 def test_rounding_works_correctly(self):
     """
     Rounding works correctly
     """
     self.assertEqual(1, Autocompleter.normalize_rounding(.51))
     self.assertEqual(0, Autocompleter.normalize_rounding(.49))
     self.assertEqual(-1, Autocompleter.normalize_rounding(-.51))
     self.assertEqual(0, Autocompleter.normalize_rounding(-.49))
开发者ID:ycharts,项目名称:django-autocompleter,代码行数:8,代码来源:test_utils.py

示例7: test_rounding_half

 def test_rounding_half(self):
     """
     Rounding a number that ends in .5 should produce a number with a greater absolute value
     """
     self.assertEqual(1, Autocompleter.normalize_rounding(.5))
     self.assertEqual(2, Autocompleter.normalize_rounding(1.5))
     self.assertEqual(-1, Autocompleter.normalize_rounding(-.5))
     self.assertEqual(-2, Autocompleter.normalize_rounding(-1.5))
开发者ID:ycharts,项目名称:django-autocompleter,代码行数:8,代码来源:test_utils.py

示例8: suggest

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,代码行数:9,代码来源:views.py

示例9: test_remove_intermediate_results_suggest

    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,代码行数:10,代码来源:test_storage.py

示例10: test_exact_matches_not_stored_by_default

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

示例11: DictProviderMatchingTestCase

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

示例12: test_store_and_remove_all_basic

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

示例13: test_store_all_facet_data

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

示例14: test_facet_identity_hash

 def test_facet_identity_hash(self):
     """
     Hashing a facet should equal the hash of an earlier call
     """
     facets = [
         {
             'type': 'or',
             'facets': [{'key': 'sector', 'value': 'Technology'}]
         }
     ]
     first_hash = Autocompleter.hash_facets(facets)
     second_hash = Autocompleter.hash_facets(facets)
     self.assertEqual(first_hash, second_hash)
开发者ID:ycharts,项目名称:django-autocompleter,代码行数:13,代码来源:test_utils.py

示例15: test_remove_intermediate_results_exact_suggest

    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,代码行数:13,代码来源:test_storage.py


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