diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py index af8b552539aa6ef31b89831b1e2d183645038bc7..5f16c4a0be0bfa22ba8fc4fa5f2880c5719a5af4 100644 --- a/ckanext/odsh/helpers.py +++ b/ckanext/odsh/helpers.py @@ -33,8 +33,6 @@ def odsh_openness_score_dataset_html(dataset): qa = ast.literal_eval(r_qa) else: qa = r_qa - print('QA') - print(qa) resource_score = qa.get('openness_score') if resource_score > score: score = resource_score diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 86114c4b1d506729114028f4ced5f70404ca0e4e..1d5701d45d7f6d9df06ad62d97ab88f850fb775f 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -370,8 +370,11 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm # Add the custom parameters to Solr's facet queries + # use several daterange queries agains temporal_start and temporal_end field + # TODO: use field of type date_range in solr index instead def before_search(self, search_params): + extras = search_params.get('extras') if not extras: # There are no extras in the search params, so do nothing. @@ -419,10 +422,18 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm enclosing_query = ' OR ({enclosing_query_start} AND {enclosing_query_end})'.format( enclosing_query_start=enclosing_query_start, enclosing_query_end=enclosing_query_end) - fq = '{fq} ({start_query} OR {end_query} {enclosing_query})'.format( - fq=fq, start_query=start_query, end_query=end_query, enclosing_query=enclosing_query) + + if end_date is '*': + open_end_query = '(*:* NOT extras_temporal_end:[* TO *])' + else: + open_end_query = '((*:* NOT extras_temporal_end:[* TO *]) AND extras_temporal_start:[* TO {end_date}])'.format( + end_date=end_date) + + fq = '{fq} ({start_query} OR {end_query} {enclosing_query} OR {open_end_query})'.format( + fq=fq, start_query=start_query, end_query=end_query, enclosing_query=enclosing_query, open_end_query=open_end_query) - print(fq) + # fq = '{fq} ({start_query}'.format( + # fq=fq, start_query=start_query, end_query=end_query, enclosing_query=enclosing_query) # return modified facet queries search_params['fq'] = fq diff --git a/ckanext/odsh/tests/test_search.py b/ckanext/odsh/tests/test_search.py index 4bab66f881ad18d8466ece5b7226b2b0f92d55a6..2557936f1f5ed0deec9843ffa1088a5795d8fc3b 100644 --- a/ckanext/odsh/tests/test_search.py +++ b/ckanext/odsh/tests/test_search.py @@ -162,6 +162,27 @@ class TestSearch(helpers.FunctionalTestBase): self._assert_datasets_in_response([datasetA], response) self._assert_datasets_not_in_response([datasetB, datasetC], response) + @odsh_test() + def test_dataset_without_end(self): + # arrange + datasetA = self._create_dataset('dataseta', '1960-01-01', None,'mytitle') + + # act + response1 = self._perform_text_and_date_search('mytitle', '1950-01-01', '1950-02-01') + response2 = self._perform_text_and_date_search('mytitle', '1950-01-01', '1960-02-01') + response3 = self._perform_text_and_date_search('mytitle', '1950-01-01', None) + response4 = self._perform_text_and_date_search('mytitle', None, '1970-01-01') + response5 = self._perform_text_and_date_search('mytitle', '1970-01-01', '1980-02-01') + response6 = self._perform_text_and_date_search('mytitle', None, '1950-01-01') + + # assert + self._assert_datasets_not_in_response([datasetA], response1) + self._assert_datasets_in_response([datasetA], response2) + self._assert_datasets_in_response([datasetA], response3) + self._assert_datasets_in_response([datasetA], response4) + self._assert_datasets_in_response([datasetA], response5) + self._assert_datasets_not_in_response([datasetA], response6) + def _assert_datasets_in_response(self, datasets, response): for dataset in datasets: assert dataset['name'] in response diff --git a/ckanext/odsh/tests/test_upload.py b/ckanext/odsh/tests/test_upload.py index 949c383b6b841b50edf305d6804ea4530115a495..8d0a30f8d760a134cb207e0db3021450e7f54aac 100644 --- a/ckanext/odsh/tests/test_upload.py +++ b/ckanext/odsh/tests/test_upload.py @@ -30,7 +30,7 @@ class TestUpload(helpers.FunctionalTestBase): response.mustcontain('Title: Missing value') response.mustcontain('Description: Missing value') response.mustcontain('odsh_spatial_uri_error_label') - response.mustcontain('odsh_temporal_error_label') + response.mustcontain('odsh_temporal_start_error_label') @odsh_test() def test_upload_empty_wrong_spatial_uri(self): @@ -67,7 +67,7 @@ class TestUpload(helpers.FunctionalTestBase): response7 = self._submit_form(form) # assert - response1.mustcontain('odsh_temporal_error_label') + response1.mustcontain('odsh_temporal_start_not_date_error_label') response2.mustcontain('odsh_temporal_error_label') response3.mustcontain('odsh_temporal_end_not_date_error_label') response4.mustcontain('odsh_temporal_start_not_date_error_label')