Esempio n. 1
0
 def _get_doc_types(self):
     # Check if we are filtering by a doc_type (e.g., apps, sites).
     # Default to all content types.
     doc_type = self.request.GET.get('doc_type', 'all')
     app_doc = WebappIndexer.get_mapping_type_name()
     site_doc = WebsiteIndexer.get_mapping_type_name()
     if doc_type == 'webapp':
         return [app_doc]
     elif doc_type == 'website':
         return [site_doc]
     return [app_doc, site_doc]
Esempio n. 2
0
 def _get_doc_types(self):
     # Check if we are filtering by a doc_type (e.g., apps, sites).
     # Default to all content types.
     doc_type = self.request.GET.get('doc_type', 'all')
     app_doc = WebappIndexer.get_mapping_type_name()
     site_doc = WebsiteIndexer.get_mapping_type_name()
     if doc_type == 'webapp':
         return [app_doc]
     elif doc_type == 'website':
         return [site_doc]
     return [app_doc, site_doc]
Esempio n. 3
0
 def mget_apps(self, app_ids):
     """
     Takes a list of app_ids. Does an ES mget.
     Returns an app_map for serializer context.
     """
     app_map = {}
     es = WebappIndexer.get_es()
     apps = es.mget(body={'ids': app_ids}, index=WebappIndexer.get_index(),
                    doc_type=WebappIndexer.get_mapping_type_name())
     for app in apps['docs']:
         # Store the apps to attach to feed elements later.
         app = app['_source']
         app_map[app['id']] = app
     return app_map
Esempio n. 4
0
    def handle(self, *args, **kwargs):
        index = WebappIndexer.get_index()
        doctype = WebappIndexer.get_mapping_type_name()
        es = WebappIndexer.get_es()

        app_ids = Webapp.objects.values_list('id', flat=True)

        missing_ids = []

        for app_id in app_ids:
            try:
                es.get(index, app_id, doctype, fields='id')
            except elasticsearch.NotFoundError:
                # App doesn't exist in our index, add it to `missing_ids`.
                missing_ids.append(app_id)

        if missing_ids:
            sys.stdout.write('Adding %s doc(s) to the index.'
                             % len(missing_ids))
            WebappIndexer().run_indexing(missing_ids, es)
        else:
            sys.stdout.write('No docs missing from index.')
Esempio n. 5
0
    def handle(self, *args, **kwargs):
        index = WebappIndexer.get_index()
        doctype = WebappIndexer.get_mapping_type_name()
        es = WebappIndexer.get_es()

        app_ids = Webapp.objects.values_list('id', flat=True)

        missing_ids = []

        for app_id in app_ids:
            try:
                es.get(index, app_id, doctype, fields='id')
            except elasticsearch.NotFoundError:
                # App doesn't exist in our index, add it to `missing_ids`.
                missing_ids.append(app_id)

        if missing_ids:
            sys.stdout.write('Adding %s doc(s) to the index.' %
                             len(missing_ids))
            WebappIndexer().run_indexing(missing_ids, es)
        else:
            sys.stdout.write('No docs missing from index.')
Esempio n. 6
0
 def test_mapping_type_name(self):
     eq_(WebappIndexer.get_mapping_type_name(), 'webapp')
Esempio n. 7
0
 def test_mapping_type_name(self):
     eq_(WebappIndexer.get_mapping_type_name(), 'webapp')
Esempio n. 8
0
 def get_queryset(self):
     return Search(
         using=BaseIndexer.get_es(),
         index=[WebappIndexer.get_index(), WebsiteIndexer.get_index()],
         doc_type=[WebappIndexer.get_mapping_type_name(),
                   WebsiteIndexer.get_mapping_type_name()])