Skip to content

Commit

Permalink
Merge pull request #4040 from maxious/3949-fix-solr-delete_package
Browse files Browse the repository at this point in the history
[#3949] Fix and test Solr index delete_package implementation
  • Loading branch information
amercader committed Feb 27, 2018
2 parents 855cfe8 + 7ff9236 commit 938cba0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ckan/lib/search/index.py
Expand Up @@ -314,12 +314,10 @@ def commit(self):
log.exception(e)
raise SearchIndexError(e)


def delete_package(self, pkg_dict):
conn = make_connection()
query = "+%s:%s (+id:\"%s\" OR +name:\"%s\") +site_id:\"%s\"" % (TYPE_FIELD, PACKAGE_TYPE,
pkg_dict.get('id'), pkg_dict.get('id'),
config.get('ckan.site_id'))
query = "+%s:%s AND +(id:\"%s\" OR name:\"%s\") AND +site_id:\"%s\"" % \
(TYPE_FIELD, PACKAGE_TYPE, pkg_dict.get('id'), pkg_dict.get('id'), config.get('ckan.site_id'))
try:
commit = asbool(config.get('ckan.search.solr_commit', 'true'))
conn.delete(q=query, commit=commit)
Expand Down
22 changes: 22 additions & 0 deletions ckan/tests/lib/search/test_index.py
Expand Up @@ -81,6 +81,28 @@ def test_clear_index(self):
response = self.solr_client.search(q='name:monkey', fq=self.fq)
assert_equal(len(response), 0)

def test_delete_package(self):
self.package_index.index_package(self.base_package_dict)

pkg_dict = self.base_package_dict.copy()
pkg_dict.update({
'id': 'test-index-2',
'name': 'monkey2'
})
self.package_index.index_package(pkg_dict)

response = self.solr_client.search(q='title:Monkey', fq=self.fq)
assert_equal(len(response), 2)
response_ids = sorted([x['id'] for x in response.docs])
assert_equal(response_ids, ['test-index', 'test-index-2'])

self.package_index.delete_package(pkg_dict)

response = self.solr_client.search(q='title:Monkey', fq=self.fq)
assert_equal(len(response), 1)
response_ids = sorted([x['id'] for x in response.docs])
assert_equal(response_ids, ['test-index'])

def test_index_illegal_xml_chars(self):

pkg_dict = self.base_package_dict.copy()
Expand Down

0 comments on commit 938cba0

Please sign in to comment.