astro-accelerator 0.3.23 → 0.3.25
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 +21 -10
package/package.json
CHANGED
package/public/js/search.js
CHANGED
|
@@ -324,6 +324,7 @@ async function search(s, r) {
|
|
|
324
324
|
cleanQuery.length > 0 && haystack.forEach( (item) => {
|
|
325
325
|
|
|
326
326
|
let foundWords = 0;
|
|
327
|
+
let isPhraseFound = false;
|
|
327
328
|
item.score = 0;
|
|
328
329
|
item.matchedHeadings = [];
|
|
329
330
|
|
|
@@ -334,6 +335,7 @@ async function search(s, r) {
|
|
|
334
335
|
// Title
|
|
335
336
|
if (contains(item.safeTitle, currentQuery)) {
|
|
336
337
|
item.score = item.score + scoring.phraseTitle;
|
|
338
|
+
isPhraseFound = true;
|
|
337
339
|
}
|
|
338
340
|
|
|
339
341
|
// Headings
|
|
@@ -341,19 +343,24 @@ async function search(s, r) {
|
|
|
341
343
|
if (contains(c.safeText, currentQuery)) {
|
|
342
344
|
item.score = item.score + scoring.phraseHeading;
|
|
343
345
|
item.matchedHeadings.push(c);
|
|
346
|
+
isPhraseFound = true;
|
|
344
347
|
}
|
|
345
348
|
});
|
|
346
349
|
|
|
347
350
|
// Description
|
|
348
351
|
if (contains(item.description, currentQuery)) {
|
|
349
352
|
item.score = item.score + scoring.phraseDescription;
|
|
353
|
+
isPhraseFound = true;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (isPhraseFound) {
|
|
357
|
+
foundWords++;
|
|
350
358
|
}
|
|
351
359
|
|
|
352
360
|
// Part 2 - Term Matches, i.e. "Kitchen" or "Sink"
|
|
353
361
|
|
|
354
362
|
allTerms.forEach(term => {
|
|
355
363
|
let isTermFound = false;
|
|
356
|
-
const isUserTerm = queryTerms.includes(term);
|
|
357
364
|
|
|
358
365
|
// Title
|
|
359
366
|
if (contains(item.safeTitle, term)) {
|
|
@@ -398,22 +405,25 @@ async function search(s, r) {
|
|
|
398
405
|
}
|
|
399
406
|
});
|
|
400
407
|
|
|
401
|
-
item.foundWords = foundWords
|
|
408
|
+
item.foundWords = foundWords;
|
|
402
409
|
|
|
403
410
|
if (item.score > 0) {
|
|
404
411
|
needles.push(item);
|
|
405
412
|
}
|
|
406
413
|
});
|
|
407
414
|
|
|
408
|
-
const maxDepth = needles
|
|
409
|
-
.reduce(function (previous, current) {
|
|
410
|
-
return (current.depth > previous.depth) ? current : previous
|
|
411
|
-
})
|
|
412
|
-
.depth;
|
|
413
|
-
|
|
414
415
|
needles.forEach(n => {
|
|
415
416
|
// Bonus points for shallow results, i.e. /features over /features/something/something
|
|
416
|
-
|
|
417
|
+
|
|
418
|
+
if (n.depth < 5) {
|
|
419
|
+
n.score += scoring.depth;
|
|
420
|
+
n.foundWords++;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (n.depth < 4) {
|
|
424
|
+
n.score += scoring.depth;
|
|
425
|
+
n.foundWords++;
|
|
426
|
+
}
|
|
417
427
|
});
|
|
418
428
|
|
|
419
429
|
needles.sort(function (a, b){
|
|
@@ -460,7 +470,8 @@ async function search(s, r) {
|
|
|
460
470
|
markers.innerHTML = highlight(needle.description, queryTerms);
|
|
461
471
|
|
|
462
472
|
const li = document.createElement('li');
|
|
463
|
-
li.dataset.
|
|
473
|
+
li.dataset.words = needle.foundWords.toString();
|
|
474
|
+
li.dataset.score = (Math.round((needle.score/ total) * 1000) / 1000).toString();
|
|
464
475
|
li.appendChild(a);
|
|
465
476
|
li.appendChild(path);
|
|
466
477
|
li.appendChild(markers);
|