Make page score configurable for search results

This commit is contained in:
Ben Edgington
2023-01-10 10:58:53 +00:00
parent f5ce56aa6c
commit 4708dd1810
4 changed files with 6 additions and 4 deletions

View File

@@ -98,7 +98,7 @@ module.exports = {
{query: 'li', label: 'List item'},
{query: 'pre', label: 'Code'},
{query: 'table', label: 'Table'},
{query: 'h3, h4, h5, h6', label: 'Heading'},
{query: 'h3, h4, h5, h6', label: 'Heading', weight: 5},
{query: 'p', label: 'Paragraph'},
],
exclude: {

View File

@@ -50,6 +50,7 @@ const getChunks = ($, node, chunkTypes, exclude, counts) => {
label: type.label,
id: id,
text: text,
weight: type.weight === undefined ? 1 : type.weight,
})
}
break

View File

@@ -19,7 +19,7 @@ const getSearchResults = (query, data) => {
const result = data.map( ({ node }) => {
let score = 0
let pageScore = 0
const matches = []
for (let i = 0; i < node.chunks?.length; i++) {
@@ -40,7 +40,7 @@ const getSearchResults = (query, data) => {
indices: indices,
}
)
score += indices.length
pageScore += chunk.weight * indices.length
}
}
@@ -48,7 +48,7 @@ const getSearchResults = (query, data) => {
url: node.frontmatter.path,
title: node.frontmatter.titles.filter(x => x).join(' | '),
matches: matches,
score: score,
score: pageScore,
}
})

View File

@@ -50,6 +50,7 @@
padding: 0.5rem;
background: var(--search-chunk-background);
border-radius: 0.75rem;
font-size: 1.1rem;
}
#search-results a.label {