astro-accelerator 4.1.7 → 4.1.8

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.1.7",
2
+ "version": "4.1.8",
3
3
  "author": "Steve Fenton",
4
4
  "name": "astro-accelerator",
5
5
  "description": "A super-lightweight, accessible, SEO-friendly starter project for Astro",
@@ -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
 
@@ -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;
@@ -404,10 +418,14 @@ function initializeSearch() {
404
418
 
405
419
  if (isTermFound) {
406
420
  foundWords++;
421
+ foundTerms.push(term);
407
422
  }
408
423
  });
409
424
 
410
425
  item.foundWords += foundWords;
426
+ item.foundTerms = item.foundTerms
427
+ .concat(foundTerms)
428
+ .filter(unique);
411
429
 
412
430
  if (item.score > 0) {
413
431
  needles.push(item);
@@ -429,11 +447,15 @@ function initializeSearch() {
429
447
  });
430
448
 
431
449
  needles.sort(function (a, b) {
432
- if (b.foundWords === a.foundWords) {
433
- return b.score - a.score;
450
+ if (b.foundTerms.length === a.foundTerms.length) {
451
+ if (b.foundWords === a.foundWords) {
452
+ return b.score - a.score;
453
+ }
454
+
455
+ return b.foundWords - a.foundWords;
434
456
  }
435
457
 
436
- return b.foundWords - a.foundWords;
458
+ return b.foundTerms.length - a.foundTerms.length;
437
459
  });
438
460
 
439
461
  const total = needles.reduce(function (accumulator, needle) {