def citations(self): """Citation export for single record in datatables format. :returns: list List of lists where every item represents a datatables row. A row consists of [reference, num_citations] """ from invenio_search.api import Query out = [] row = [] recid = self.record['control_number'] es_query = Query('refersto:' + str(recid)).search() es_query.body.update({ 'sort': [{'citation_count': {'order': 'desc'}}], 'size': 9999 }) citations = es_query.records() for citation in citations: row.append(render_template_to_string("citations.html", record=citation)) row.append(citation.get('citation_count', '')) out.append(row) row = [] return out
def _query(query): """ :type query: str """ ret = Query(query).search() ret.records = (get_record(request)(recid) for recid in ret.recids) return ret
def _query(query): """ :type query: str ..note:: `get_record` is used so that `invenio_records` is kept up to date. """ ret = Query(query).search() ret.records = (get_record(recid) for recid in ret.recids) return ret
def get_kbd_values_by_def(confdict, searchwith=""): """Return a list of values by searching a dynamic kb. :param confdict: dictionary with keys "field", "expression" and "collection" name :param searchwith: a term to search with :return: list of values """ from invenio_search.api import Query # get the configuration so that we see what the field is if not confdict: return [] if 'field' not in confdict: return [] field = confdict['field'] expression = confdict['expression'] collection = "" if 'collection' in confdict: collection = confdict['collection'] if searchwith and expression: if (expression.count('%') > 0): expression = expression.replace("%", searchwith) response = Query(expression).search(collection=collection) else: # no %.. just make a combination expression = expression + " and " + searchwith response = Query(expression).search(collection=collection) else: # either no expr or no searchwith.. but never mind about searchwith if expression: # in this case: only expression response = Query(expression).search(collection=collection) else: # make a fake expression so that only records that have this field # will be returned fake_exp = "/.*/" if searchwith: fake_exp = searchwith response = Query("{0}:{1}".format(field, fake_exp)).search( collection=collection ) # TODO wait for new search API for pagination response.body["size"] = 9999999 values = [] for record in response.records(): value = record.get(field) if value: values.append(value) return values
def get_kbd_values_by_def(confdict, searchwith=""): """Return a list of values by searching a dynamic kb. :param confdict: dictionary with keys "field", "expression" and "collection" name :param searchwith: a term to search with :return: list of values """ from invenio_search.api import Query # get the configuration so that we see what the field is if not confdict: return [] if 'field' not in confdict: return [] field = confdict['field'] expression = confdict['expression'] collection = "" if 'collection' in confdict: collection = confdict['collection'] if searchwith and expression: if (expression.count('%') > 0): expression = expression.replace("%", searchwith) response = Query(expression).search(collection=collection) else: # no %.. just make a combination expression = expression + " and " + searchwith response = Query(expression).search(collection=collection) else: # either no expr or no searchwith.. but never mind about searchwith if expression: # in this case: only expression response = Query(expression).search(collection=collection) else: # make a fake expression so that only records that have this field # will be returned fake_exp = "/.*/" if searchwith: fake_exp = searchwith response = Query("{0}:{1}".format( field, fake_exp)).search(collection=collection) # TODO wait for new search API for pagination response.body["size"] = 9999999 values = [] for record in response.records(): value = record.get(field) if value: values.append(value) return values
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, num_citations] """ from invenio_search.api import Query out = [] references = self.record.get('references') if references: refs_to_get_from_es = [ ref['recid'] for ref in references if ref.get('recid') ] es_query = ' or '.join( ['control_number:' + str(recid) for recid in refs_to_get_from_es] ) es_query = Query(es_query).search() es_query.body.update({ 'size': 9999 }) refs_from_es = { record['control_number']: record for record in es_query.records() } for reference in references: row = [] if 'recid' in reference: recid = reference['recid'] ref_record = refs_from_es.get(str(recid)) if ref_record: row.append(render_template_to_string( "references.html", record=ref_record, reference=reference )) row.append(ref_record.get('citation_count', '')) out.append(row) continue row.append(render_template_to_string( "references.html", reference=reference)) row.append('') out.append(row) return out
def render_citations(recid): """Citation export for single record in datatables format. :returns: list List of lists where every item represents a datatables row. A row consists of [reference, num_citations] """ out = [] row = [] es_query = Query('refersto:' + str(recid)).search() es_query.body.update({ 'sort': [{'citation_count': {'order': 'desc'}}] }) citations = es_query.records() for citation in citations: row.append(render_template_to_string("citations.html", record=citation, reference=None)) row.append(citation.get('citation_count', '')) out.append(row) row = [] return out