コード例 #1
0
def append_updated_record_to_queue(sender, json, record, index, doc_type):
    """Append record after an update to the queue.

    The method receives a record on before_record_index signal and
    decides if the updates made are essential to append the record
    to the queue of records to be processed by Beard.
    """
    # FIXME: Use a dedicated method when #1355 will be resolved.
    if "hep.json" in json['$schema']:
        from invenio_search import current_search_client as es
        from elasticsearch.exceptions import NotFoundError

        try:
            before_json = es.get_source(index=index,
                                        id=record.id,
                                        doc_type=doc_type)
        except (ValueError, NotFoundError):
            # The record in not available in the Elasticsearch instance.
            # This will be caught by append_new_record_to_queue method.
            return

        if _needs_beard_reprocessing(before_json['authors'], json['authors']):
            record_arguments = {'record_id': record.id}

            beard_record = DisambiguationRecord(**record_arguments)
            beard_record.save()
コード例 #2
0
def get_es_record_by_uuid(uuid):
    pid = PersistentIdentifier.query.filter_by(object_uuid=uuid).one()
    search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][pid.pid_type]

    return es.get_source(index=search_conf['search_index'],
                         id=str(uuid),
                         doc_type=search_conf['search_type'])
コード例 #3
0
ファイル: receivers.py プロジェクト: bittirousku/inspire-next
def append_updated_record_to_queue(sender, json, record, index, doc_type):
    """Append record after an update to the queue.

    The method receives a record on before_record_index signal and
    decides if the updates made are essential to append the record
    to the queue of records to be processed by Beard.
    """
    # FIXME: Use a dedicated method when #1355 will be resolved.
    if "hep.json" in json['$schema']:
        from invenio_search import current_search_client as es
        from elasticsearch.exceptions import NotFoundError

        try:
            before_json = es.get_source(
                index=index, id=record.id, doc_type=doc_type)
        except (ValueError, NotFoundError):
            # The record in not available in the Elasticsearch instance.
            # This will be caught by append_new_record_to_queue method.
            return

        if _needs_beard_reprocessing(before_json['authors'], json['authors']):
            record_arguments = {'record_id': record.id}

            beard_record = DisambiguationRecord(**record_arguments)
            beard_record.save()
コード例 #4
0
def get_es_record(record_type, recid):
    pid = PersistentIdentifier.get(record_type, recid)
    search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][record_type]

    return es.get_source(index=search_conf['search_index'],
                         id=str(pid.object_uuid),
                         doc_type=search_conf['search_type'])
コード例 #5
0
def get_es_record_by_uuid(uuid):
    pid = PersistentIdentifier.query.filter_by(object_uuid=uuid).one()
    search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][pid.pid_type]

    return es.get_source(
        index=search_conf['search_index'],
        id=str(uuid),
        doc_type=search_conf['search_type'])
コード例 #6
0
def get_es_record(record_type, recid):
    pid = PersistentIdentifier.get(record_type, recid)
    search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][record_type]

    return es.get_source(
        index=search_conf['search_index'],
        id=str(pid.object_uuid),
        doc_type=search_conf['search_type'])
コード例 #7
0
 def get_source(self, uuid, **kwargs):
     """Get source from a given uuid.
     This function mimics the behaviour from the low level ES library
     get_source function.
     :param uuid: uuid of document to be retrieved.
     :type uuid: UUID
     :returns: dict
     """
     return es.get_source(index=self.alias, id=uuid, **kwargs)
コード例 #8
0
    def get_source(self, uuid, **kwargs):
        """Get source from a given uuid.

        This function mimics the behaviour from the low level ES library
        get_source function.

        :param uuid: uuid of document to be retrieved.
        :type uuid: UUID
        :returns: dict
        """
        return current_search_client.get_source(index=self.Meta.index,
                                                doc_type=self.Meta.doc_types,
                                                id=uuid,
                                                **kwargs)
コード例 #9
0
ファイル: api.py プロジェクト: bittirousku/inspire-next
    def get_source(self, uuid, **kwargs):
        """Get source from a given uuid.

        This function mimics the behaviour from the low level ES library
        get_source function.

        :param uuid: uuid of document to be retrieved.
        :type uuid: UUID
        :returns: dict
        """
        return current_search_client.get_source(
            index=self.Meta.index,
            doc_type=self.Meta.doc_types,
            id=uuid,
            **kwargs
        )
コード例 #10
0
ファイル: views.py プロジェクト: liamkirsh/inspire-next
def ajax_citations():
    """Handler for datatables citations view"""

    recid = request.args.get('recid', '')
    collection = request.args.get('collection', '')

    pid = PersistentIdentifier.get(collection, recid)

    record = current_search_client.get_source(index='records-hep',
                                              id=pid.object_uuid,
                                              doc_type='hep',
                                              ignore=404)

    return jsonify(
        {
            "data": Citation(record).citations()
        }
    )
コード例 #11
0
ファイル: views.py プロジェクト: liamkirsh/inspire-next
def ajax_institutions_experiments():
    """Datatable handler to get experiments in an institution."""
    recid = request.args.get('recid', '')

    pid = PersistentIdentifier.get('institutions', recid)

    record = current_search_client.get_source(index='records-institutions',
                                              id=pid.object_uuid,
                                              doc_type='institutions',
                                              ignore=404)
    try:
        icn = record.get('ICN', [])[0]
    except KeyError:
        icn = ''

    hits = get_institution_experiments_from_es(icn)
    return jsonify(
        {
            "data": get_institution_experiments_datatables_rows(hits),
            "total": hits.total
        }
    )
コード例 #12
0
ファイル: search.py プロジェクト: michamos/inspire-next
def _get_record(record_id, source):
    """Make a call to the Elasticsearch instance with known record_id.

    :param record_id:
        An identification (UUID) of the given record.

        Example:
            record_id = "a5afb151-8f75-4e91-8dc1-05e7e8e8c0b8"

    :param source:
        A list of fields to be extracted from the Elasticsearch response.

        Example:
            source = ["collaboration", "author.full_name"]
    """
    elasticsearch_index = current_app.config.get('DISAMBIGUATION_RECORD_INDEX')
    elasticsearch_type = current_app.config.get('DISAMBIGUATION_RECORD_DOCTYPE')

    return es.get_source(
        index=elasticsearch_index,
        id=str(record_id),
        doc_type=elasticsearch_type,
        _source=source)
コード例 #13
0
ファイル: search.py プロジェクト: fschwenn/inspire-next
def _get_record(record_id, source):
    """Make a call to the Elasticsearch instance with known record_id.

    :param record_id:
        An identification (UUID) of the given record.

        Example:
            record_id = "a5afb151-8f75-4e91-8dc1-05e7e8e8c0b8"

    :param source:
        A list of fields to be extracted from the Elasticsearch response.

        Example:
            source = ["collaboration", "author.full_name"]
    """
    elasticsearch_index = current_app.config.get('DISAMBIGUATION_RECORD_INDEX')
    elasticsearch_type = current_app.config.get('DISAMBIGUATION_RECORD_DOCTYPE')

    return es.get_source(
        index=elasticsearch_index,
        id=str(record_id),
        doc_type=elasticsearch_type,
        _source=source)
コード例 #14
0
ファイル: citations.py プロジェクト: kaplun/inspire-next
    def citations(self):
        """Return citation export for single record."""

        out = []
        row = []

        # Get citations
        es_query = IQ('refersto:' + self.record['control_number'])
        record_citations = es.search(
            index='records-hep',
            doc_type='hep',
            body={"query": es_query.to_dict()},
            size=10,
            _source=[
                'control_number',
                'citation_count',
                'titles',
                'earliest_date'
            ]
        )['hits']['hits']

        for citation in record_citations:

            citation_from_es = es.get_source(index='records-hep',
                                             id=citation['_id'],
                                             doc_type='hep',
                                             ignore=404)

            row.append(render_template_to_string(
                "inspirehep_theme/citations.html",
                record=citation_from_es))
            row.append(citation.get('citation_count', ''))
            out.append(row)
            row = []

        return out