PageSourceSearch

https://ddvizig.hu/assets/del-dunantuli/site-default-hu/modules_site/solr/solr_search.js

js ddvizig.hu collected 2026-10-04 12:34:27 UTC 5,044 bytes, 185 lines download raw bytes

1System.register("solr/solr_search.js", ["jquery", "portal", "./solr-search.scss", "./typeahead.bundle.min"], function (_export, _context) {
2  "use strict";
3
4  var $, portal, translate;
5
6  function run(container) {
7    var $element = $(container);
8    var config = window.solrSearchConfig[$element.attr("data-solr-search")];
9    var url = config.suggestUrl;
10    var categories = config.categories;
11    var categoriesTemplate = {
12      "ALL": function ALL() {
13        return {
14          header: '<hr/>'
15        };
16      },
17      "default": function _default(categoryId) {
18        return {
19          header: '<span class="category-title">' + translate("SolrSearchResultPortlet.js." + categoryId) + '</span>',
20          suggestion: function suggestion(obj) {
21            return '<div>' + obj.name + '</div>';
22          }
23        };
24      },
25      get: function get(categoryId) {
26        var c = categoriesTemplate[categoryId];
27
28        if (!c) {
29          c = categoriesTemplate["default"];
30        }
31
32        return c(getCategory(categoryId));
33      }
34    };
35
36    function getCategory(categoryId) {
37      for (var i = 0; i < categories.length; ++i) {
38        var c = categories[i];
39
40        if (c === categoryId) {
41          return c;
42        }
43      }
44
45      return null;
46    }
47
48    function createSource(category) {
49      return new Bloodhound({
50        datumTokenizer: function datumTokenizer(datum) {
51          return Bloodhound.tokenizers.whitespace(datum.value);
52        },
53        queryTokenizer: Bloodhound.tokenizers.whitespace,
54        rateLimitWait: 0,
55        identify: function identify(obj) {
56          return obj.name;
57        },
58        remote: {
59          url: url,
60          prepare: function prepare(query, options) {
61            //Cache key calculated by: options.url + options.type + $.param(options.data||{})
62            options.data = {
63              term: query,
64              categories: categories
65            };
66            return options;
67          },
68          transport: function transport(options, onSuccess, onError) {
69            $.ajax({
70              "type": 'POST',
71              "url": options.url + "?_csrf=" + portal.getCsrfToken(),
72              "dataType": "json",
73              "contentType": "application/json; charset=utf-8",
74              "data": JSON.stringify(options.data),
75              success: function success(resp) {
76                var categories = resp.body;
77
78                for (var _category in categories) {
79                  if (categories.hasOwnProperty(_category)) {
80                    for (var i = 0; i < categories[_category].length; ++i) {
81                      var obj = categories[_category][i];
82                      obj.category = _category;
83                    }
84                  }
85                }
86
87                onSuccess(categories);
88              },
89              error: function error(resp) {
90                onError(resp);
91              }
92            });
93          },
94          transform: function transform(response) {
95            if (response.hasOwnProperty(category)) {
96              return response[category];
97            }
98
99            return [];
100          }
101        }
102      });
103    }
104
105    function createDataSource(categoryId, limit) {
106      if (!limit) {
107        limit = 5;
108      }
109
110      return {
111        name: categoryId,
112        limit: limit,
113        async: true,
114        source: createSource(categoryId),
115        display: function display(obj) {
116          return obj.name;
117        },
118        templates: categoriesTemplate.get(categoryId)
119      };
120    }
121
122    function createDataSources() {
123      var res = [];
124
125      for (var i = 0; i < categories.length; ++i) {
126        var c = categories[i];
127        res.push(createDataSource(c));
128      }
129
130      return res;
131    }
132
133    var queryInput = $element.find(".search-term");
134    var tt = queryInput.typeahead({
135      hint: false,
136      highlight: true,
137      minLength: 1
138    }, createDataSources());
139
140    function navigate(item) {
141      var urlKey = "SolrSearchResultPortlet.js.url";
142      var param = {
143        query: encodeURIComponent(queryInput.val())
144      };
145      var urlMappings = portal.getUrlMappings();
146
147      if (item) {
148        var urlN = urlKey + "." + item.category;
149
150        if (urlMappings.hasUrl(urlN, true)) {
151          if (item.name) {
152            //FIX IE bug
153            item.name = encodeURIComponent(item.name);
154          }
155
156          urlKey = urlN;
157          param = item;
158        }
159      }
160
161      location.href = urlMappings.getUrl(urlKey, param, true);
162    }
163
164    var form = $element.find("form");
165    form.on("submit", function (e) {
166      e.preventDefault();
167      navigate(null);
168    });
169    tt.on("typeahead:select", function (event, item) {
170      navigate(item);
171    });
172  }
173
174  _export("run", run);
175
176  return {
177    setters: [function (_jquery) {
178      $ = _jquery.default;
179    }, function (_portal) {
180      portal = _portal.portal;
181      translate = _portal.translate;
182    }, function (_solrSearchScss) {}, function (_typeaheadBundleMin) {}],
183    execute: function () {}
184  };
185});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.