Skip to content

Commit

Permalink
MIR-1362 fix empty fq and queries with more than one word
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy 'Alex' Levshyn committed Nov 19, 2024
1 parent f51c3e6 commit 00d4adb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
11 changes: 8 additions & 3 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 @@ -360,8 +360,8 @@
if (selectModsValue === 'all') {
$(fqElement).attr('value', '');
let condQueryValue = initialCondQueryValue;
if (initialCondQueryValue !== '') {
condQueryValue += ' AND ' + queryText;
if (queryText !== '') {
condQueryValue += ' AND ' + preparingQueryStringForSolr(queryText);
} else {
condQueryValue += queryText;
}
Expand All @@ -371,7 +371,7 @@
enableButton(secondSearchFormSubmitButtonElement);
}
} else {
const filterQuery = selectModsValue + ':' + queryText;
const filterQuery = selectModsValue + ':' + preparingQueryStringForSolr(queryText);
$(fqElement).attr('value', filterQuery);
$(condQuery).attr('value', initialCondQueryValue);
if (eventType === 'selectMods') {
Expand All @@ -387,6 +387,11 @@
}
}

// Add special characters to the query string for the SOLR request and remove all quotes from the query string
function preparingQueryStringForSolr(queryStr) {
return queryStr ? '"' + queryStr.replace(/"|%22/g, '') + '"' : queryStr;
}

// Disable the button
function disableButton(element) {
if (element) {
Expand Down
25 changes: 10 additions & 15 deletions mir-module/src/main/resources/xsl/response-mir.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,7 @@
<div class="search_box">

<!-- Check if 'condQuery' exists and extract its value if it does -->
<xsl:variable name="condQuery">
<xsl:choose>
<xsl:when test="contains($solrParams, 'condQuery=')">
<xsl:value-of select="substring-before(substring-after($solrParams, 'condQuery='), '&amp;')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="''" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="condQuery" select="/response/lst[@name='responseHeader']/lst[@name='params']/str[@name='condQuery']" />

<!-- Check if 'initialCondQuery' exists and extract its value if it does -->
<xsl:variable name="initialCondQuery" select="/response/lst[@name='responseHeader']/lst[@name='params']/str[@name='initialCondQuery']" />
Expand All @@ -85,7 +76,6 @@
<!-- Check if 'version' exists and extract its value if it does -->
<xsl:variable name="version" select="/response/lst[@name='responseHeader']/lst[@name='params']/str[@name='version']" />


<!-- Extract part before ':' ('%3A') if $fq is not empty or null -->
<xsl:variable name="initialSelectMods">
<xsl:choose>
Expand Down Expand Up @@ -209,7 +199,7 @@
<xsl:value-of select="''" />
</xsl:when>
<xsl:otherwise>
<xsl:variable name="searchString" select="concat($initialCondQuery, '+AND+')" />
<xsl:variable name="searchString" select="concat($initialCondQuery, ' AND ')" />
<xsl:value-of select="substring-after($condQuery, $searchString)" />
</xsl:otherwise>
</xsl:choose>
Expand All @@ -236,6 +226,9 @@
</xsl:choose>
</xsl:variable>

<!-- Decode the current query -->
<xsl:variable name="decodedCurrentQryFromLastRequest" select="decoder:decode($currentQryFromLastRequest, 'UTF-8')" />

<!-- Get a type of the last request -->
<xsl:variable name="lastTypeRequest">
<xsl:choose>
Expand All @@ -259,9 +252,9 @@
<input type="hidden" id="condQuery" name="condQuery">
<xsl:attribute name="value">
<xsl:choose>
<!-- If $lastTypeRequest is 'condQuery', concatenate $initialCondQuery, ' AND ', and $currentQry -->
<!-- If $lastTypeRequest is 'condQuery', concatenate $initialCondQuery, ' AND ' and $currentQry -->
<xsl:when test="$lastTypeRequest = 'condQuery'">
<xsl:value-of select="concat($initialCondQuery, ' AND ', $currentQryFromLastRequest)" />
<xsl:value-of select="concat($initialCondQuery, ' AND ', $decodedCurrentQryFromLastRequest)" />
</xsl:when>
<!-- If $lastTypeRequest is 'fq' or empty, use $initialCondQuery -->
<xsl:when test="$lastTypeRequest = 'fq' or $lastTypeRequest = ''">
Expand All @@ -275,8 +268,10 @@
</xsl:attribute>
</input>

<!-- Preparing the current query for the input field (remove all quotes) -->
<xsl:variable name="preparedCurrentQryFromLastRequest" select="translate($decodedCurrentQryFromLastRequest, '&quot;', '')" />
<!-- Input element for the second search -->
<input class="form-control" id="qry" placeholder="{i18n:translate('mir.placeholder.response.search')}" type="text" value="{$currentQryFromLastRequest}" />
<input class="form-control" id="qry" placeholder="{i18n:translate('mir.placeholder.response.search')}" type="text" value="{$preparedCurrentQryFromLastRequest}" />

</xsl:when>
<xsl:otherwise>
Expand Down

0 comments on commit 00d4adb

Please sign in to comment.