Sourcecode in Site/actions.js:
1: function search_action() {
2: res.data.action = this.href(req.action);
3: res.data.title = "Search " + this.title;
4: res.data.body = this.renderSkinAsString("searchform");
5:
6: if (req.data.q) {
7: var query = stripTags(req.data.q);
8: // array with sites to search
9: var sites = new Array (this);
10: var result = root.searchSites (query, this._id);
11: var found = result.length;
12: if (found == 0)
13: res.data.body += getMessage("error.searchNothingFound", query);
14: else {
15: var start = 0;
16: var end = found;
17:
18: if (found == 1)
19: res.data.body += getMessage("confirm.resultOne", query);
20: else if (found <= 10)
21: res.data.body += getMessage("confirm.resultMany", [encodeForm(query), found]);
22: else {
23: if (req.data.start)
24: start = Math.min (found-1, parseInt (req.data.start));
25: if (isNaN (start))
26: start = 0;
27: end = Math.min (found, start+10);
28: res.data.body += getMessage("confirm.resultMany", [encodeForm(query), found]);
29: res.data.body += " " + getMessage("confirm.resultDisplay", [start+1, end]);
30: }
31:
32: res.data.body += "<br />";
33:
34: // note: I'm doing this without a "searchbody" skin, since
35: // I think there's not much need to customize the body of
36: // search results, esp. since its parts are fully customizable.
37: // of course, I may be wrong about that.
38:
39: // render prev links, if necessary
40: if (start > 0) {
41: var sp = new Object();
42: sp.url = this.href() + "search?q=" + escape(query)+"&start=" + Math.max(0, start-10);
43: sp.text = "previous results";
44: res.data.body += "<br /><br />" + renderSkinAsString("prevpagelink", sp);
45: }
46:
47: // render result
48: for (var i=start; i<end; i++) {
49: var site = root.get(result[i].sitealias);
50: var item = site.allcontent.get(result[i].sid);
51: if (item)
52: res.data.body += item.renderSkinAsString("searchview");
53: }
54:
55: // render next links, if necessary
56: if (end < found) {
57: var sp = new Object();
58: sp.url = this.href() + "search?q=" + escape(query) + "&start=" + Math.min(found-1, start+10);
59: sp.text = "next results";
60: res.data.body += renderSkinAsString("nextpagelink", sp);
61: }
62: }
63: }
64: this.renderSkin("page");
65: return;
66: }
|