From b5653f42fca5fb34c390288009b728068191db16 Mon Sep 17 00:00:00 2001 From: Oleksiy 'Alex' Levshyn Date: Thu, 24 Oct 2024 15:15:35 +0200 Subject: [PATCH 01/14] MIR-1362 fix SOLR query filter --- .../META-INF/resources/js/mir/base.js | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/mir-module/src/main/resources/META-INF/resources/js/mir/base.js b/mir-module/src/main/resources/META-INF/resources/js/mir/base.js index b5c9f006fd..c2032c80ff 100644 --- a/mir-module/src/main/resources/META-INF/resources/js/mir/base.js +++ b/mir-module/src/main/resources/META-INF/resources/js/mir/base.js @@ -305,21 +305,31 @@ // do nothing if a query is missing $( ".search_box form" ).submit( function( event ) { if($(this).find("input[name='qry']").val().trim() != '') { - var origSearchAction = $(this).attr('action'); - var addValue = encodeURIComponent(solrEscapeSearchValue($('.search_box input').val().trim())); + const origSearchAction = $(this).attr('action'); + // To get the condQuery parameter, the URLSearchParams API is used + // (https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) + // (compatible: https://caniuse.com/?search=URLSearchParams) + const urlObj = new URL(origSearchAction); + // Get the query parameters + const params = new URLSearchParams(urlObj.search); + // Get the 'condQuery' parameter value + const condQuery = params.get('condQuery'); + const searchTypeButtonValueAttr = $('#search_type_button').attr('value'); + const addValue = encodeURIComponent(solrEscapeSearchValue($('.search_box input').val().trim())); + let newAction; if (origSearchAction.includes('servlets/solr/find')) { - var replAction = origSearchAction.replace(/(.*[&|\?])(condQuery=.*?)&(.*)/,'$1$3'); - if ($('#search_type_button').attr('value') == 'all') { - var newAction = replAction + "&condQuery=" + addValue; + const replAction = origSearchAction.replace(/(.*[&|\?])(condQuery=.*?)&(.*)/,'$1$3'); + if (searchTypeButtonValueAttr === 'all') { + newAction = replAction + "&condQuery=" + condQuery + "&fq=allMeta:" + addValue; } else { - var newAction = replAction + "&condQuery=" + addValue + "&df=" + $('#search_type_button').attr('value'); + newAction = replAction + "&condQuery=" + condQuery + "&fq=" + searchTypeButtonValueAttr + ":" + addValue; } - } else { - var replAction = origSearchAction.replace(/(.*[&|\?])(condQuery=.*?)&(.*)/,'$1$3&$2'); - if ($('#search_type_button').attr('value') == 'all') { - var newAction = replAction + "+%2BallMeta:" + addValue; + } else { // TODO: do it right + const replAction = origSearchAction.replace(/(.*[&|\?])(condQuery=.*?)&(.*)/,'$1$3&$2'); + if (searchTypeButtonValueAttr === 'all') { + newAction = replAction + "+%2BallMeta:" + addValue; } else { - var newAction = replAction + "+%2B" + $('#search_type_button').attr('value') + ":" + addValue; + newAction = replAction + "+%2B" + searchTypeButtonValueAttr + ":" + addValue; } } $(this).attr('action', newAction); From bf7b6e9f86d769b93437e8fafbfa8ad9000499fd Mon Sep 17 00:00:00 2001 From: Oleksiy 'Alex' Levshyn Date: Fri, 25 Oct 2024 11:28:13 +0200 Subject: [PATCH 02/14] MIR-1362 fix SOLR-request for all fields --- mir-module/src/main/resources/META-INF/resources/js/mir/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mir-module/src/main/resources/META-INF/resources/js/mir/base.js b/mir-module/src/main/resources/META-INF/resources/js/mir/base.js index c2032c80ff..0459c80972 100644 --- a/mir-module/src/main/resources/META-INF/resources/js/mir/base.js +++ b/mir-module/src/main/resources/META-INF/resources/js/mir/base.js @@ -320,7 +320,7 @@ if (origSearchAction.includes('servlets/solr/find')) { const replAction = origSearchAction.replace(/(.*[&|\?])(condQuery=.*?)&(.*)/,'$1$3'); if (searchTypeButtonValueAttr === 'all') { - newAction = replAction + "&condQuery=" + condQuery + "&fq=allMeta:" + addValue; + newAction = replAction + "&condQuery=" + condQuery + "+AND+" + addValue; } else { newAction = replAction + "&condQuery=" + condQuery + "&fq=" + searchTypeButtonValueAttr + ":" + addValue; } From 82622a27b78f6cec1f631c79f268c559b9068c30 Mon Sep 17 00:00:00 2001 From: Oleksiy 'Alex' Levshyn Date: Wed, 13 Nov 2024 11:35:49 +0100 Subject: [PATCH 03/14] MIR-1362 change and fix the second search with filter query etc --- .../xsl/mir-flatmir-layout-utils.xsl | 1 + .../META-INF/resources/js/mir/base.js | 110 +++++--- .../src/main/resources/xsl/response-mir.xsl | 253 ++++++++++++++---- 3 files changed, 268 insertions(+), 96 deletions(-) diff --git a/mir-layout/src/main/resources/xsl/mir-flatmir-layout-utils.xsl b/mir-layout/src/main/resources/xsl/mir-flatmir-layout-utils.xsl index 5a023acd5a..4c3886ac5f 100644 --- a/mir-layout/src/main/resources/xsl/mir-flatmir-layout-utils.xsl +++ b/mir-layout/src/main/resources/xsl/mir-flatmir-layout-utils.xsl @@ -73,6 +73,7 @@ id="searchInput" type="text" aria-label="Search" /> + diff --git a/mir-module/src/main/resources/META-INF/resources/js/mir/base.js b/mir-module/src/main/resources/META-INF/resources/js/mir/base.js index 0459c80972..0eac4b1802 100644 --- a/mir-module/src/main/resources/META-INF/resources/js/mir/base.js +++ b/mir-module/src/main/resources/META-INF/resources/js/mir/base.js @@ -293,52 +293,78 @@ }); }); - //for select box in search field on hit list page - $( ".search_type a" ).click(function() { - $( "#search_type_label" ).html( $( this ).html() ); - $( "#search_type_button" ).attr( 'value', $( this ).attr('value') ); + // Input element in the original search + const originalSearchInputElement = "#searchInput"; + // Selector for the search form + const subSearchFormName = "form.search_form"; + // ID of the input field for the second search text + const qrySelector = "#qry"; + // ID of the select box with the filter query key + const selectMods = "#select_mods"; + // ID of the hidden element with the fq parameter + const fqElement = "#fq"; + // ID of the hidden element with the initial condQuery parameter in the first search form + const initialCondQueryFirst = "#initialCondQuery"; + // ID of the hidden element with the initial condQuery parameter in the second search form + const initialCondQuerySecond = "#initialCondQuerySecond"; + // ID of the hidden element 'condQuery' for the query parameter 'condQuery' + const condQuery = "#condQuery"; + + // Input element's changes in the original search + $(originalSearchInputElement).change(() => { + if ($(initialCondQueryFirst)) { + $(initialCondQueryFirst).attr('value', $('#searchInput').val().trim()); + } }); - // filter for result lists - // modify search query - // TODO: modify? add why and how - // do nothing if a query is missing - $( ".search_box form" ).submit( function( event ) { - if($(this).find("input[name='qry']").val().trim() != '') { - const origSearchAction = $(this).attr('action'); - // To get the condQuery parameter, the URLSearchParams API is used - // (https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) - // (compatible: https://caniuse.com/?search=URLSearchParams) - const urlObj = new URL(origSearchAction); - // Get the query parameters - const params = new URLSearchParams(urlObj.search); - // Get the 'condQuery' parameter value - const condQuery = params.get('condQuery'); - const searchTypeButtonValueAttr = $('#search_type_button').attr('value'); - const addValue = encodeURIComponent(solrEscapeSearchValue($('.search_box input').val().trim())); - let newAction; - if (origSearchAction.includes('servlets/solr/find')) { - const replAction = origSearchAction.replace(/(.*[&|\?])(condQuery=.*?)&(.*)/,'$1$3'); - if (searchTypeButtonValueAttr === 'all') { - newAction = replAction + "&condQuery=" + condQuery + "+AND+" + addValue; - } else { - newAction = replAction + "&condQuery=" + condQuery + "&fq=" + searchTypeButtonValueAttr + ":" + addValue; - } - } else { // TODO: do it right - const replAction = origSearchAction.replace(/(.*[&|\?])(condQuery=.*?)&(.*)/,'$1$3&$2'); - if (searchTypeButtonValueAttr === 'all') { - newAction = replAction + "+%2BallMeta:" + addValue; - } else { - newAction = replAction + "+%2B" + searchTypeButtonValueAttr + ":" + addValue; - } - } - $(this).attr('action', newAction); - } else { - // nothing to do if a value is missing - event.preventDefault(); - } + // Changes in the select box for the filter query + $(selectMods).change(() => { + setFQAndCondQueryElementsValues(); + }); + + // Changes in the input field of the filter query + $(qrySelector).change(() => { + setFQAndCondQueryElementsValues(); }); + // Changes for the fq element and condQuery element + function setFQAndCondQueryElementsValues() { + if ($(selectMods) && $(qrySelector) && $(fqElement) && $(initialCondQuerySecond) && $(condQuery)) { + let queryText = ''; + if ($(qrySelector).val() !== '') { + queryText = $(qrySelector).val().trim(); + // Remove all duplicate spaces, tabs, newlines etc + queryText = queryText.replace(/\s\s+/g, ' '); + } + + const initialCondQueryValue = $(initialCondQuerySecond).val().trim(); + + const selectModsValue = $(selectMods).val(); + // Case if selectMods is 'all' - 'everything' + if (selectModsValue === 'all') { + $(fqElement).attr('value', ''); + let condQueryValue = initialCondQueryValue; + if (initialCondQueryValue !== '') { + if (queryText !== '') { + condQueryValue += ' AND ' + queryText; + } + } else { + if (queryText !== '') { + condQueryValue += queryText; + } + } + $(condQuery).attr('value', condQueryValue); + } else { + if (queryText !== '') { + // const selectModsValue = $(selectMods).val(); + const filterQuery = selectModsValue + ':' + queryText; + $(fqElement).attr('value', filterQuery); + $(condQuery).attr('value', initialCondQueryValue); + } + } + } + } + var languageList = jQuery('#topnav .languageList'); jQuery('#topnav .languageSelect').click(function() { languageList.toggleClass('hide'); diff --git a/mir-module/src/main/resources/xsl/response-mir.xsl b/mir-module/src/main/resources/xsl/response-mir.xsl index f8f6b32d84..8b89f46518 100644 --- a/mir-module/src/main/resources/xsl/response-mir.xsl +++ b/mir-module/src/main/resources/xsl/response-mir.xsl @@ -60,54 +60,129 @@