From a26399658258b43f59be0cf44c1ba7e160915a5b Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Thu, 20 Sep 2018 17:34:55 +0300 Subject: [PATCH] app.py: Fix Solr queries for item views According to dspace-api's Constants.java, items are type 2 and they use a unique ID field of `id` instead of `owningItem`. There is no need to check the bundleName for item types. Also, I decided to use the main Solr query for item IDs because the filter query parameter (fq) stores results in the filterCache and can be quite expensive with cores storing tens of millions of docu- ments (we currently have 149 million docs!). It makes sense to use the filter query parameter to reduce the result set returned by the main Solr query. --- app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index a06a7cd..b137eee 100644 --- a/app.py +++ b/app.py @@ -18,16 +18,16 @@ class ItemResource: # Get views res = solr.query(SOLR_CORE, { - 'q':'type:0', - 'fq':'owningItem:{0} AND isBot:false AND statistics_type:view AND -bundleName:ORIGINAL'.format(item_id) + 'q':'type:2 AND id:{0}'.format(item_id), + 'fq':'isBot:false AND statistics_type:view' }, rows=0) views = res.get_num_found() # Get downloads res = solr.query(SOLR_CORE, { - 'q':'type:0', - 'fq':'owningItem:{0} AND isBot:false AND statistics_type:view AND bundleName:ORIGINAL'.format(item_id) + 'q':'type:0 AND owningItem:{0}'.format(item_id), + 'fq':'isBot:false AND statistics_type:view AND bundleName:ORIGINAL' }, rows=0) downloads = res.get_num_found()