comparison examples/blog/src/lib/Db.luan @ 1429:82415c9c0015

move versioning into Lucene
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 24 Nov 2019 23:07:21 -0700
parents 732b5de211fc
children 13135e289b50
comparison
equal deleted inserted replaced
1428:d21a7cf8fa9e 1429:82415c9c0015
8 local Thread = require "luan:Thread.luan" 8 local Thread = require "luan:Thread.luan"
9 local Logging = require "luan:logging/Logging.luan" 9 local Logging = require "luan:logging/Logging.luan"
10 local logger = Logging.logger "Db" 10 local logger = Logging.logger "Db"
11 11
12 12
13 local Db = {}
14
15 local postgres_spec = Hosted.postgres_spec() 13 local postgres_spec = Hosted.postgres_spec()
16 --logger.info(stringify(postgres_spec)) 14 --logger.info(stringify(postgres_spec))
17 15
18 local function completer(doc) 16 local function completer(doc)
19 return doc 17 return doc
20 end 18 end
21 19
22 function Db.new(lucene_dir) 20 local dir = Io.uri("site:/private/local/lucene")
23 local dir = Io.uri(lucene_dir) 21 local Db = Lucene.index( dir, {
24 local db = Lucene.index( dir, { 22 default_type = Lucene.type.english
25 version = "2" 23 default_fields = {"subject","content"}
26 default_type = Lucene.type.english 24 completer = completer
27 default_fields = {"subject","content"} 25 postgres_spec = postgres_spec
28 completer = completer 26 } )
29 postgres_spec = postgres_spec 27
30 } )
31
32 -- this is how you index a field 28 -- this is how you index a field
33 -- db.indexed_fields.post_date = Lucene.type.long 29 -- db.indexed_fields.post_date = Lucene.type.long
34 30
35 return db 31 Db.restore_from_postgres()
36 end 32 Db.update{
37 33 [1] = function()
38 Db.db = Db.new("site:/private/local/lucene") 34 logger.info "update"
39 35 end
40 Db.db.restore_from_postgres() 36 }
41 Thread.schedule( Db.db.check, { delay=0, repeating_delay=Time.period{hours=1}, id="blog-db-check" } ) 37 Thread.schedule( Db.check, { delay=0, repeating_delay=Time.period{hours=1}, id="blog-db-check" } )
42 38
43 return Db 39 return Db