middleman-search 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,245 @@
1
+ /*!
2
+ * Lunr languages, `Swedish` language
3
+ * https://github.com/MihaiValentin/lunr-languages
4
+ *
5
+ * Copyright 2014, Mihai Valentin
6
+ * http://www.mozilla.org/MPL/
7
+ */
8
+ /*!
9
+ * based on
10
+ * Snowball JavaScript Library v0.3
11
+ * http://code.google.com/p/urim/
12
+ * http://snowball.tartarus.org/
13
+ *
14
+ * Copyright 2010, Oleg Mazko
15
+ * http://www.mozilla.org/MPL/
16
+ */
17
+
18
+ /**
19
+ * export the module via AMD, CommonJS or as a browser global
20
+ * Export code from https://github.com/umdjs/umd/blob/master/returnExports.js
21
+ */
22
+ ;
23
+ (function(root, factory) {
24
+ if (typeof define === 'function' && define.amd) {
25
+ // AMD. Register as an anonymous module.
26
+ define(factory)
27
+ } else if (typeof exports === 'object') {
28
+ /**
29
+ * Node. Does not work with strict CommonJS, but
30
+ * only CommonJS-like environments that support module.exports,
31
+ * like Node.
32
+ */
33
+ module.exports = factory()
34
+ } else {
35
+ // Browser globals (root is window)
36
+ factory()(root.lunr);
37
+ }
38
+ }(this, function() {
39
+ /**
40
+ * Just return a value to define the module export.
41
+ * This example returns an object, but the module
42
+ * can return a function as the exported value.
43
+ */
44
+ return function(lunr) {
45
+ /* throw error if lunr is not yet included */
46
+ if ('undefined' === typeof lunr) {
47
+ throw new Error('Lunr is not present. Please include / require Lunr before this script.');
48
+ }
49
+
50
+ /* throw error if lunr stemmer support is not yet included */
51
+ if ('undefined' === typeof lunr.stemmerSupport) {
52
+ throw new Error('Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.');
53
+ }
54
+
55
+ /* register specific locale function */
56
+ lunr.sv = function() {
57
+ this.pipeline.reset();
58
+ this.pipeline.add(
59
+ lunr.sv.stopWordFilter,
60
+ lunr.sv.stemmer
61
+ );
62
+ };
63
+
64
+ /* lunr stemmer function */
65
+ lunr.sv.stemmer = (function() {
66
+ /* create the wrapped stemmer object */
67
+ var Among = lunr.stemmerSupport.Among,
68
+ SnowballProgram = lunr.stemmerSupport.SnowballProgram,
69
+ st = new function SwedishStemmer() {
70
+ var a_0 = [new Among("a", -1, 1), new Among("arna", 0, 1),
71
+ new Among("erna", 0, 1), new Among("heterna", 2, 1),
72
+ new Among("orna", 0, 1), new Among("ad", -1, 1),
73
+ new Among("e", -1, 1), new Among("ade", 6, 1),
74
+ new Among("ande", 6, 1), new Among("arne", 6, 1),
75
+ new Among("are", 6, 1), new Among("aste", 6, 1),
76
+ new Among("en", -1, 1), new Among("anden", 12, 1),
77
+ new Among("aren", 12, 1), new Among("heten", 12, 1),
78
+ new Among("ern", -1, 1), new Among("ar", -1, 1),
79
+ new Among("er", -1, 1), new Among("heter", 18, 1),
80
+ new Among("or", -1, 1), new Among("s", -1, 2),
81
+ new Among("as", 21, 1), new Among("arnas", 22, 1),
82
+ new Among("ernas", 22, 1), new Among("ornas", 22, 1),
83
+ new Among("es", 21, 1), new Among("ades", 26, 1),
84
+ new Among("andes", 26, 1), new Among("ens", 21, 1),
85
+ new Among("arens", 29, 1), new Among("hetens", 29, 1),
86
+ new Among("erns", 21, 1), new Among("at", -1, 1),
87
+ new Among("andet", -1, 1), new Among("het", -1, 1),
88
+ new Among("ast", -1, 1)
89
+ ],
90
+ a_1 = [new Among("dd", -1, -1),
91
+ new Among("gd", -1, -1), new Among("nn", -1, -1),
92
+ new Among("dt", -1, -1), new Among("gt", -1, -1),
93
+ new Among("kt", -1, -1), new Among("tt", -1, -1)
94
+ ],
95
+ a_2 = [
96
+ new Among("ig", -1, 1), new Among("lig", 0, 1),
97
+ new Among("els", -1, 1), new Among("fullt", -1, 3),
98
+ new Among("l\u00F6st", -1, 2)
99
+ ],
100
+ g_v = [17, 65, 16, 1, 0, 0, 0, 0,
101
+ 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 32
102
+ ],
103
+ g_s_ending = [119, 127, 149],
104
+ I_x, I_p1, sbp = new SnowballProgram();
105
+ this.setCurrent = function(word) {
106
+ sbp.setCurrent(word);
107
+ };
108
+ this.getCurrent = function() {
109
+ return sbp.getCurrent();
110
+ };
111
+
112
+ function r_mark_regions() {
113
+ var v_1, c = sbp.cursor + 3;
114
+ I_p1 = sbp.limit;
115
+ if (0 <= c || c <= sbp.limit) {
116
+ I_x = c;
117
+ while (true) {
118
+ v_1 = sbp.cursor;
119
+ if (sbp.in_grouping(g_v, 97, 246)) {
120
+ sbp.cursor = v_1;
121
+ break;
122
+ }
123
+ sbp.cursor = v_1;
124
+ if (sbp.cursor >= sbp.limit)
125
+ return;
126
+ sbp.cursor++;
127
+ }
128
+ while (!sbp.out_grouping(g_v, 97, 246)) {
129
+ if (sbp.cursor >= sbp.limit)
130
+ return;
131
+ sbp.cursor++;
132
+ }
133
+ I_p1 = sbp.cursor;
134
+ if (I_p1 < I_x)
135
+ I_p1 = I_x;
136
+ }
137
+ }
138
+
139
+ function r_main_suffix() {
140
+ var among_var, v_2 = sbp.limit_backward;
141
+ if (sbp.cursor >= I_p1) {
142
+ sbp.limit_backward = I_p1;
143
+ sbp.cursor = sbp.limit;
144
+ sbp.ket = sbp.cursor;
145
+ among_var = sbp.find_among_b(a_0, 37);
146
+ sbp.limit_backward = v_2;
147
+ if (among_var) {
148
+ sbp.bra = sbp.cursor;
149
+ switch (among_var) {
150
+ case 1:
151
+ sbp.slice_del();
152
+ break;
153
+ case 2:
154
+ if (sbp.in_grouping_b(g_s_ending, 98, 121))
155
+ sbp.slice_del();
156
+ break;
157
+ }
158
+ }
159
+ }
160
+ }
161
+
162
+ function r_consonant_pair() {
163
+ var v_1 = sbp.limit_backward;
164
+ if (sbp.cursor >= I_p1) {
165
+ sbp.limit_backward = I_p1;
166
+ sbp.cursor = sbp.limit;
167
+ if (sbp.find_among_b(a_1, 7)) {
168
+ sbp.cursor = sbp.limit;
169
+ sbp.ket = sbp.cursor;
170
+ if (sbp.cursor > sbp.limit_backward) {
171
+ sbp.bra = --sbp.cursor;
172
+ sbp.slice_del();
173
+ }
174
+ }
175
+ sbp.limit_backward = v_1;
176
+ }
177
+ }
178
+
179
+ function r_other_suffix() {
180
+ var among_var, v_2;
181
+ if (sbp.cursor >= I_p1) {
182
+ v_2 = sbp.limit_backward;
183
+ sbp.limit_backward = I_p1;
184
+ sbp.cursor = sbp.limit;
185
+ sbp.ket = sbp.cursor;
186
+ among_var = sbp.find_among_b(a_2, 5);
187
+ if (among_var) {
188
+ sbp.bra = sbp.cursor;
189
+ switch (among_var) {
190
+ case 1:
191
+ sbp.slice_del();
192
+ break;
193
+ case 2:
194
+ sbp.slice_from("l\u00F6s");
195
+ break;
196
+ case 3:
197
+ sbp.slice_from("full");
198
+ break;
199
+ }
200
+ }
201
+ sbp.limit_backward = v_2;
202
+ }
203
+ }
204
+ this.stem = function() {
205
+ var v_1 = sbp.cursor;
206
+ r_mark_regions();
207
+ sbp.limit_backward = v_1;
208
+ sbp.cursor = sbp.limit;
209
+ r_main_suffix();
210
+ sbp.cursor = sbp.limit;
211
+ r_consonant_pair();
212
+ sbp.cursor = sbp.limit;
213
+ r_other_suffix();
214
+ return true;
215
+ }
216
+ };
217
+
218
+ /* and return a function that stems a word for the current locale */
219
+ return function(word) {
220
+ st.setCurrent(word);
221
+ st.stem();
222
+ return st.getCurrent();
223
+ }
224
+ })();
225
+
226
+ lunr.Pipeline.registerFunction(lunr.sv.stemmer, 'stemmer-sv');
227
+
228
+ /* stop word filter function */
229
+ lunr.sv.stopWordFilter = function(token) {
230
+ if (lunr.sv.stopWordFilter.stopWords.indexOf(token) === -1) {
231
+ return token;
232
+ }
233
+ };
234
+
235
+ lunr.sv.stopWordFilter.stopWords = new lunr.SortedSet();
236
+ lunr.sv.stopWordFilter.stopWords.length = 115;
237
+
238
+ // The space at the beginning is crucial: It marks the empty string
239
+ // as a stop word. lunr.js crashes during search when documents
240
+ // processed by the pipeline still contain the empty string.
241
+ lunr.sv.stopWordFilter.stopWords.elements = ' alla allt att av blev bli blir blivit de dem den denna deras dess dessa det detta dig din dina ditt du där då efter ej eller en er era ert ett från för ha hade han hans har henne hennes hon honom hur här i icke ingen inom inte jag ju kan kunde man med mellan men mig min mina mitt mot mycket ni nu när någon något några och om oss på samma sedan sig sin sina sitta själv skulle som så sådan sådana sådant till under upp ut utan vad var vara varför varit varje vars vart vem vi vid vilka vilkas vilken vilket vår våra vårt än är åt över'.split(' ');
242
+
243
+ lunr.Pipeline.registerFunction(lunr.sv.stopWordFilter, 'stopWordFilter-sv');
244
+ };
245
+ }))