From d5aeb49eae312c1c2f2992c2aff81232b2120493 Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Tue, 28 Nov 2023 17:11:46 -0800 Subject: [PATCH 1/9] Move exact matches to top of results, re #10306 --- arches/app/models/concept.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arches/app/models/concept.py b/arches/app/models/concept.py index bf386175054..dc7a9685747 100644 --- a/arches/app/models/concept.py +++ b/arches/app/models/concept.py @@ -638,6 +638,13 @@ def get_child_edges( FROM children c JOIN values ON(values.conceptid = c.conceptidto) WHERE LOWER(values.value) like %(query)s + AND values.valuetype in ('prefLabel') + AND LOWER(values.value) != %(match)s + UNION + SELECT c.conceptidfrom, c.conceptidto, '0' as row, c.depth, c.collector + FROM children c + JOIN values ON(values.conceptid = c.conceptidto) + WHERE LOWER(values.value) = %(match)s AND values.valuetype in ('prefLabel') UNION SELECT c.conceptidfrom, c.conceptidto, c.row, c.depth, c.collector @@ -662,6 +669,7 @@ def get_child_edges( "limit": limit, "offset": offset, "query": "%" + query.lower() + "%", + "match": query.lower(), "recursive_table": AsIs(recursive_table), "languageid": languageid, "short_languageid": languageid.split("-")[0] + "%", From 0d928fdc4935a13a1a1d1414c7e4c5e78b12032d Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Tue, 28 Nov 2023 17:12:45 -0800 Subject: [PATCH 2/9] Prevent concepts outside collection from being selectable, re #10306 --- arches/app/views/concept.py | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/arches/app/views/concept.py b/arches/app/views/concept.py index 66efc8379c4..748782383af 100644 --- a/arches/app/views/concept.py +++ b/arches/app/views/concept.py @@ -392,42 +392,6 @@ def paged_dropdown(request): for d in data ] - # This try/except block trys to find an exact match to the concept the user is searching and if found - # it will insert it into the results as the first item so that users don't have to scroll to find it. - # See: https://github.com/archesproject/arches/issues/8355 - try: - if page == 1: - found = False - for i, d in enumerate(data): - if i <= 7 and d["text"].lower() == query.lower(): - found = True - break - if not found: - languageid = get_language().lower() - cursor = connection.cursor() - cursor.execute( - """ - SELECT value, valueid - FROM - ( - SELECT *, CASE WHEN LOWER(languageid) = %(languageid)s THEN 10 - WHEN LOWER(languageid) like %(short_languageid)s THEN 5 - ELSE 0 - END score - FROM values - ) as vals - WHERE LOWER(value)=%(query)s AND score > 0 - AND valuetype in ('prefLabel') - ORDER BY score desc limit 1 - """, - {"languageid": languageid, "short_languageid": languageid.split("-")[0] + "%", "query": query.lower()}, - ) - rows = cursor.fetchall() - - if len(rows) == 1: - data.insert(0, {"id": str(rows[0][1]), "text": rows[0][0], "depth": 1, "collector": False}) - except: - pass return JSONResponse({"results": data, "more": offset + limit < total_count}) From 990e742dfd14a1d08782a9acfe08584c1c941a50 Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Tue, 28 Nov 2023 17:13:05 -0800 Subject: [PATCH 3/9] nit --- arches/app/views/concept.py | 1 - 1 file changed, 1 deletion(-) diff --git a/arches/app/views/concept.py b/arches/app/views/concept.py index 748782383af..a2c011b142a 100644 --- a/arches/app/views/concept.py +++ b/arches/app/views/concept.py @@ -392,7 +392,6 @@ def paged_dropdown(request): for d in data ] - return JSONResponse({"results": data, "more": offset + limit < total_count}) From 57998a4fa7d56ee001dce31af2a33aba7132a117 Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Wed, 29 Nov 2023 11:30:28 -0800 Subject: [PATCH 4/9] Fix message formatting, re #10250 --- arches/app/media/js/views/search.js | 3 ++- arches/app/views/search.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arches/app/media/js/views/search.js b/arches/app/media/js/views/search.js index aa8f1e1e452..d3c6fc95cd9 100644 --- a/arches/app/media/js/views/search.js +++ b/arches/app/media/js/views/search.js @@ -163,8 +163,9 @@ define([ this.viewModel.alert(false); }, error: function(response, status, error) { + const alert = new AlertViewModel('ep-alert-red', arches.requestFailed.title, response.responseJSON?.message); if(this.updateRequest.statusText !== 'abort'){ - this.viewModel.alert(new AlertViewModel('ep-alert-red', arches.requestFailed.title, response.responseText)); + this.viewModel.alert(alert); } }, complete: function(request, status) { diff --git a/arches/app/views/search.py b/arches/app/views/search.py index e0e9690b4db..9737819442c 100644 --- a/arches/app/views/search.py +++ b/arches/app/views/search.py @@ -312,7 +312,7 @@ def search_results(request, returnDsl=False): append_instance_permission_filter_dsl(request, search_results_object) except Exception as err: logger.exception(err) - return JSONErrorResponse(message=err) + return JSONErrorResponse(message=str(err)) dsl = search_results_object.pop("query", None) if returnDsl: From c9e1e0f4019ba090086ad8366eae27a948fc07b7 Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Wed, 29 Nov 2023 11:31:34 -0800 Subject: [PATCH 5/9] Fix invalid exact match edtf query, re #10250 --- arches/app/datatypes/datatypes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arches/app/datatypes/datatypes.py b/arches/app/datatypes/datatypes.py index a3f450211a0..fcbc7683df9 100644 --- a/arches/app/datatypes/datatypes.py +++ b/arches/app/datatypes/datatypes.py @@ -556,7 +556,9 @@ def add_date_to_doc(query, edtf): if value["op"] == "eq": if edtf.lower != edtf.upper: raise Exception(_('Only dates that specify an exact year, month, and day can be used with the "=" operator')) - query.should(Match(field="tiles.data.%s.dates.date" % (str(node.pk)), query=edtf.lower, type="phrase_prefix")) + else: + operators = {"gte": edtf.lower, "lte": edtf.lower} + query.must(Range(field="tiles.data.%s.dates.date" % (str(node.pk)), **operators)) else: if value["op"] == "overlaps": operators = {"gte": edtf.lower, "lte": edtf.upper} From 981bd1be92295fca4c73bac5b6347298446300f8 Mon Sep 17 00:00:00 2001 From: Christopher Byrd Date: Wed, 29 Nov 2023 14:36:08 -0800 Subject: [PATCH 6/9] sorts resource instance select results #10304 (#10305) * sorts resource instance select results #10304 * change sorting to ascending #10304 --- arches/app/media/js/viewmodels/resource-instance-select.js | 1 + 1 file changed, 1 insertion(+) diff --git a/arches/app/media/js/viewmodels/resource-instance-select.js b/arches/app/media/js/viewmodels/resource-instance-select.js index 75613d13aa2..5e7554c4117 100644 --- a/arches/app/media/js/viewmodels/resource-instance-select.js +++ b/arches/app/media/js/viewmodels/resource-instance-select.js @@ -438,6 +438,7 @@ define([ queryString.set('term-filter', JSON.stringify(termFilter)); } } + queryString.set('sort-results', 'asc') return queryString.toString(); } }, From 2daf796f729fef32ccd0b8b603c33aa877a872a6 Mon Sep 17 00:00:00 2001 From: Christopher Byrd Date: Wed, 29 Nov 2023 15:24:36 -0800 Subject: [PATCH 7/9] updates message, fixes failure when passing empty edtf filter #10250 --- arches/app/datatypes/datatypes.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/arches/app/datatypes/datatypes.py b/arches/app/datatypes/datatypes.py index fcbc7683df9..a74599180b4 100644 --- a/arches/app/datatypes/datatypes.py +++ b/arches/app/datatypes/datatypes.py @@ -553,9 +553,16 @@ def add_date_to_doc(document, edtf): def append_search_filters(self, value, node, query, request): def add_date_to_doc(query, edtf): + invalid_filter_exception = Exception( + _( + 'Only dates that specify an exact year, month, \ + and day can be used with the "=", ">", "<", ">=", and "<=" operators' + ) + ) + if value["op"] == "eq": if edtf.lower != edtf.upper: - raise Exception(_('Only dates that specify an exact year, month, and day can be used with the "=" operator')) + raise invalid_filter_exception else: operators = {"gte": edtf.lower, "lte": edtf.lower} query.must(Range(field="tiles.data.%s.dates.date" % (str(node.pk)), **operators)) @@ -564,12 +571,7 @@ def add_date_to_doc(query, edtf): operators = {"gte": edtf.lower, "lte": edtf.upper} else: if edtf.lower != edtf.upper: - raise Exception( - _( - 'Only dates that specify an exact year, month, \ - and day can be used with the ">", "<", ">=", and "<=" operators' - ) - ) + raise invalid_filter_exception operators = {value["op"]: edtf.lower or edtf.upper} @@ -582,7 +584,9 @@ def add_date_to_doc(query, edtf): if edtf.lower is None and edtf.upper is None: raise Exception(_("Invalid date specified.")) - if value["op"] == "null" or value["op"] == "not_null": + if not value.get('op'): + pass + elif value["op"] == "null" or value["op"] == "not_null": self.append_null_search_filters(value, node, query, request) elif value["val"] != "" and value["val"] is not None: edtf = ExtendedDateFormat(value["val"]) From 28fcecae08c15f80781505b6f2218b9ac8ae91a4 Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Wed, 29 Nov 2023 15:53:42 -0800 Subject: [PATCH 8/9] Update release notes with latest bug fixes --- releases/6.2.6.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/releases/6.2.6.md b/releases/6.2.6.md index e3a0bf65cd6..9ea3d180267 100644 --- a/releases/6.2.6.md +++ b/releases/6.2.6.md @@ -7,6 +7,9 @@ Arches 6.2.6 release notes - Adds missing file renderers to project template #10171 - Fixes multiple EDTF nodes in single card used in advanced search returning too many records #10202 - Fixes error when handling multiple subcard levels in search export #10214 +- Fixes edtf advanced search error message #10309 +- Disallows selection of concepts outside of a collection in concept widget #10308 +- Sorts resources in resource instance dropdown, #10305 ### Dependency changes: ``` From fc5d62b7840682fd44f1243c9e07e599cebd949b Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Wed, 29 Nov 2023 17:14:34 -0800 Subject: [PATCH 9/9] Update 7.4.3 release notes with lates fixes in 6 --- releases/7.4.3.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/releases/7.4.3.md b/releases/7.4.3.md index cfeb4fea6f8..828ea6f73bd 100644 --- a/releases/7.4.3.md +++ b/releases/7.4.3.md @@ -13,6 +13,9 @@ Arches 7.4.3 release notes - Hides separator line for invisible cards #10221 - Fixes resetting the maximum number of files for a file-list node #10229 - Fixes geometries not being updated for geojson nodes #10292 +- Fixes edtf advanced search error message #10309 +- Disallows selection of concepts outside of a collection in concept widget #10308 +- Sorts resources in resource instance dropdown, #10305 ### Dependency changes: