notch8_sunspot_autocomplete 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/LICENSE +7 -0
  2. data/README.rdoc +95 -0
  3. data/Rakefile +37 -0
  4. data/VERSION +1 -0
  5. data/lib/autocomplete_view_helpers.rb +126 -0
  6. data/lib/notch8_sunspot_autocomplete.rb +3 -0
  7. data/lib/sunspot_autocomplete.rb +38 -0
  8. data/notch8_sunspot_autocomplete.gemspec +78 -0
  9. data/rdoc/classes/AutocompleteViewHelpers.html +322 -0
  10. data/rdoc/classes/Sunspot.html +111 -0
  11. data/rdoc/classes/Sunspot/Type.html +112 -0
  12. data/rdoc/classes/Sunspot/Type/AutocompleteType.html +117 -0
  13. data/rdoc/classes/Sunspot/Type/AutosuggestType.html +117 -0
  14. data/rdoc/created.rid +1 -0
  15. data/rdoc/files/README.html +238 -0
  16. data/rdoc/files/README_rdoc.html +238 -0
  17. data/rdoc/files/lib/autocomplete_view_helpers_rb.html +236 -0
  18. data/rdoc/files/lib/sunspot_autocomplete_rb.html +101 -0
  19. data/rdoc/fr_class_index.html +31 -0
  20. data/rdoc/fr_file_index.html +29 -0
  21. data/rdoc/fr_method_index.html +28 -0
  22. data/rdoc/index.html +24 -0
  23. data/rdoc/rdoc-style.css +208 -0
  24. data/tasks/tasks.rake +10 -0
  25. data/test/sunspot_autocomplete_test.rb +21 -0
  26. data/test/test_helper.rb +3 -0
  27. data/vendor/assets/javascripts/jquery.js +6240 -0
  28. data/vendor/assets/javascripts/solr-autocomplete/ajax-solr/core/AbstractManager.js +182 -0
  29. data/vendor/assets/javascripts/solr-autocomplete/ajax-solr/core/Core.js +226 -0
  30. data/vendor/assets/javascripts/solr-autocomplete/ajax-solr/core/Parameter.js +161 -0
  31. data/vendor/assets/javascripts/solr-autocomplete/ajax-solr/core/ParameterStore.js +354 -0
  32. data/vendor/assets/javascripts/solr-autocomplete/ajax-solr/managers/Manager.jquery.js +20 -0
  33. data/vendor/assets/javascripts/solr-autocomplete/jquery-autocomplete/indicator.gif +0 -0
  34. data/vendor/assets/javascripts/solr-autocomplete/jquery-autocomplete/jquery.autocomplete.css +49 -0
  35. data/vendor/assets/javascripts/solr-autocomplete/jquery-autocomplete/jquery.autocomplete.js +867 -0
  36. metadata +114 -0
@@ -0,0 +1,182 @@
1
+ // $Id$
2
+
3
+ /**
4
+ * The Manager acts as the controller in a Model-View-Controller framework. All
5
+ * public calls should be performed on the manager object.
6
+ *
7
+ * @param properties A map of fields to set. Refer to the list of public fields.
8
+ * @class AbstractManager
9
+ */
10
+ AjaxSolr.AbstractManager = AjaxSolr.Class.extend(
11
+ /** @lends AjaxSolr.AbstractManager.prototype */
12
+ {
13
+ /**
14
+ * The fully-qualified URL of the Solr application. You must include the
15
+ * trailing slash. Do not include the path to any Solr servlet.
16
+ *
17
+ * @field
18
+ * @public
19
+ * @type String
20
+ * @default "http://localhost:8983/solr/"
21
+ */
22
+ solrUrl: 'http://localhost:8983/solr/',
23
+
24
+ /**
25
+ * If we want to proxy queries through a script, rather than send queries
26
+ * to Solr directly, set this field to the fully-qualified URL of the script.
27
+ *
28
+ * @field
29
+ * @public
30
+ * @type String
31
+ */
32
+ proxyUrl: null,
33
+
34
+ /**
35
+ * The default Solr servlet.
36
+ *
37
+ * @field
38
+ * @public
39
+ * @type String
40
+ * @default "select"
41
+ */
42
+ servlet: 'select',
43
+
44
+ /**
45
+ * The most recent response from Solr.
46
+ *
47
+ * @field
48
+ * @private
49
+ * @type Object
50
+ * @default {}
51
+ */
52
+ response: {},
53
+
54
+ /**
55
+ * A collection of all registered widgets. For internal use only.
56
+ *
57
+ * @field
58
+ * @private
59
+ * @type Object
60
+ * @default {}
61
+ */
62
+ widgets: {},
63
+
64
+ /**
65
+ * The parameter store for the manager and its widgets. For internal use only.
66
+ *
67
+ * @field
68
+ * @private
69
+ * @type Object
70
+ */
71
+ store: null,
72
+
73
+ /**
74
+ * Whether <tt>init()</tt> has been called yet. For internal use only.
75
+ *
76
+ * @field
77
+ * @private
78
+ * @type Boolean
79
+ * @default false
80
+ */
81
+ initialized: false,
82
+
83
+ /**
84
+ * An abstract hook for child implementations.
85
+ *
86
+ * <p>This method should be called after the store and the widgets have been
87
+ * added. It should initialize the widgets and the store, and do any other
88
+ * one-time initializations, e.g., perform the first request to Solr.</p>
89
+ *
90
+ * <p>If no store has been set, it sets the store to the basic <tt>
91
+ * AjaxSolr.ParameterStore</tt>.</p>
92
+ */
93
+ init: function () {
94
+ this.initialized = true;
95
+ if (this.store === null) {
96
+ this.setStore(new AjaxSolr.ParameterStore());
97
+ }
98
+ this.store.load(false);
99
+ for (var widgetId in this.widgets) {
100
+ this.widgets[widgetId].init();
101
+ }
102
+ this.store.init();
103
+ },
104
+
105
+ /**
106
+ * Set the manager's parameter store.
107
+ *
108
+ * @param {AjaxSolr.ParameterStore} store
109
+ */
110
+ setStore: function (store) {
111
+ store.manager = this;
112
+ this.store = store;
113
+ },
114
+
115
+ /**
116
+ * Adds a widget to the manager.
117
+ *
118
+ * @param {AjaxSolr.AbstractWidget} widget
119
+ */
120
+ addWidget: function (widget) {
121
+ widget.manager = this;
122
+ this.widgets[widget.id] = widget;
123
+ },
124
+
125
+ /**
126
+ * Stores the Solr parameters to be sent to Solr and sends a request to Solr.
127
+ *
128
+ * @param {Boolean} [start] The Solr start offset parameter.
129
+ * @param {String} [servlet] The Solr servlet to send the request to.
130
+ */
131
+ doRequest: function (start, servlet) {
132
+ if (this.initialized === false) {
133
+ this.init();
134
+ }
135
+ // Allow non-pagination widgets to reset the offset parameter.
136
+ if (start !== undefined) {
137
+ this.store.get('start').val(start);
138
+ }
139
+ if (servlet === undefined) {
140
+ servlet = this.servlet;
141
+ }
142
+
143
+ this.store.save();
144
+
145
+ for (var widgetId in this.widgets) {
146
+ this.widgets[widgetId].beforeRequest();
147
+ }
148
+
149
+ this.executeRequest(servlet);
150
+ },
151
+
152
+ /**
153
+ * An abstract hook for child implementations.
154
+ *
155
+ * <p>Sends the request to Solr, i.e. to <code>this.solrUrl</code> or <code>
156
+ * this.proxyUrl</code>, and receives Solr's response. It should send <code>
157
+ * this.store.string()</code> as the Solr query, and it should pass Solr's
158
+ * response to <code>handleResponse()</code> for handling.</p>
159
+ *
160
+ * <p>See <tt>managers/Manager.jquery.js</tt> for a jQuery implementation.</p>
161
+ *
162
+ * @param {String} servlet The Solr servlet to send the request to.
163
+ * @throws If not defined in child implementation.
164
+ */
165
+ executeRequest: function (servlet) {
166
+ throw 'Abstract method executeRequest must be overridden in a subclass.';
167
+ },
168
+
169
+ /**
170
+ * This method is executed after the Solr response data arrives. Allows each
171
+ * widget to handle Solr's response separately.
172
+ *
173
+ * @param {Object} data The Solr response.
174
+ */
175
+ handleResponse: function (data) {
176
+ this.response = data;
177
+
178
+ for (var widgetId in this.widgets) {
179
+ this.widgets[widgetId].afterRequest();
180
+ }
181
+ }
182
+ });
@@ -0,0 +1,226 @@
1
+ // $Id$
2
+
3
+ /**
4
+ * @namespace A unique namespace for the AJAX Solr library.
5
+ */
6
+ AjaxSolr = function () {};
7
+
8
+ /**
9
+ * @namespace Baseclass for all classes
10
+ */
11
+ AjaxSolr.Class = function () {};
12
+
13
+ /**
14
+ * A class 'extends' itself into a subclass.
15
+ *
16
+ * @static
17
+ * @param properties The properties of the subclass.
18
+ * @returns A function that represents the subclass.
19
+ */
20
+ AjaxSolr.Class.extend = function (properties) {
21
+ var klass = this; // Safari dislikes 'class'
22
+ // The subclass is just a function that when called, instantiates itself.
23
+ // Nothing is _actually_ shared between _instances_ of the same class.
24
+ var subClass = function (options) {
25
+ // 'this' refers to the subclass, which starts life as an empty object.
26
+ // Add its parent's properties, its own properties, and any passed options.
27
+ AjaxSolr.extend(this, new klass(options), properties, options);
28
+ }
29
+ // Allow the subclass to extend itself into further subclasses.
30
+ subClass.extend = this.extend;
31
+ return subClass;
32
+ };
33
+
34
+ /**
35
+ * @static
36
+ * @param {Object} obj Any object.
37
+ * @returns {Number} the number of properties on an object.
38
+ * @see http://stackoverflow.com/questions/5223/length-of-javascript-associative-array
39
+ */
40
+ AjaxSolr.size = function (obj) {
41
+ var size = 0;
42
+ for (var key in obj) {
43
+ if (obj.hasOwnProperty(key)) {
44
+ size++;
45
+ }
46
+ }
47
+ return size;
48
+ };
49
+
50
+ /**
51
+ * @static
52
+ * @param foo A value.
53
+ * @param bar A value.
54
+ * @returns {Boolean} Whether the two given values are equal.
55
+ */
56
+ AjaxSolr.equals = function (foo, bar) {
57
+ if (AjaxSolr.isArray(foo) && AjaxSolr.isArray(bar)) {
58
+ if (foo.length !== bar.length) {
59
+ return false;
60
+ }
61
+ for (var i = 0, l = foo.length; i < l; i++) {
62
+ if (foo[i] !== bar[i]) {
63
+ return false;
64
+ }
65
+ }
66
+ return true;
67
+ }
68
+ else if (AjaxSolr.isRegExp(foo) && AjaxSolr.isString(bar)) {
69
+ return bar.match(foo);
70
+ }
71
+ else if (AjaxSolr.isRegExp(bar) && AjaxSolr.isString(foo)) {
72
+ return foo.match(bar);
73
+ }
74
+ else {
75
+ return foo === bar;
76
+ }
77
+ };
78
+
79
+ /**
80
+ * @static
81
+ * @param value A value.
82
+ * @param array An array.
83
+ * @returns {Boolean} Whether value exists in the array.
84
+ */
85
+ AjaxSolr.inArray = function (value, array) {
86
+ if (array) {
87
+ for (var i = 0, l = array.length; i < l; i++) {
88
+ if (AjaxSolr.equals(array[i], value)) {
89
+ return i;
90
+ }
91
+ }
92
+ }
93
+ return -1;
94
+ };
95
+
96
+ /**
97
+ * A copy of MooTools' Array.flatten function.
98
+ *
99
+ * @static
100
+ * @see http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools.js
101
+ */
102
+ AjaxSolr.flatten = function(array) {
103
+ var ret = [];
104
+ for (var i = 0, l = array.length; i < l; i++) {
105
+ ret = ret.concat(AjaxSolr.isArray(array[i]) ? AjaxSolr.flatten(array[i]) : array[i]);
106
+ }
107
+ return ret;
108
+ };
109
+
110
+ /**
111
+ * A copy of jQuery's jQuery.grep function.
112
+ *
113
+ * @static
114
+ * @see http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
115
+ */
116
+ AjaxSolr.grep = function(array, callback) {
117
+ var ret = [];
118
+ for (var i = 0, l = array.length; i < l; i++) {
119
+ if (!callback(array[i], i) === false) {
120
+ ret.push(array[i]);
121
+ }
122
+ }
123
+ return ret;
124
+ }
125
+
126
+ /**
127
+ * Equivalent to Ruby's Array#compact.
128
+ */
129
+ AjaxSolr.compact = function(array) {
130
+ return AjaxSolr.grep(array, function (item) {
131
+ return item.toString();
132
+ });
133
+ }
134
+
135
+ /**
136
+ * Can't use toString.call(obj) === "[object Array]", as it may return
137
+ * "[xpconnect wrapped native prototype]", which is undesirable.
138
+ *
139
+ * @static
140
+ * @see http://thinkweb2.com/projects/prototype/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/
141
+ * @see http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js
142
+ */
143
+ AjaxSolr.isArray = function (obj) {
144
+ return obj != null && typeof obj == 'object' && 'splice' in obj && 'join' in obj;
145
+ };
146
+
147
+ /**
148
+ * @param obj Any object.
149
+ * @returns {Boolean} Whether the object is a RegExp object.
150
+ */
151
+ AjaxSolr.isRegExp = function (obj) {
152
+ return obj != null && (typeof obj == 'object' || typeof obj == 'function') && 'ignoreCase' in obj;
153
+ };
154
+
155
+ /**
156
+ * @param obj Any object.
157
+ * @returns {Boolean} Whether the object is a String object.
158
+ */
159
+ AjaxSolr.isString = function (obj) {
160
+ return obj != null && typeof obj == 'string';
161
+ };
162
+
163
+ /**
164
+ * Define theme functions to separate, as much as possible, your HTML from your
165
+ * JavaScript. Theme functions provided by AJAX Solr are defined in the
166
+ * AjaxSolr.theme.prototype namespace, e.g. AjaxSolr.theme.prototype.select_tag.
167
+ *
168
+ * To override a theme function provided by AJAX Solr, define a function of the
169
+ * same name in the AjaxSolr.theme namespace, e.g. AjaxSolr.theme.select_tag.
170
+ *
171
+ * To retrieve the HTML output by AjaxSolr.theme.prototype.select_tag(...), call
172
+ * AjaxSolr.theme('select_tag', ...).
173
+ *
174
+ * @param {String} func
175
+ * The name of the theme function to call.
176
+ * @param ...
177
+ * Additional arguments to pass along to the theme function.
178
+ * @returns
179
+ * Any data the theme function returns. This could be a plain HTML string,
180
+ * but also a complex object.
181
+ *
182
+ * @static
183
+ * @throws Exception if the theme function is not defined.
184
+ * @see http://cvs.drupal.org/viewvc.py/drupal/drupal/misc/drupal.js?revision=1.58
185
+ */
186
+ AjaxSolr.theme = function (func) {
187
+ for (var i = 1, args = []; i < arguments.length; i++) {
188
+ args.push(arguments[i]);
189
+ }
190
+ try {
191
+ return (AjaxSolr.theme[func] || AjaxSolr.theme.prototype[func]).apply(this, args);
192
+ }
193
+ catch (e) {
194
+ if (console && console.log) {
195
+ console.log('Theme function "' + func + '" is not defined.');
196
+ }
197
+ throw e;
198
+ }
199
+ };
200
+
201
+ /**
202
+ * A simplified version of jQuery's extend function.
203
+ *
204
+ * @static
205
+ * @see http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
206
+ */
207
+ AjaxSolr.extend = function () {
208
+ var target = arguments[0] || {}, i = 1, length = arguments.length, options;
209
+ for (; i < length; i++) {
210
+ if ((options = arguments[i]) != null) {
211
+ for (var name in options) {
212
+ var src = target[name], copy = options[name];
213
+ if (target === copy) {
214
+ continue;
215
+ }
216
+ if (copy && typeof copy == 'object' && !copy.nodeType) {
217
+ target[name] = AjaxSolr.extend(src || (copy.length != null ? [] : {}), copy);
218
+ }
219
+ else if (copy !== undefined) {
220
+ target[name] = copy;
221
+ }
222
+ }
223
+ }
224
+ }
225
+ return target;
226
+ };
@@ -0,0 +1,161 @@
1
+ // $Id$
2
+
3
+ /**
4
+ * Represents a Solr parameter.
5
+ *
6
+ * @param properties A map of fields to set. Refer to the list of public fields.
7
+ * @class Parameter
8
+ */
9
+ AjaxSolr.Parameter = AjaxSolr.Class.extend(
10
+ /** @lends AjaxSolr.Parameter.prototype */
11
+ {
12
+ /**
13
+ * The parameter's name.
14
+ *
15
+ * @field
16
+ * @private
17
+ * @type String
18
+ */
19
+ name: null,
20
+
21
+ /**
22
+ * The parameter's value.
23
+ *
24
+ * @field
25
+ * @private
26
+ * @type String
27
+ */
28
+ value: null,
29
+
30
+ /**
31
+ * The parameter's local parameters.
32
+ *
33
+ * @field
34
+ * @private
35
+ * @type Object
36
+ * @default {}
37
+ */
38
+ locals: {},
39
+
40
+ /**
41
+ * Returns the value. If called with an argument, sets the value.
42
+ *
43
+ * @param {String|Number|String[]|Number[]} [value] The value to set.
44
+ * @returns The value.
45
+ */
46
+ val: function (value) {
47
+ if (value === undefined) {
48
+ return this.value;
49
+ }
50
+ else {
51
+ this.value = value;
52
+ }
53
+ },
54
+
55
+ /**
56
+ * Returns the value of a local parameter. If called with a second argument,
57
+ * sets the value of a local parameter.
58
+ *
59
+ * @param {String} name The name of the local parameter.
60
+ * @param {String|Number|String[]|Number[]} [value] The value to set.
61
+ * @returns The value.
62
+ */
63
+ local: function (name, value) {
64
+ if (value === undefined) {
65
+ return this.locals[name];
66
+ }
67
+ else {
68
+ this.locals[name] = value;
69
+ }
70
+ },
71
+
72
+ /**
73
+ * Deletes a local parameter.
74
+ *
75
+ * @param {String} name The name of the local parameter.
76
+ */
77
+ remove: function (name) {
78
+ delete this.locals[name];
79
+ },
80
+
81
+ /**
82
+ * Returns the Solr parameter as a query string key-value pair.
83
+ *
84
+ * <p>IE6 calls the default toString() if you write <tt>store.toString()
85
+ * </tt>. So, we need to choose another name for toString().</p>
86
+ */
87
+ string: function () {
88
+ var pairs = [];
89
+
90
+ for (var name in this.locals) {
91
+ if (this.locals[name]) {
92
+ pairs.push(name + '=' + encodeURIComponent(this.locals[name]));
93
+ }
94
+ }
95
+
96
+ var prefix = pairs.length ? '{!' + pairs.join('%20') + '}' : '';
97
+
98
+ if (this.value) {
99
+ return this.name + '=' + prefix + this.valueString(this.value);
100
+ }
101
+ // For dismax request handlers, if the q parameter has local params, the
102
+ // q parameter must be set to a non-empty value. In case the q parameter
103
+ // is empty, use the q.alt parameter, which accepts wildcards.
104
+ else if (this.name == 'q') {
105
+ return 'q.alt=' + prefix + encodeURIComponent('*.*');
106
+ }
107
+ else {
108
+ return '';
109
+ }
110
+ },
111
+
112
+ /**
113
+ * Parses a string formed by calling string().
114
+ *
115
+ * @param {String} str The string to parse.
116
+ */
117
+ parseString: function (str) {
118
+ var param = str.match(/^([^=]+)=(?:\{!([^\}]*)\})?(.*)$/);
119
+ if (param) {
120
+ var matches;
121
+
122
+ while (matches = /([^\s=]+)=(\S*)/g.exec(decodeURIComponent(param[2]))) {
123
+ this.locals[matches[1]] = decodeURIComponent(matches[2]);
124
+ param[2] = param[2].replace(matches[0], ''); // Safari's exec seems not to do this on its own
125
+ }
126
+
127
+ if (param[1] == 'q.alt') {
128
+ this.name = 'q';
129
+ // if q.alt is present, assume it is because q was empty, as above
130
+ }
131
+ else {
132
+ this.name = param[1];
133
+ this.value = this.parseValueString(param[3]);
134
+ }
135
+ }
136
+ },
137
+
138
+ /**
139
+ * Returns the value as a URL-encoded string.
140
+ *
141
+ * @private
142
+ * @param {String|Number|String[]|Number[]} value The value.
143
+ * @returns {String} The URL-encoded string.
144
+ */
145
+ valueString: function (value) {
146
+ value = AjaxSolr.isArray(value) ? value.join(',') : value;
147
+ return encodeURIComponent(value);
148
+ },
149
+
150
+ /**
151
+ * Parses a URL-encoded string to return the value.
152
+ *
153
+ * @private
154
+ * @param {String} str The URL-encoded string.
155
+ * @returns {Array} The value.
156
+ */
157
+ parseValueString: function (str) {
158
+ str = decodeURIComponent(str);
159
+ return str.indexOf(',') == -1 ? str : str.split(',');
160
+ }
161
+ });