コード例 #1
0
    def mget(self, uuids, **kwargs):
        """Get source from a list of uuids.

        :param uuids: uuids of documents to be retrieved.
        :type uuids: list of strings representing uuids
        :returns: list of JSON documents
        """
        documents = current_search_client.mget(index=self.Meta.index,
                                               doc_type=self.Meta.doc_types,
                                               body={'ids': uuids},
                                               **kwargs)

        return [document['_source'] for document in documents['docs']]
コード例 #2
0
ファイル: references.py プロジェクト: nikpap/inspire-next
    def references(self):
        """Reference export for single record in datatables format.

        :returns: list
            List of lists where every item represents a datatables row.
            A row consists of [reference_number, reference, num_citations]
        """

        out = []
        references = self.record.get('references')
        if references:
            refs_to_get_from_es = [
                ref['recid'] for ref in references if ref.get('recid')
            ]
            records_from_es = []

            if refs_to_get_from_es:
                records_from_es = es.mget(body={
                    "ids": refs_to_get_from_es
                }, index="records-hep")['docs']

            refs_from_es = {
                ref['_id']: ref['_source'] for ref in records_from_es if '_source' in ref
            }
            for reference in references:
                row = []
                recid = reference.get('recid')
                ref_record = refs_from_es.get(str(recid)) if recid else None

                if recid and ref_record:
                    recid = reference['recid']
                    ref_record = Record(refs_from_es.get(str(recid)))
                    if ref_record:
                        row.append(render_template_to_string(
                            "inspirehep_theme/references.html",
                            record=ref_record,
                            reference=reference
                        ))
                        row.append(ref_record.get('citation_count', ''))
                        out.append(row)
                else:

                    row.append(render_template_to_string(
                        "inspirehep_theme/references.html",
                        reference=reference))
                    row.append('')
                    out.append(row)

        return out
コード例 #3
0
ファイル: api.py プロジェクト: bittirousku/inspire-next
    def mget(self, uuids, **kwargs):
        """Get source from a list of uuids.

        :param uuids: uuids of documents to be retrieved.
        :type uuids: list of strings representing uuids
        :returns: list of JSON documents
        """
        documents = current_search_client.mget(
            index=self.Meta.index,
            doc_type=self.Meta.doc_types,
            body={'ids': uuids},
            **kwargs
        )

        return [document['_source'] for document in documents['docs']]
コード例 #4
0
ファイル: api.py プロジェクト: tsgit/inspirehep
    def mget(self, uuids, **kwargs):
        """Get source from a list of uuids.
        :param uuids: uuids of documents to be retrieved.
        :type uuids: list of strings representing uuids
        :returns: list of JSON documents
        """
        results = []

        try:
            documents = es.mget(index=self.alias,
                                doc_type=self.Meta.doc_types,
                                body={"ids": uuids},
                                **kwargs)
            results = [document["_source"] for document in documents["docs"]]
        except RequestError:
            pass

        return results
コード例 #5
0
ファイル: api.py プロジェクト: rikirenz/inspire-next
    def mget(self, uuids, **kwargs):
        """Get source from a list of uuids.

        :param uuids: uuids of documents to be retrieved.
        :type uuids: list of strings representing uuids
        :returns: list of JSON documents
        """
        results = []

        try:
            documents = es.mget(index=self.Meta.index,
                                doc_type=self.Meta.doc_types,
                                body={'ids': uuids},
                                **kwargs)
            results = [document['_source'] for document in documents['docs']]
        except RequestError as e:
            logger.exception(e)

        return results
コード例 #6
0
ファイル: api.py プロジェクト: harunurhan/inspire-next
    def mget(self, uuids, **kwargs):
        """Get source from a list of uuids.

        :param uuids: uuids of documents to be retrieved.
        :type uuids: list of strings representing uuids
        :returns: list of JSON documents
        """
        results = []

        try:
            documents = es.mget(
                index=self.Meta.index,
                doc_type=self.Meta.doc_types,
                body={'ids': uuids},
                **kwargs
            )
            results = [document['_source'] for document in documents['docs']]
        except RequestError:
            pass

        return results
コード例 #7
0
    def serialize(self, pid, record, links_factory=None):
        """
        Serialize a single impact graph from a record.

        :param pid: Persistent identifier instance.
        :param record: Record instance.
        :param links_factory: Factory function for the link generation,
                              which are added to the response.
        """
        out = {}

        # Add information about current record
        out['inspire_id'] = record['control_number']
        out['title'] = get_title(record)
        out['year'] = record['earliest_date'].split('-')[0]

        # Get citations
        citations = []

        es_query = Query('refersto:' + record['control_number'])
        es_query.body.update(
            {
                'size': 9999
            }
        )
        record_citations = current_search_client.search(
            index='records-hep',
            doc_type='hep',
            body=es_query.body,
            _source=[
                'control_number',
                'citation_count',
                'titles',
                'earliest_date'
            ]
        )['hits']['hits']
        for citation in record_citations:
            citation = citation['_source']
            citations.append({
                "inspire_id": citation['control_number'],
                "citation_count": citation.get('citation_count', 0),
                "title": get_title(citation),
                "year": citation['earliest_date'].split('-')[0]
            })

        out['citations'] = citations

        # Get references
        record_references = record.get('references', [])
        references = []

        reference_recids = [
            ref['recid'] for ref in record_references if ref.get('recid')
        ]

        if reference_recids:
            mget_body = {
                "ids": reference_recids
            }

            record_references = current_search_client.mget(
                index='records-hep',
                doc_type='hep',
                body=mget_body,
                _source=[
                    'control_number',
                    'citation_count',
                    'titles',
                    'earliest_date'
                ]
            )

            for reference in record_references["docs"]:
                ref_info = reference["_source"]

                references.append({
                    "inspire_id": ref_info['control_number'],
                    "citation_count": ref_info.get('citation_count', 0),
                    "title": get_title(ref_info),
                    "year": ref_info['earliest_date'].split('-')[0]
                })

        out['references'] = references

        return json.dumps(out)
コード例 #8
0
    def serialize(self, pid, record, links_factory=None):
        """
        Serialize a single impact graph from a record.

        :param pid: Persistent identifier instance.
        :param record: Record instance.
        :param links_factory: Factory function for the link generation,
                              which are added to the response.
        """
        out = {}

        # Add information about current record
        out['inspire_id'] = record['control_number']
        out['title'] = get_title(record)
        out['year'] = record['earliest_date'].split('-')[0]

        # Get citations
        citations = []

        es_query = Query('refersto:' + record['control_number'])
        es_query.body.update({'size': 9999})
        record_citations = current_search_client.search(index='records-hep',
                                                        doc_type='hep',
                                                        body=es_query.body,
                                                        _source=[
                                                            'control_number',
                                                            'citation_count',
                                                            'titles',
                                                            'earliest_date'
                                                        ])['hits']['hits']
        for citation in record_citations:
            citation = citation['_source']
            citations.append({
                "inspire_id":
                citation['control_number'],
                "citation_count":
                citation.get('citation_count', 0),
                "title":
                get_title(citation),
                "year":
                citation['earliest_date'].split('-')[0]
            })

        out['citations'] = citations

        # Get references
        record_references = record.get('references', [])
        references = []

        reference_recids = [
            ref['recid'] for ref in record_references if ref.get('recid')
        ]

        if reference_recids:
            mget_body = {"ids": reference_recids}

            record_references = current_search_client.mget(
                index='records-hep',
                doc_type='hep',
                body=mget_body,
                _source=[
                    'control_number', 'citation_count', 'titles',
                    'earliest_date'
                ])

            for reference in record_references["docs"]:
                ref_info = reference["_source"]

                references.append({
                    "inspire_id":
                    ref_info['control_number'],
                    "citation_count":
                    ref_info.get('citation_count', 0),
                    "title":
                    get_title(ref_info),
                    "year":
                    ref_info['earliest_date'].split('-')[0]
                })

        out['references'] = references

        return json.dumps(out)