Exemple #1
0
 def index_datasets(self):
     if self.options['datasets']:
         if self.options['debug']: print "[Iniciando datasets]"
         for dataset in Dataset.objects.filter(
                 last_published_revision__status=StatusChoices.PUBLISHED):
             try:
                 datasetrevision = dataset.last_published_revision
                 search_dao = DatasetSearchDAOFactory().create(
                     datasetrevision)
                 search_dao.add()
             except:
                 print "[ERROR dt] Fallo al indexar Dataset. ID: {} Account: {}".format(
                     dataset.id, dataset.user.account.name)
Exemple #2
0
def reindex_category_resources(category_id, language):
    """ reindex all resurce using given category """
    logger = logging.getLogger(__name__)

    if settings.DEBUG:
        logger.info('Reindexing category resources %d, %s' %
                    (category_id, language))

    datasets = Dataset.objects.filter(
        last_published_revision__category_id=category_id,
        last_published_revision__status=StatusChoices.PUBLISHED)
    datastreams = DataStream.objects.filter(
        last_published_revision__category_id=category_id,
        last_published_revision__status=StatusChoices.PUBLISHED)

    for dataset in datasets:
        datasetrevision = dataset.last_published_revision
        search_dao = DatasetSearchDAOFactory().create(datasetrevision)
        search_dao.add()
    for datastream in datastreams:
        datastreamrevision = datastream.last_published_revision
        search_dao = DatastreamSearchDAOFactory().create(datastreamrevision)
        search_dao.add()
Exemple #3
0
    def handle(self, *args, **options):

        # index resources
        if options['reindex']:

            # destruye el index
            ElasticsearchIndex().flush_index()
            es = ElasticsearchIndex()

            for dataset in Dataset.objects.filter(last_published_revision__status=StatusChoices.PUBLISHED):
                datasetrevision=dataset.last_published_revision
                search_dao = DatasetSearchDAOFactory().create(datasetrevision)
                search_dao.add()

            for vz in Visualization.objects.filter(last_published_revision__status=StatusChoices.PUBLISHED):
                vz_revision=vz.last_published_revision
                search_dao = VisualizationSearchDAOFactory().create(vz_revision)
                search_dao.add()

                h = VisualizationHitsDAO(vz_revision)

                doc={
                    'docid': "VZ::%s" % vz.guid,
                    "type": "vz",
                    "doc": {
                        "fields": {
                            "hits": h.count(),
                            "web_hits": h.count(channel_type=0),
                            "api_hits": h.count(channel_type=1)
                        }
                    }
                }
                try:
                    es.update(doc)
                except:
                    pass

            # TODO Hay que usar el metodo query del DAO
            for datastream in DataStream.objects.filter(last_published_revision__status=StatusChoices.PUBLISHED):
                datastreamrevision=datastream.last_published_revision
                datastream_rev = DataStreamDBDAO().get(
                    datastreamrevision.user.language,
                    datastream_revision_id=datastreamrevision.id,
                    published=True
                )
                search_dao = DatastreamSearchDAOFactory().create(datastreamrevision)
                search_dao.add()

                h = DatastreamHitsDAO(datastream_rev)

                doc={
                    'docid': "DS::%s" % datastreamrevision.datastream.guid,
                    "type": "ds",
                    "doc": {
                        "fields": {
                            "hits": h.count(),
                            "web_hits": h.count(channel_type=0),
                            "api_hits": h.count(channel_type=1)
                        }
                    }
                }
                try:
                    es.update(doc)
                except:
                    pass

        for plugin in DatalPluginPoint.get_active_with_att('reindex'):
            plugin.reindex(es)