Mercurial Hosting > luan
annotate examples/blog/src/lib/Db.luan @ 1499:22e15cf73040
lucene.backup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 09 May 2020 23:14:13 -0600 |
parents | 82415c9c0015 |
children | 13135e289b50 |
rev | line source |
---|---|
1396
a5f61890ad84
add check_postgres_password
Franklin Schmidt <fschmidt@gmail.com>
parents:
1395
diff
changeset
|
1 local Luan = require "luan:Luan.luan" |
a5f61890ad84
add check_postgres_password
Franklin Schmidt <fschmidt@gmail.com>
parents:
1395
diff
changeset
|
2 local error = Luan.error |
a5f61890ad84
add check_postgres_password
Franklin Schmidt <fschmidt@gmail.com>
parents:
1395
diff
changeset
|
3 local stringify = Luan.stringify or error() |
693
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
599
diff
changeset
|
4 local Lucene = require "luan:lucene/Lucene.luan" |
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
599
diff
changeset
|
5 local Io = require "luan:Io.luan" |
1418 | 6 local Hosted = require "luan:host/Hosted.luan" |
1399 | 7 local Time = require "luan:Time.luan" |
8 local Thread = require "luan:Thread.luan" | |
1392 | 9 local Logging = require "luan:logging/Logging.luan" |
10 local logger = Logging.logger "Db" | |
596 | 11 |
12 | |
1418 | 13 local postgres_spec = Hosted.postgres_spec() |
1396
a5f61890ad84
add check_postgres_password
Franklin Schmidt <fschmidt@gmail.com>
parents:
1395
diff
changeset
|
14 --logger.info(stringify(postgres_spec)) |
1395
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
15 |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
16 local function completer(doc) |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
17 return doc |
1387
bc40bc9aab3a
start postgres backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
1369
diff
changeset
|
18 end |
bc40bc9aab3a
start postgres backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
1369
diff
changeset
|
19 |
1429
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
20 local dir = Io.uri("site:/private/local/lucene") |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
21 local Db = Lucene.index( dir, { |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
22 default_type = Lucene.type.english |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
23 default_fields = {"subject","content"} |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
24 completer = completer |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
25 postgres_spec = postgres_spec |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
26 } ) |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
27 |
596 | 28 -- this is how you index a field |
29 -- db.indexed_fields.post_date = Lucene.type.long | |
30 | |
1429
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
31 Db.restore_from_postgres() |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
32 Db.update{ |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
33 [1] = function() |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
34 logger.info "update" |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
35 end |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
36 } |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1418
diff
changeset
|
37 Thread.schedule( Db.check, { delay=0, repeating_delay=Time.period{hours=1}, id="blog-db-check" } ) |
1399 | 38 |
1220 | 39 return Db |