1 | function performRefinedSearch()
|
---|
2 | {
|
---|
3 | var allCheckBoxes = $("#facetSelector input");
|
---|
4 | var counts = new Array();
|
---|
5 | for(var i = 0; i < allCheckBoxes.length; i++)
|
---|
6 | {
|
---|
7 | var current = $(allCheckBoxes[i]);
|
---|
8 | if(current.prop("checked"))
|
---|
9 | {
|
---|
10 | counts.push(current.parent().parent().attr("indexName") + ":(\"" + current.siblings("span").first().html() + "\")");
|
---|
11 | }
|
---|
12 | }
|
---|
13 |
|
---|
14 | var searchString = "";
|
---|
15 | for(var key in gs.cgiParams)
|
---|
16 | {
|
---|
17 | if (gs.cgiParams.hasOwnProperty(key))
|
---|
18 | {
|
---|
19 | searchString += key.replace(/_/g, ".") + "=" + makeURLComponentSafe(gs.cgiParams[key]) + "&";
|
---|
20 | //console.log("PARAM FOR key " + key + ":" + gs.cgiParams[key]);
|
---|
21 | //console.log("SAFE PARAM FOR " + key + ":" + makeURLComponentSafe(gs.cgiParams[key]));
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | var countsString = "s1.facetQueries=";
|
---|
26 | if(counts.length > 0)
|
---|
27 | {
|
---|
28 | var countsStringBuffer = "[";
|
---|
29 | for(var i = 0; i < counts.length; i++)
|
---|
30 | {
|
---|
31 | // escape any apostrophes in facet query terms
|
---|
32 | // (ext/solr's Greenstone3SearchHandler does the other half of handling them)
|
---|
33 | //countsStringBuffer += "\"" + encodeURI(counts[i]).replace(/'/g, "%2527") + "\"";
|
---|
34 | // calling makeURLSafe() here will ensure percent signs are escaped away too
|
---|
35 | // by the end of makeURLComponentSafe() call below
|
---|
36 | // Note that apostrophe's in URLs should get encoded, https://www.techwalla.com/articles/how-to-encode-an-apostrophe-in-a-url
|
---|
37 | // though the apostrophe is not in that other list of invalid and unsafe chars in urls dealt with in utility_scripts.js
|
---|
38 | countsStringBuffer += "\"" + makeURLSafe(counts[i]).replace(/'/g, "%2527") + "\"";
|
---|
39 | if(i < counts.length - 1)
|
---|
40 | {
|
---|
41 | countsStringBuffer += ", ";
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | countsStringBuffer += "]";
|
---|
46 |
|
---|
47 | // We need to ensure that the *value* of s1.facetQueries (so everything after
|
---|
48 | // s1.facetQueries= and before the connecting &) are safe, which requires escaping,
|
---|
49 | // and are further also escaped to not be mistaken for their reserved meaning.
|
---|
50 | // : is a reserved character in URLs, [] are unsafe characters. All need escaping.
|
---|
51 | // So call makeURLComponentSafe(), not makeURLSafe()
|
---|
52 | countsString = countsString + makeURLComponentSafe(countsStringBuffer, 1);
|
---|
53 | }
|
---|
54 |
|
---|
55 | countsString += "&";
|
---|
56 | //console.log("STRING IS " + countsString);
|
---|
57 |
|
---|
58 | $.ajax(gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/search/" + gs.cgiParams.s + "?" + searchString + countsString + "excerptid=resultsArea")
|
---|
59 | .done(function(response)
|
---|
60 | {
|
---|
61 | $("#resultsArea").html("");
|
---|
62 | $("#resultsArea").html(response.substring(response.indexOf(">") + 1, response.lastIndexOf("<")));
|
---|
63 | if(gs.cgiParams.berrybasket == "on") {
|
---|
64 | berryCheckout(); // called to add back in berries (if berrybasket active)
|
---|
65 | }
|
---|
66 | if(gs.cgiParams.favouritebasket == "on") {
|
---|
67 | favouritesCheckout(); // called to add back in favourites icons (if favouritebasket active)
|
---|
68 | }
|
---|
69 | if(typeof mapEnabled !== 'undefined') {
|
---|
70 |
|
---|
71 | facetedMapSearch(gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/search/" + gs.cgiParams.s + "?" + searchString + countsString);
|
---|
72 |
|
---|
73 | }
|
---|
74 | });
|
---|
75 | }
|
---|
76 |
|
---|
77 | function expandFacetList(indexName, countSize)
|
---|
78 | {
|
---|
79 | var tables = $(".facetTable");
|
---|
80 |
|
---|
81 | for(var i = 0; i < tables.length; i++)
|
---|
82 | {
|
---|
83 | var current = $(tables[i]);
|
---|
84 | if(current.attr("indexName") == indexName)
|
---|
85 | {
|
---|
86 | var items = current.children("li");
|
---|
87 |
|
---|
88 | for(var j = 0; j < items.length; j++)
|
---|
89 | {
|
---|
90 | $(items[j]).css("display", "block");
|
---|
91 | }
|
---|
92 |
|
---|
93 | break;
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | // the above code has made both see more and see less links display=block, so we need to hide
|
---|
98 | // see more
|
---|
99 | var morelink = $(".expandFacetList" + indexName);
|
---|
100 | morelink.css("display", "none");
|
---|
101 |
|
---|
102 | }
|
---|
103 |
|
---|
104 | function collapseFacetList(indexName, countSize)
|
---|
105 | {
|
---|
106 | var tables = $(".facetTable");
|
---|
107 |
|
---|
108 | for(var i = 0; i < tables.length; i++)
|
---|
109 | {
|
---|
110 | var current = $(tables[i]);
|
---|
111 | if(current.attr("indexName") == indexName)
|
---|
112 | {
|
---|
113 | var items = current.children("li");
|
---|
114 |
|
---|
115 | for(var j = 0; j < items.length; j++)
|
---|
116 | {
|
---|
117 | if(j > countSize)
|
---|
118 | {
|
---|
119 | $(items[j]).css("display", "none");
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | break;
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | // the above code has hidden both the see more and see less links.
|
---|
128 | // display the see more one
|
---|
129 | var morelink = $(".expandFacetList" + indexName);
|
---|
130 | morelink.css("display", "block");
|
---|
131 |
|
---|
132 | }
|
---|
133 |
|
---|