* We no longer keep mkws.pp2filter state-variable around
* limitTarget() and unlimitTarge() no longer mess around with Pazpar2
filter syntax
* limitQuery() no longer messes with the actual query
* triggerSearch () now calculates pp2filter (for targets) and pp2limit
(for field values) on the fly from mkws.filters.
* Limits as well as filters are passed into my_paz.search()
* limitQuery() calls resetPage() etc. by hand, as its sibling
functions do, instead of delegating to onFormSubmitEventHandler()
* Pass pazpar2 fieldnames rather than CCL indexes into
add_single_facet()
All of this fixes bug MKWS-63 ("Reimplement facets to use Pazpar2
filtering rather than query manipulation")
// Set up namespace and some state.
var mkws = {
filters: [],
// Set up namespace and some state.
var mkws = {
filters: [],
if (facets[i] == "sources") {
add_single_facet(acc, "Sources", data.xtargets, SourceMax, null);
} else if (facets[i] == "subjects") {
if (facets[i] == "sources") {
add_single_facet(acc, "Sources", data.xtargets, SourceMax, null);
} else if (facets[i] == "subjects") {
- add_single_facet(acc, "Subjects", data.subject, SubjectMax, "su");
+ add_single_facet(acc, "Subjects", data.subject, SubjectMax, "subject");
} else if (facets[i] == "authors") {
} else if (facets[i] == "authors") {
- add_single_facet(acc, "Authors", data.author, AuthorMax, "au");
+ add_single_facet(acc, "Authors", data.author, AuthorMax, "author");
} else {
alert("bad facet configuration: '" + facets[i] + "'");
}
} else {
alert("bad facet configuration: '" + facets[i] + "'");
}
replaceHtml(termlist, acc.join(''));
}
replaceHtml(termlist, acc.join(''));
}
-function add_single_facet(acc, caption, data, max, cclIndex) {
+function add_single_facet(acc, caption, data, max, pzIndex) {
acc.push('<div class="facet" id="mkwsFacet' + caption + '">');
acc.push('<div class="termtitle">' + M(caption) + '</div>');
for (var i = 0; i < data.length && i < max; i++ ) {
acc.push('<div class="term">');
acc.push('<a href="#" ');
var action;
acc.push('<div class="facet" id="mkwsFacet' + caption + '">');
acc.push('<div class="termtitle">' + M(caption) + '</div>');
for (var i = 0; i < data.length && i < max; i++ ) {
acc.push('<div class="term">');
acc.push('<a href="#" ');
var action;
// Special case: target selection
acc.push('target_id='+data[i].id+' ');
action = 'mkws.limitTarget(this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
} else {
// Special case: target selection
acc.push('target_id='+data[i].id+' ');
action = 'mkws.limitTarget(this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
} else {
- action = 'mkws.limitQuery(\'' + cclIndex + '\', this.firstChild.nodeValue)';
+ action = 'mkws.limitQuery(\'' + pzIndex + '\', this.firstChild.nodeValue)';
}
acc.push('onclick="' + action + ';return false;">' + data[i].name + '</a>'
+ ' <span>' + data[i].freq + '</span>');
}
acc.push('onclick="' + action + ';return false;">' + data[i].name + '</a>'
+ ' <span>' + data[i].freq + '</span>');
function triggerSearch ()
{
function triggerSearch ()
{
- debug("triggerSearch: filters = " + JSON.stringify(mkws.filters));
- my_paz.search(document.mkwsSearchForm.mkwsQuery.value, recPerPage, curSort, mkws.pp2filter);
+ var pp2filter = "";
+ var pp2limit = "";
+
+ for (var i in mkws.filters) {
+ var filter = mkws.filters[i];
+ if (filter.id) {
+ if (pp2filter)
+ pp2filter += ",";
+ pp2filter += 'pz:id=' + filter.id;
+ } else {
+ if (pp2limit)
+ pp2limit += ",";
+ pp2limit += filter.field + "=" + filter.value.replace(/[\\|,]/g, '\\$&');
+ }
+ }
+
+ debug("triggerSearch: filters = " + JSON.stringify(mkws.filters) + ", pp2filter = " + pp2filter + ", pp2limit = " + pp2limit);
+ my_paz.search(document.mkwsSearchForm.mkwsQuery.value, recPerPage, curSort, pp2filter, undefined, { limit: pp2limit });
debug("limitQuery(field=" + field + ", value=" + value + ")");
mkws.filters.push({ field: field, value: value });
redraw_navi();
debug("limitQuery(field=" + field + ", value=" + value + ")");
mkws.filters.push({ field: field, value: value });
redraw_navi();
- document.mkwsSearchForm.mkwsQuery.value += ' and ' + field + '="' + value + '"';
- onFormSubmitEventHandler();
+ resetPage();
+ loadSelect();
+ triggerSearch();
+ return false;
}
// limit by target functions
}
// limit by target functions
debug("limitTarget(id=" + id + ", name=" + name + ")");
mkws.filters.push({ id: id, name: name });
redraw_navi();
debug("limitTarget(id=" + id + ", name=" + name + ")");
mkws.filters.push({ id: id, name: name });
redraw_navi();
- mkws.pp2filter = 'pz:id=' + id;
resetPage();
loadSelect();
triggerSearch();
resetPage();
loadSelect();
triggerSearch();
mkws.filters = newFilters;
redraw_navi();
mkws.filters = newFilters;
redraw_navi();
resetPage();
loadSelect();
triggerSearch();
resetPage();
loadSelect();
triggerSearch();
mkws.filters = newFilters;
redraw_navi();
mkws.filters = newFilters;
redraw_navi();
resetPage();
loadSelect();
triggerSearch();
resetPage();
loadSelect();
triggerSearch();