-
-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
123 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
7.1.1+28fce6b04c414523280c53ee02f9f3a94d9d23da | ||
7.1.1+b44434ce9957d65f7a7052bfa2db201395d3c960 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { | ||
create, | ||
search as oramaSearch, | ||
insertMultiple, | ||
} from "https://cdn.jsdelivr.net/npm/@orama/orama@latest/+esm"; | ||
// "https://unpkg.com/browse/@orama/orama@latest/dist/esm/index.js"; | ||
// https://cdn.jsdelivr.net/npm/@orama/[email protected]/dist/esm/index.js | ||
|
||
|
||
//import { createTokenizer } from '@orama/tokenizers/japanese' | ||
//import { stopwords as japaneseStopwords } from "@orama/stopwords/japanese"; | ||
|
||
let searchEngine = null; | ||
|
||
async function init() { | ||
async function initIndex( index ){ | ||
searchEngine = await create({ | ||
schema: { | ||
title: 'string', | ||
content: 'string', | ||
uri: 'string', | ||
breadcrumb: 'string', | ||
description: 'string', | ||
tags: 'string[]', | ||
}, | ||
/* | ||
defaultLanguage: 'french', | ||
components: { | ||
tokenizer: { | ||
stemmingFn: stemmer, | ||
}, | ||
}, | ||
*/ | ||
}); | ||
await insertMultiple(searchEngine, index); | ||
|
||
window.relearn.isSearchEngineReady = true; | ||
window.relearn.executeInitialSearch(); | ||
} | ||
|
||
if( window.index_js_url ){ | ||
var js = document.createElement("script"); | ||
js.src = index_js_url; | ||
js.setAttribute("async", ""); | ||
js.onload = function(){ | ||
initIndex(relearn_searchindex); | ||
}; | ||
js.onerror = function(e){ | ||
console.error('Error getting Hugo index file'); | ||
}; | ||
document.head.appendChild(js); | ||
} | ||
} | ||
|
||
async function search( term ){ | ||
const searchResponse = await oramaSearch(searchEngine, {term: term, properties: '*'}); | ||
return searchResponse.hits.map( hit => ({ page: hit.document }) ); | ||
} | ||
|
||
export { init, search }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters