astro-accelerator 4.1.7 → 4.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/public/js/search.js +30 -6
package/package.json
CHANGED
package/public/js/search.js
CHANGED
|
@@ -26,6 +26,17 @@ function enabled(settings, option) {
|
|
|
26
26
|
return settings && settings.includes(option);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param {any} value
|
|
32
|
+
* @param {number} index
|
|
33
|
+
* @param {any[]} array
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
function unique(value, index, array) {
|
|
37
|
+
return array.indexOf(value) === index;
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
/**
|
|
30
41
|
@typedef {
|
|
31
42
|
{
|
|
@@ -38,6 +49,7 @@ function enabled(settings, option) {
|
|
|
38
49
|
@typedef {
|
|
39
50
|
{
|
|
40
51
|
foundWords: number;
|
|
52
|
+
foundTerms: string[];
|
|
41
53
|
score: number;
|
|
42
54
|
depth: number;
|
|
43
55
|
title: string;
|
|
@@ -272,7 +284,6 @@ function initializeSearch() {
|
|
|
272
284
|
}
|
|
273
285
|
}
|
|
274
286
|
|
|
275
|
-
console.log('Post-synonym', queryTerms);
|
|
276
287
|
return queryTerms.filter((qt) => qt != null);
|
|
277
288
|
}
|
|
278
289
|
|
|
@@ -295,7 +306,7 @@ function initializeSearch() {
|
|
|
295
306
|
}
|
|
296
307
|
|
|
297
308
|
/** @type {SearchEntry[]} */
|
|
298
|
-
|
|
309
|
+
let needles = [];
|
|
299
310
|
|
|
300
311
|
// Clean the input
|
|
301
312
|
const cleanQuery = sanitise(s);
|
|
@@ -321,6 +332,7 @@ function initializeSearch() {
|
|
|
321
332
|
cleanQuery.length > 0 &&
|
|
322
333
|
haystack.forEach((item) => {
|
|
323
334
|
item.foundWords = 0;
|
|
335
|
+
item.foundTerms = [];
|
|
324
336
|
item.score = 0;
|
|
325
337
|
item.matchedHeadings = [];
|
|
326
338
|
|
|
@@ -356,6 +368,8 @@ function initializeSearch() {
|
|
|
356
368
|
// Part 2 - Term Matches, i.e. "Kitchen" or "Sink"
|
|
357
369
|
|
|
358
370
|
let foundWords = 0;
|
|
371
|
+
/** @type{string[]} */
|
|
372
|
+
let foundTerms = [];
|
|
359
373
|
|
|
360
374
|
allTerms.forEach((term) => {
|
|
361
375
|
let isTermFound = false;
|
|
@@ -363,6 +377,7 @@ function initializeSearch() {
|
|
|
363
377
|
// Title
|
|
364
378
|
if (contains(item.safeTitle, term)) {
|
|
365
379
|
item.score = item.score + scoring.termTitle;
|
|
380
|
+
item.foundWords += scores.titleContains / 2;
|
|
366
381
|
isTermFound = true;
|
|
367
382
|
}
|
|
368
383
|
|
|
@@ -370,6 +385,7 @@ function initializeSearch() {
|
|
|
370
385
|
item.headings.forEach((c) => {
|
|
371
386
|
if (contains(c.safeText, term)) {
|
|
372
387
|
item.score = item.score + scoring.termHeading;
|
|
388
|
+
item.foundWords += scores.headingContains / 2;
|
|
373
389
|
isTermFound = true;
|
|
374
390
|
|
|
375
391
|
if (
|
|
@@ -404,10 +420,14 @@ function initializeSearch() {
|
|
|
404
420
|
|
|
405
421
|
if (isTermFound) {
|
|
406
422
|
foundWords++;
|
|
423
|
+
foundTerms.push(term);
|
|
407
424
|
}
|
|
408
425
|
});
|
|
409
426
|
|
|
410
427
|
item.foundWords += foundWords;
|
|
428
|
+
item.foundTerms = item.foundTerms
|
|
429
|
+
.concat(foundTerms)
|
|
430
|
+
.filter(unique);
|
|
411
431
|
|
|
412
432
|
if (item.score > 0) {
|
|
413
433
|
needles.push(item);
|
|
@@ -428,12 +448,16 @@ function initializeSearch() {
|
|
|
428
448
|
}
|
|
429
449
|
});
|
|
430
450
|
|
|
431
|
-
needles.sort(function (a, b) {
|
|
432
|
-
if (b.
|
|
433
|
-
|
|
451
|
+
needles = needles.sort(function (a, b) {
|
|
452
|
+
if (b.foundTerms.length === a.foundTerms.length) {
|
|
453
|
+
if (b.foundWords === a.foundWords) {
|
|
454
|
+
return b.score - a.score;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return b.foundWords - a.foundWords;
|
|
434
458
|
}
|
|
435
459
|
|
|
436
|
-
return b.
|
|
460
|
+
return b.foundTerms.length - a.foundTerms.length;
|
|
437
461
|
});
|
|
438
462
|
|
|
439
463
|
const total = needles.reduce(function (accumulator, needle) {
|