Exemple #1
0
 def handle(self, *args, **options):
     index_name = options.get('index_name')
     delete = options.get('delete', False)
     if index_name:
         create_search_index(index_name, delete_if_exists=delete)
         self.stdout.write(
             self.style.SUCCESS(
                 "Created search index '{}'".format(index_name)))
     else:
         self.stdout.write("Creating search indices from settings")
         SEARCH = getattr(settings, 'SEARCH', None)
         if SEARCH and isinstance(SEARCH, dict):
             for name, config in SEARCH.items():
                 index_name = config.get('index')
                 if index_name:
                     doc_types = config.get('doc_types', None)
                     create_search_index(index_name,
                                         doc_types=doc_types,
                                         delete_if_exists=delete)
                     self.stdout.write(
                         self.style.SUCCESS(
                             "Created search index '{}'".format(
                                 index_name)))
                 else:
                     self.stdout.write(
                         self.style.WARNING(
                             "No index specified for '{}'".format(name)))
         else:
             raise CommandError('SEARCH not set in django settings')
Exemple #2
0
    def test_create_search_index_only(self):
        index = create_search_index('test_create')

        self.assertIsNotNone(index)

        index_dict = index.to_dict()
        self.assertNotIn('mappings', index_dict)

        index.delete()
        self.assertFalse(index.exists())
    def test_create_search_index_only(self):
        index = create_search_index('test_create')

        self.assertIsNotNone(index)

        index_dict = index.to_dict()
        self.assertNotIn('mappings', index_dict)

        index.delete()
        self.assertFalse(index.exists())
 def handle(self, *args, **options):
     index_name = options.get('index_name')
     delete = options.get('delete', False)
     if index_name:
         create_search_index(index_name, delete_if_exists=delete)
         self.stdout.write(self.style.SUCCESS("Created search index '{}'".format(index_name)))
     else:
         self.stdout.write("Creating search indices from settings")
         SEARCH = getattr(settings, 'SEARCH', None)
         if SEARCH and isinstance(SEARCH, dict):
             for name, config in SEARCH.items():
                 index_name = config.get('index')
                 if index_name:
                     doc_types = config.get('doc_types', None)
                     create_search_index(index_name, doc_types=doc_types, delete_if_exists=delete)
                     self.stdout.write(self.style.SUCCESS("Created search index '{}'".format(index_name)))
                 else:
                     self.stdout.write(self.style.WARNING("No index specified for '{}'".format(name)))
         else:
             raise CommandError('SEARCH not set in django settings')
    def test_create_search_index_with_doctypes(self):
        index = create_search_index('foo', doc_types=('search.tests.mocks.MockDocOne', 'search.tests.mocks.MockDocTwo'))

        self.assertIsNotNone(index)

        index_dict = index.to_dict()
        self.assertIn('mappings', index_dict)

        mappings = index_dict.get('mappings')
        self.assertEqual(len(mappings.keys()), 2)
        self.assertIn('mock_doc_one', mappings)
        self.assertIn('mock_doc_two', mappings)

        index.delete()
        self.assertFalse(index.exists())
Exemple #6
0
    def test_create_search_index_with_doctypes(self):
        index = create_search_index(
            'foo',
            doc_types=('search.tests.mocks.MockDocOne',
                       'search.tests.mocks.MockDocTwo'))

        self.assertIsNotNone(index)

        index_dict = index.to_dict()
        self.assertIn('mappings', index_dict)

        mappings = index_dict.get('mappings')
        self.assertEqual(len(mappings.keys()), 2)
        self.assertIn('mock_doc_one', mappings)
        self.assertIn('mock_doc_two', mappings)

        index.delete()
        self.assertFalse(index.exists())