From 623fca5f80ecd832a2b3d6cefafc3e5ec48a1c7d Mon Sep 17 00:00:00 2001 From: David Read Date: Tue, 10 May 2016 11:14:35 +0000 Subject: [PATCH] New syntax for pysolr connection --- ckanext/harvest/logic/action/update.py | 30 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/ckanext/harvest/logic/action/update.py b/ckanext/harvest/logic/action/update.py index 9c1f227..e4f2041 100644 --- a/ckanext/harvest/logic/action/update.py +++ b/ckanext/harvest/logic/action/update.py @@ -5,7 +5,6 @@ import logging import datetime from pylons import config -from paste.deploy.converters import asbool from sqlalchemy import and_, or_ from ckan.lib.search.index import PackageSearchIndex @@ -249,15 +248,26 @@ def harvest_source_index_clear(context, data_dict): conn = make_connection() query = ''' +%s:"%s" +site_id:"%s" ''' % ( 'harvest_source_id', harvest_source_id, config.get('ckan.site_id')) - try: - conn.delete_query(query) - if asbool(config.get('ckan.search.solr_commit', 'true')): - conn.commit() - except Exception, e: - log.exception(e) - raise SearchIndexError(e) - finally: - conn.close() + + solr_commit = toolkit.asbool(config.get('ckan.search.solr_commit', 'true')) + if toolkit.check_ckan_version(max_version='2.5.99'): + # conn is solrpy + try: + conn.delete_query(query) + if solr_commit: + conn.commit() + except Exception, e: + log.exception(e) + raise SearchIndexError(e) + finally: + conn.close() + else: + # conn is pysolr + try: + conn.delete(q=query, commit=solr_commit) + except Exception, e: + log.exception(e) + raise SearchIndexError(e) return {'id': harvest_source_id}