mirror of
https://github.com/ilri/dspace-statistics-api.git
synced 2025-05-10 15:16:02 +02:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
9e01a80011
|
|||
a263996582
|
|||
ed9d25294e
|
|||
5e165d2e88
|
|||
8e29fd8a43
|
|||
24af83b03f
|
|||
a87aaba812
|
|||
57faec59c8
|
|||
06ab254017
|
|||
5b5cab8b34
|
@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.0.3] - 2018-09-20
|
||||
### Changed
|
||||
- Refactor environment variables into config module
|
||||
- Simplify Solr query for "downloads"
|
||||
- Optimize Solr query by using rows=0
|
||||
- Fix Solr queries for item views
|
||||
|
||||
## [0.0.2] - 2018-09-18
|
||||
### Added
|
||||
- Ability to get Solr parameters from environment (`SOLR_SERVER` and `SOLR_CORE`)
|
||||
|
@ -13,7 +13,7 @@ Create a virtual environment and run it:
|
||||
|
||||
## Todo
|
||||
|
||||
- Take a list of items (POST in JSON?)
|
||||
- Ability to return a paginated list of items (on a different route?)
|
||||
|
||||
## License
|
||||
This work is licensed under the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html).
|
||||
|
24
app.py
24
app.py
@ -2,13 +2,11 @@
|
||||
# See DSpace Solr docs for tips about parameters
|
||||
# https://wiki.duraspace.org/display/DSPACE/Solr
|
||||
|
||||
from config import SOLR_SERVER
|
||||
from config import SOLR_CORE
|
||||
import falcon
|
||||
import os
|
||||
from SolrClient import SolrClient
|
||||
|
||||
# Check if Solr connection information was provided in the environment
|
||||
solr_server = os.environ.get('SOLR_SERVER', 'http://localhost:8080/solr')
|
||||
solr_core = os.environ.get('SOLR_CORE', 'statistics')
|
||||
|
||||
class ItemResource:
|
||||
def on_get(self, req, resp):
|
||||
@ -16,21 +14,21 @@ class ItemResource:
|
||||
# Return HTTPBadRequest if id parameter is not present and valid
|
||||
item_id = req.get_param_as_int("id", required=True, min=0)
|
||||
|
||||
solr = SolrClient(solr_server)
|
||||
solr = SolrClient(SOLR_SERVER)
|
||||
|
||||
# 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)
|
||||
})
|
||||
res = solr.query(SOLR_CORE, {
|
||||
'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:[* TO *] -bundleName:ORIGINAL)'.format(item_id)
|
||||
})
|
||||
res = solr.query(SOLR_CORE, {
|
||||
'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()
|
||||
|
||||
|
Reference in New Issue
Block a user