Skip to content

Commit

Permalink
MIR-1362 fix SOLR query filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy 'Alex' Levshyn committed Oct 24, 2024
1 parent ed74361 commit b5653f4
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions mir-module/src/main/resources/META-INF/resources/js/mir/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b5653f4

Please sign in to comment.