1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-08-12 09:04:35 +02:00

result highlighting

This commit is contained in:
Thomas Wilkerling
2025-03-14 21:36:13 +01:00
parent 114303831c
commit baf0faaf81
54 changed files with 2220 additions and 1685 deletions

View File

@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-module-document-highlighting</title>
</head>
<body style="white-space: pre">
<script type="module">
import { Document, Charset } from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.compact.module.min.js";
// some test data
const data = [{
"id": 1,
"title": "Carmencita"
},{
"id": 2,
"title": "Le clown et ses chiens"
}];
// create the document index
const index = new Document({
document: {
id: "tconst",
store: true,
index: [{
field: "title",
tokenize: "forward",
encoder: Charset.LatinBalance
}]
}
});
// add test data
for(let i = 0; i < data.length; i++){
index.add(data[i]);
}
// perform a query
const result = index.search({
query: "karmen or clown or not found",
suggest: true,
// set enrich to true (required)
enrich: true,
// highlight template
// $1 is a placeholder for the matched partial
highlight: "<b>$1</b>"
});
// display results
console.log(suggestions);
log(JSON.stringify(suggestions, null, 2));
function log(str){
document.body.appendChild(
document.createTextNode(str + "\n")
);
}
</script>
</body>
</html>