mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-31 02:50: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){ | 	set data(value){ | ||||||
| 		this.__data = value }, | 		this.__data = value }, | ||||||
| 
 | 
 | ||||||
|  | 	__cache_path__: '.cache', | ||||||
| 	// XXX not sure if it is better to set these here or use index.IndexManagerMixin(..)
 | 	// XXX not sure if it is better to set these here or use index.IndexManagerMixin(..)
 | ||||||
| 	get index_attrs(){ | 	get index_attrs(){ | ||||||
| 		return [...index.iter(this)] }, | 		return [...index.iter(this)] }, | ||||||
| @ -300,14 +301,23 @@ module.BaseStore = { | |||||||
| 	}, | 	}, | ||||||
| 	//*/
 | 	//*/
 | ||||||
| 	__search: index.makeIndex('search', | 	__search: index.makeIndex('search', | ||||||
|  | 		// XXX do a load if present...
 | ||||||
| 		async function(){ | 		async function(){ | ||||||
| 			var index = new flexsearch.Index( | 			var path = this.__cache_path__ +'/search' | ||||||
| 				this.__search_options  | 			// load index...
 | ||||||
| 					?? {})  | 			if(this.__cache_path__  | ||||||
| 			var update = this.__search.options.update | 					&& await this.exists(path)){ | ||||||
| 			for(var path of (await this.paths)){ | 				return this.__search.options.load() | ||||||
| 				update.call(this, index, path, await this.get(path)) } | 			// 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 }, { | 			return index }, { | ||||||
|  | 		// XXX do a save???
 | ||||||
| 		update: async function(data, path, update){ | 		update: async function(data, path, update){ | ||||||
| 			var {text, tags} = update | 			var {text, tags} = update | ||||||
| 			text = [ | 			text = [ | ||||||
| @ -322,8 +332,43 @@ module.BaseStore = { | |||||||
| 			].join('\n\n') | 			].join('\n\n') | ||||||
| 			;(await data).add(path, update.text)  | 			;(await data).add(path, update.text)  | ||||||
| 			return data }, | 			return data }, | ||||||
|  | 		// XXX do a save???
 | ||||||
| 		remove: async function(data, path){ | 		remove: async function(data, path){ | ||||||
| 			;(await data).remove(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 }, }), | 			return data }, }), | ||||||
| 	search: function(){ | 	search: function(){ | ||||||
| 		return this.__search().search(...arguments) }, | 		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... | * XXX FEATURE: to avoid reinventing the wheel, serialize stuff as pages... | ||||||
| * 		something like: | * 		.paths					- ??? | ||||||
| * 			/.index/<name> | * 		.names					- ??? | ||||||
| * 		would be logical for indexes or: | * 		.tags					-  | ||||||
| * 			/.data/<name> | * 		.search()				- DONE | ||||||
| * 		for general stuff... | * 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  | * XXX macro: macro:count / macro:index vars can be overridden by count/index  | ||||||
| * 		attributes.... | * 		attributes.... | ||||||
| * 		...this needs testing... | * 		...this needs testing... | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user