mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-29 10:00:08 +00:00
added persistent search index, still experimenting...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
1efe56bfe3
commit
5446537a33
@ -120,6 +120,7 @@ module.BaseStore = {
|
||||
set data(value){
|
||||
this.__data = value },
|
||||
|
||||
__cache_path__: '.cache',
|
||||
// XXX not sure if it is better to set these here or use index.IndexManagerMixin(..)
|
||||
get index_attrs(){
|
||||
return [...index.iter(this)] },
|
||||
@ -300,14 +301,23 @@ module.BaseStore = {
|
||||
},
|
||||
//*/
|
||||
__search: index.makeIndex('search',
|
||||
// XXX do a load if present...
|
||||
async function(){
|
||||
var index = new flexsearch.Index(
|
||||
this.__search_options
|
||||
?? {})
|
||||
var update = this.__search.options.update
|
||||
for(var path of (await this.paths)){
|
||||
update.call(this, index, path, await this.get(path)) }
|
||||
var path = this.__cache_path__ +'/search'
|
||||
// load index...
|
||||
if(this.__cache_path__
|
||||
&& await this.exists(path)){
|
||||
return this.__search.options.load()
|
||||
// generate...
|
||||
} else {
|
||||
var index = new flexsearch.Index(
|
||||
this.__search_options
|
||||
?? {})
|
||||
var update = this.__search.options.update
|
||||
for(var path of (await this.paths)){
|
||||
update.call(this, index, path, await this.get(path)) } }
|
||||
return index }, {
|
||||
// XXX do a save???
|
||||
update: async function(data, path, update){
|
||||
var {text, tags} = update
|
||||
text = [
|
||||
@ -322,8 +332,43 @@ module.BaseStore = {
|
||||
].join('\n\n')
|
||||
;(await data).add(path, update.text)
|
||||
return data },
|
||||
// XXX do a save???
|
||||
remove: async function(data, path){
|
||||
;(await data).remove(path)
|
||||
return data },
|
||||
// XXX EXPERIMENTAL...
|
||||
save: async function(data){
|
||||
if(this.__cache_path__){
|
||||
var that = this
|
||||
var path = this.__cache_path__ +'/search'
|
||||
/*/ XXX this thing runs async but does not return a promise...
|
||||
var index = {}
|
||||
data.export(
|
||||
function(key, value){
|
||||
index[key] = value })
|
||||
this.update(path, {index})
|
||||
/*/
|
||||
// XXX this is quote ugly but can't figure out a way to
|
||||
// track when exporting is done...
|
||||
var index = {}
|
||||
data.export(
|
||||
function(key, value){
|
||||
index[key] = value
|
||||
return that.update(path, {index}) })
|
||||
//*/
|
||||
}
|
||||
return data },
|
||||
load: async function(data){
|
||||
if(this.__cache_path__){
|
||||
var path = this.__cache_path__ +'/search'
|
||||
var {index} =
|
||||
await this.get(path)
|
||||
?? {index: {}}
|
||||
var data = new flexsearch.Index(
|
||||
this.__search_options
|
||||
?? {})
|
||||
for(var [key, value] of Object.entries(index)){
|
||||
data.import(key, value) } }
|
||||
return data }, }),
|
||||
search: function(){
|
||||
return this.__search().search(...arguments) },
|
||||
|
||||
13
pwiki2.js
13
pwiki2.js
@ -25,12 +25,15 @@
|
||||
* -
|
||||
*
|
||||
*
|
||||
* XXX stored index cache: need to define the save/load strategy + stored
|
||||
* cache validation...
|
||||
* XXX FEATURE: to avoid reinventing the wheel, serialize stuff as pages...
|
||||
* something like:
|
||||
* /.index/<name>
|
||||
* would be logical for indexes or:
|
||||
* /.data/<name>
|
||||
* for general stuff...
|
||||
* .paths - ???
|
||||
* .names - ???
|
||||
* .tags -
|
||||
* .search() - DONE
|
||||
* XXX index: pass name to all the handlers...
|
||||
* ...this will simplify generic handlers...
|
||||
* XXX macro: macro:count / macro:index vars can be overridden by count/index
|
||||
* attributes....
|
||||
* ...this needs testing...
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user