Skip to content

Commit

Permalink
Fix query string for PubDate filter in old catalog
Browse files Browse the repository at this point in the history
Fixes #2151
  • Loading branch information
robyngit committed Jun 28, 2023
1 parent 492009b commit c7882cb
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions src/js/models/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,16 @@ define(["jquery", "underscore", "backbone", "models/SolrResult", "collections/Fi
query += " AND ";
}

var value = "[" + yearMin + "-01-01T00:00:00Z TO " + yearMax + "-12-31T00:00:00Z]";
var opts = {
forPOST: forPOST,
escapeSquareBrackets: false
}

//Add to the query if we are searching publication year
query += this.getMultiFieldQuery(this.fieldNameMap["pubYear"], "[" + yearMin + "-01-01T00:00:00Z TO " + yearMax + "-12-31T00:00:00Z]",
{
forPOST: forPOST
});
query += this.getMultiFieldQuery(
this.fieldNameMap["pubYear"], value, opts
);
}
}

Expand Down Expand Up @@ -929,10 +934,10 @@ define(["jquery", "underscore", "backbone", "models/SolrResult", "collections/Fi
return true;
}

return false;
return false;
},

escapeSpecialChar: function(term) {
escapeSpecialChar: function(term, escapeSquareBrackets=true) {
term = term.replace(/%7B/g, "%5C%7B");
term = term.replace(/%7D/g, "%5C%7D");
term = term.replace(/%3A/g, "%5C%3A");
Expand All @@ -948,17 +953,22 @@ define(["jquery", "underscore", "backbone", "models/SolrResult", "collections/Fi
term = term.replace(/%21/g, "%5C%21");
term = term.replace(/%28/g, "%5C%28");
term = term.replace(/%29/g, "%5C%29");
term = term.replace(/%5B/g, "%5C%5B");
term = term.replace(/%5D/g, "%5C%5D");
term = term.replace(/%5E/g, "%5C%5E");
term = term.replace(/%22/g, "%5C%22");
term = term.replace(/~/g, "%5C~");
term = term.replace(/-/g, "%5C-");
term = term.replace(/%2F/g, "%5C%2F");

if (escapeSquareBrackets) {
console.log("Escaping square brackets in term: ", term);
term = term.replace(/%5B/g, "%5C%5B");
term = term.replace(/%5D/g, "%5C%5D");
} else {
console.log("Not escaping square brackets in term: ", term);
}

return term;
},

},
/*
* Makes a Solr syntax grouped query using the field name, the field values to search for, and the operator.
* Example: title:(resistance OR salmon OR "pink salmon")
Expand Down Expand Up @@ -1090,6 +1100,8 @@ define(["jquery", "underscore", "backbone", "models/SolrResult", "collections/Fi
subtext = options.subtext,
forPOST = options.forPOST;
}
var esb = (typeof options.escapeSquareBrackets == "boolean") ?
options.escapeSquareBrackets : true;

//Default to the OR operator
if ((typeof operator === "undefined") || !operator ||
Expand Down Expand Up @@ -1121,26 +1133,26 @@ define(["jquery", "underscore", "backbone", "models/SolrResult", "collections/Fi
valueString += "("
}

if (model.needsQuotes(v) || _.contains(fieldNames, "id")) {
if (model.needsQuotes(v) || _.contains(fieldNames, "id")) {
if( forPOST ){
valueString += '"' + this.escapeSpecialChar(v.trim()) + '"';
valueString += '"' + this.escapeSpecialChar(v.trim(), esb) + '"';
}
else{
valueString += '"' + this.escapeSpecialChar(encodeURIComponent(v.trim())) + '"';
valueString += '"' + this.escapeSpecialChar(encodeURIComponent(v.trim()), esb) + '"';
}
} else if (subtext) {
} else if (subtext) {
if( forPOST ){
valueString += "*" + this.escapeSpecialChar(v.trim()) + "*";
valueString += "*" + this.escapeSpecialChar(v.trim(), esb) + "*";
}
else{
valueString += "*" + this.escapeSpecialChar(encodeURIComponent(v.trim())) + "*";
valueString += "*" + this.escapeSpecialChar(encodeURIComponent(v.trim()), esb) + "*";
}
} else {
if( forPOST ){
valueString += this.escapeSpecialChar(v.trim());
if (forPOST) {
valueString += this.escapeSpecialChar(v.trim(), esb);
}
else{
valueString += this.escapeSpecialChar(encodeURIComponent(v.trim()));
else {
valueString += this.escapeSpecialChar(encodeURIComponent(v.trim()), esb);
}
}

Expand Down

0 comments on commit c7882cb

Please sign in to comment.