annotate examples/blog/src/lib/Db.luan @ 1701:077366d117bb

use local luan
author Vadim Filimonov <fffilimonov@yandex.ru>
date Tue, 28 Jun 2022 17:59:19 +0300
parents 2958cf04d844
children fc224a1bb6ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
1672
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
6 local uri = Io.uri or error()
1399
Franklin Schmidt <fschmidt@gmail.com>
parents: 1398
diff changeset
7 local Time = require "luan:Time.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 1398
diff changeset
8 local Thread = require "luan:Thread.luan"
1672
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
9 local Hosted = require "luan:host/Hosted.luan"
1392
002152af497a hosted postgres
Franklin Schmidt <fschmidt@gmail.com>
parents: 1391
diff changeset
10 local Logging = require "luan:logging/Logging.luan"
002152af497a hosted postgres
Franklin Schmidt <fschmidt@gmail.com>
parents: 1391
diff changeset
11 local logger = Logging.logger "Db"
596
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
1672
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
14 if not Hosted.is_hosted then
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
15 require "java"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
16 local BackupIndexWriter = require "java:goodjava.lucene.backup.BackupIndexWriter"
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
17 BackupIndexWriter.backupDomains = {"localhost"}
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
18 end
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
19
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
20 local dir = uri("site:/private/local/lucene")
1429
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"}
1672
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
24 log_dir = uri("site:/private/local/lucene_log")
1429
82415c9c0015 move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents: 1418
diff changeset
25 } )
82415c9c0015 move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents: 1418
diff changeset
26
596
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 -- this is how you index a field
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 -- db.indexed_fields.post_date = Lucene.type.long
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29
1672
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
30 Db.restore_from_log()
1429
82415c9c0015 move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents: 1418
diff changeset
31 Db.update{
82415c9c0015 move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents: 1418
diff changeset
32 [1] = function()
82415c9c0015 move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents: 1418
diff changeset
33 logger.info "update"
82415c9c0015 move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents: 1418
diff changeset
34 end
82415c9c0015 move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents: 1418
diff changeset
35 }
82415c9c0015 move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents: 1418
diff changeset
36 Thread.schedule( Db.check, { delay=0, repeating_delay=Time.period{hours=1}, id="blog-db-check" } )
1399
Franklin Schmidt <fschmidt@gmail.com>
parents: 1398
diff changeset
37
1220
4721c482c86b cleaner Db example
Franklin Schmidt <fschmidt@gmail.com>
parents: 1088
diff changeset
38 return Db