From f9b8ce4ca71110c94bc5cf90d346bc18466d5075 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Fri, 22 Nov 2013 17:30:23 +0000 Subject: [PATCH] A whole bunch of changes to do facets properly: * 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") --- tools/htdocs/mkws.js | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 9530afe..e560ad1 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -6,7 +6,6 @@ // Set up namespace and some state. var mkws = { filters: [], - pp2filter: null, }; /* @@ -259,9 +258,9 @@ function my_onterm(data) { 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") { - 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] + "'"); } @@ -271,19 +270,19 @@ function my_onterm(data) { replaceHtml(termlist, acc.join('')); } -function add_single_facet(acc, caption, data, max, cclIndex) { +function add_single_facet(acc, caption, data, max, pzIndex) { acc.push('
'); acc.push('
' + M(caption) + '
'); for (var i = 0; i < data.length && i < max; i++ ) { acc.push('
'); acc.push('' + data[i].name + '' + ' ' + data[i].freq + ''); @@ -375,8 +374,24 @@ function resetPage() 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 }); } function loadSelect () @@ -395,8 +410,10 @@ mkws.limitQuery = function (field, value) 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 @@ -405,7 +422,6 @@ mkws.limitTarget = function (id, name) debug("limitTarget(id=" + id + ", name=" + name + ")"); mkws.filters.push({ id: id, name: name }); redraw_navi(); - mkws.pp2filter = 'pz:id=' + id; resetPage(); loadSelect(); triggerSearch(); @@ -430,7 +446,6 @@ mkws.delimitQuery = function (field, value) mkws.filters = newFilters; redraw_navi(); - mkws.pp2filter = null; resetPage(); loadSelect(); triggerSearch(); @@ -454,7 +469,6 @@ mkws.delimitTarget = function (id) mkws.filters = newFilters; redraw_navi(); - mkws.pp2filter = null; resetPage(); loadSelect(); triggerSearch(); -- 1.7.10.4