def number_of_records(collection_name): """Returns number of records for the collection.""" query = Query() index = collection_to_index(collection_name) result = es.count(index=index, body=query.body) return result['count']
def get_count_for_collection(doc_type, index=None): """ :param doc_type: e.g. CFG_PUB_TYPE or CFG_DATA_TYPE :param index: name of index to use. :return: the number of records in that collection """ return es.count(index=index, doc_type=doc_type)
def collections_count(): data = {'other': {}, 'journals': {}} # generate journal statistics journals = current_app.config['JOURNAL_ABBREVIATIONS'].keys() for journal in journals: data['journals'][journal] = current_search_client.count(q='journal:"%s"' % journal)['count'] # generate past x days statistics dates = { 'yesterday': (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d'), 'last_30_days': (datetime.now() - timedelta(days=30)).strftime('%Y-%m-%d'), 'this_year': datetime.now().year, } for key, date in dates.items(): data['other'][key] = current_search_client.count(q='date:>=%s' % date)['count'] # all article number data['other']['all'] = sum(count for _, count in data['journals'].items()) response = Response(json.dumps(data)) response.headers['Access-Control-Allow-Origin'] = '*' return response
def number_of_search_results(query, collection_name): """ Filter used to show total number of results out of filtered ones. """ session_key = 'last-query' + query + collection_name if session.get(session_key): query_timestamp = session[session_key]['timestamp'] seconds_since_query = ( datetime.datetime.utcnow() - query_timestamp).total_seconds() if seconds_since_query < 300: # Only use the session value if it is newer than 5 minutes # This should allow for the common use case of navigating # facets and avoid using an outdated value when using a direct # link return session[session_key][ "number_of_hits" ] query = Query(query) index = collection_to_index(collection_name) result = es.count(index=index, body=query.body) return result['count']
def is_doi_in_db(doi): return current_search_client.count(q='doi:"%s"' % doi)['count'] > 0
def is_record_in_db(obj, eng): """Checks if record is in database""" return es.count(q='dois.value:"%s"' % (get_first_doi(obj),))['count'] > 0
def is_record_in_db(obj, eng): """Checks if record is in database""" return es.count(q='dois.value:"%s"' % (__get_first_doi(obj), ))['count'] > 0
def number_of_records(collection_name): """Returns number of records for the collection.""" index = collection_to_index(collection_name) result = es.count(index=index) return result['count']