added basic full-text search support (flexsearch), still needs some work...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-11-03 23:48:53 +03:00
parent 8d0fcb5baa
commit 28fa71ff00
5 changed files with 48 additions and 2 deletions

View File

@ -5,6 +5,7 @@
"license": "BSD",
"dependencies": {
"@toast-ui/editor": "^3.2.0",
"flexsearch": "^0.7.31",
"glob": "*",
"idb-keyval": "^6.2.0",
"ig-actions": "*",

View File

@ -2325,7 +2325,22 @@ module.System = {
RecursionError: {
text: 'RECURSION ERROR: @source(../path)' },
NotFoundError: {
text: 'NOT FOUND ERROR: @source(./path)' },
//text: 'NOT FOUND ERROR: @source(./path)' },
text: object.doc`
<slot title/>
<p>NOT FOUND ERROR: @source(./path)</p>
<slot nested>
<div>
<b>Nested pages:</b><br>
<div style="padding-left: 30px">
<macro src="./*" join="<br>" else="@slot(nested)">
<a href="#@source(s ./path)">@source(./title)</a>
</macro>
</div>
</div>
</slot>` },
NotFoundTemplateError: {
text: 'NOT FOUND TEMPLATE ERROR: @source(../path)' },

View File

@ -7,6 +7,8 @@
(function(require){ var module={} // make module AMD/node compatible...
/*********************************************************************/
var flexsearch = require('flexsearch')
var object = require('ig-object')
var types = require('ig-types')
@ -296,6 +298,26 @@ module.BaseStore = {
// XXX text search index (???)
// XXX do we index .data.text or .raw or .text
__search: index.makeIndex('search',
async function(){
var index = new flexsearch.Index()
for(var path of (await this.paths)){
var text = (await this.get(path)).text
text
&& typeof(text) != 'function'
&& index.add(path, text) }
return index }, {
update: async function(data, path, update){
update.text
&& typeof(update.text) != 'function'
&& (await data).add(path, update.text)
return data },
remove: async function(data, path){
;(await data).remove(path)
return data }, }),
search: function(){
return this.__search().search(...arguments) },
//

View File

@ -234,6 +234,7 @@ require.config({
'pouchdb': 'node_modules/pouchdb/dist/pouchdb',
'showdown': 'node_modules/showdown/dist/showdown',
'idb-keyval': 'node_modules/idb-keyval/dist/umd',
'flexsearch': 'node_modules/flexsearch/dist/flexsearch.bundle',
}, ['ext-lib']),
},
packages: [

View File

@ -4,7 +4,7 @@
* XXX ASAP start writing docs in pwiki
* - minimal/functional editor - DONE
* - WYSIWYG markdown editor/viewer (ASAP) -
* - transparent sync
* - transparent sync/backup
* - fs store/export in browser or a simple way to export/import...
* ...can't seem to get it to work without asking for permission
* on every startup (one more thing left to try, keeping the
@ -17,6 +17,13 @@
* - GUI -
* - CLI -
*
* XXX things that will help:
* - async render (infinite scroll + search + large pages)
* unresolved -> dom placeholder
* iterator prepends to placeholder
* when resolved/done remove placeholder
* -
*
*
* XXX macro-vars: should the vars be defined as macro:<name> (current) or
* simply as <name>???