From b0d81a543c94850809890eaeab0e83f00b71772a Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Sun, 23 Sep 2018 13:24:30 +0300 Subject: [PATCH] Refactor Solr components This makes it so we only need to define and connect once and then we can re-use the connection everywhere else. --- app.py | 5 +---- solr.py | 9 +++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 solr.py diff --git a/app.py b/app.py index 61fb35c..5f9745e 100644 --- a/app.py +++ b/app.py @@ -2,10 +2,9 @@ # 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 -from SolrClient import SolrClient +from solr import solr_connection class ItemResource: @@ -14,8 +13,6 @@ 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) - # Get views res = solr.query(SOLR_CORE, { 'q':'type:2 AND id:{0}'.format(item_id), diff --git a/solr.py b/solr.py new file mode 100644 index 0000000..e2677b7 --- /dev/null +++ b/solr.py @@ -0,0 +1,9 @@ +from config import SOLR_SERVER +from SolrClient import SolrClient + +def solr_connection(): + connection = SolrClient(SOLR_SERVER) + + return connection + +# vim: set sw=4 ts=4 expandtab: