Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIR-1362 Result filter displayed on top of search results ignores "df"-Parameter #1088

Open
wants to merge 14 commits into
base: 2023.06.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,42 +177,49 @@ public void searchBy(String title) {
public void searchByPublication(String title, String subTitle, String author, String name, String nameIdentifier,
String metadata, String content) {

// select mods (filter query) is 'all'
if (title != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Alles")).click();
qry(title);
}

// select mods (filter query) is 'mods.title'
if (subTitle != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Titel")).click();
qry(subTitle);
}

// select mods (filter query) is 'mods.author'
if (author != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Autor")).click();
qry(author);
}

// select mods (filter query) is 'mods.name.top'
if (name != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Name")).click();
qry(name);
}

// select mods (filter query) is 'mods.nameIdentifier'
if (nameIdentifier != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Namens Identifikator")).click();
qry(nameIdentifier);
}

// select mods (filter query) is 'allMeta'
if (metadata != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Alle Metadaten")).click();
qry(metadata);
}

// select mods (filter query) is 'content'
if (content != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Volltext")).click();
Expand Down
18 changes: 18 additions & 0 deletions mir-layout/src/main/resources/xsl/mir-flatmir-layout-utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,30 @@
action="{$WebApplicationBaseURL}servlets/solr/find"
class="searchfield_box form-inline my-2 my-lg-0"
role="search">
<!-- 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']" />

<input
name="condQuery"
placeholder="{i18n:translate('mir.navsearch.placeholder')}"
class="form-control mr-sm-2 search-query"
id="searchInput"
type="text"
aria-label="Search" />

<input type="hidden" id="initialCondQueryMirFlatmirLayout" name="initialCondQuery">
<xsl:attribute name="value">
<xsl:choose>
<xsl:when test="$initialCondQuery">
<xsl:value-of select="$initialCondQuery"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'*'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</input>

<xsl:choose>
<xsl:when test="contains($isSearchAllowedForCurrentUser, 'true')">
<input name="owner" type="hidden" value="createdby:*" />
Expand All @@ -81,6 +98,7 @@
<input name="owner" type="hidden" value="createdby:{$CurrentUser}" />
</xsl:when>
</xsl:choose>

<button type="submit" class="btn btn-primary my-2 my-sm-0">
<i class="fas fa-search"></i>
</button>
Expand Down
157 changes: 126 additions & 31 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 @@ -293,42 +293,137 @@
});
});

//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 mir-flatmir-layout-utils.xsl search
const mirFlatmirLayoutSearchInputElement = "#searchInput";
// Selector for the second search form
const subSearchFormName = "form.search_form";
// The submit button in the second search form
const secondSearchFormSubmitButtonElement = subSearchFormName + ' button[type="submit"]';
// ID of the input field for the second search text
const qrySelector = "#qry";
// ID of the dropdown element with the filter query key
const selectMods = "#select_mods";
// ID of the dropdown element with the filter query key
const selectModsLabel = "#select_mods_label";
// Selector of a dropdown-menu item
const selectModsItem = ".select_mods_type .dropdown-item";
// ID of the hidden element with the fq parameter
const fqElement = "#fq";
// ID of the hidden element with the initial condQuery parameter in the mir-flatmir-layout-utils.xsl search form
const initialCondQueryMirFlatmirLayout = "#initialCondQueryMirFlatmirLayout";
// 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 mir-flatmir-layout-utils.xsl search
$(mirFlatmirLayoutSearchInputElement).change(() => {
if ($(initialCondQueryMirFlatmirLayout).length) {
let initialCondQueryValue = $(mirFlatmirLayoutSearchInputElement).val().trim();
if (initialCondQueryValue === '') {
initialCondQueryValue = '*';
}
$(initialCondQueryMirFlatmirLayout).attr('value', initialCondQueryValue);
}
});

// 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() != '') {
var origSearchAction = $(this).attr('action');
var addValue = encodeURIComponent(solrEscapeSearchValue($('.search_box input').val().trim()));
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;
} else {
var newAction = replAction + "&condQuery=" + addValue + "&df=" + $('#search_type_button').attr('value');
}
} else {
var replAction = origSearchAction.replace(/(.*[&|\?])(condQuery=.*?)&(.*)/,'$1$3&$2');
if ($('#search_type_button').attr('value') == 'all') {
var newAction = replAction + "+%2BallMeta:" + addValue;
} else {
var newAction = replAction + "+%2B" + $('#search_type_button').attr('value') + ":" + addValue;
}
}
$(this).attr('action', newAction);
} else {
// nothing to do if a value is missing
event.preventDefault();
// Select one of the dropdown-menu items
$(selectModsItem).click(function() {
if ($(selectModsLabel).length) {
// Change the dropdowns label
$(selectModsLabel).html( $( this ).html() );
}
if ($(selectMods).length) {
// Change the dropdowns value
$(selectMods).attr( 'value', $( this ).attr('value') );

setFQAndCondQueryElementsValues('selectMods');
}
});

// Changes in the input field of the filter query
$(qrySelector).change(() => {
setFQAndCondQueryElementsValues('changeQry');
});

// Key up changes in the second search input element
$(qrySelector).keyup(() => {
if ($(selectMods).length) {
const queryText = $(qrySelector).val().trim();
const selectModsValue = $(selectMods).val();
// Case if selectMods is 'all' - 'everything'
if (selectModsValue !== 'all') {
if (queryText !== '') {
// Enable the submit button in the second search form
enableButton(secondSearchFormSubmitButtonElement);
} else {
// Disable the submit button in the second search form
disableButton(secondSearchFormSubmitButtonElement);
}
}
}
});

// Changes for the fq element and condQuery element
function setFQAndCondQueryElementsValues(eventType = 'selectMods') {
if ($(selectMods).length && $(qrySelector).length && $(fqElement).length && $(initialCondQuerySecond).length
&& $(condQuery).length) {
let queryText = '';
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 (queryText !== '') {
condQueryValue += ' AND ' + preparingQueryStringForSolr(queryText);
} else {
condQueryValue += queryText;
}
$(condQuery).attr('value', condQueryValue);
if (eventType === 'selectMods') {
// Enable the submit button in the second search form
enableButton(secondSearchFormSubmitButtonElement);
}
} else {
const filterQuery = selectModsValue + ':' + preparingQueryStringForSolr(queryText);
$(fqElement).attr('value', filterQuery);
$(condQuery).attr('value', initialCondQueryValue);
if (eventType === 'selectMods') {
if (queryText !== '') {
// Enable the submit button in the second search form
enableButton(secondSearchFormSubmitButtonElement);
} else {
// Disable the submit button in the second search form
disableButton(secondSearchFormSubmitButtonElement);
}
}
}
}
}

// 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) {
$(element).attr('disabled','disabled');
}
}

// Enable the button
function enableButton(element) {
if (element) {
$(element).removeAttr('disabled');
}
}

var languageList = jQuery('#topnav .languageList');
jQuery('#topnav .languageSelect').click(function() {
languageList.toggleClass('hide');
Expand Down
Loading
Loading