Mercurial Hosting > luan
annotate examples/blog/src/lib/Db.luan @ 1427:a076e89a2879
remove literal
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 24 Nov 2019 18:23:57 -0700 |
parents | 732b5de211fc |
children | 82415c9c0015 |
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 | |
1220 | 13 local Db = {} |
596 | 14 |
1418 | 15 local postgres_spec = Hosted.postgres_spec() |
1396
a5f61890ad84
add check_postgres_password
Franklin Schmidt <fschmidt@gmail.com>
parents:
1395
diff
changeset
|
16 --logger.info(stringify(postgres_spec)) |
1395
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
17 |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
18 local function completer(doc) |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
19 return doc |
1387
bc40bc9aab3a
start postgres backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
1369
diff
changeset
|
20 end |
bc40bc9aab3a
start postgres backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
1369
diff
changeset
|
21 |
1224 | 22 function Db.new(lucene_dir) |
1369
709f7498a363
change Lucene.index() and add Lucene.recover()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1224
diff
changeset
|
23 local dir = Io.uri(lucene_dir) |
1395
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
24 local db = Lucene.index( dir, { |
1398 | 25 version = "2" |
1395
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
26 default_type = Lucene.type.english |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
27 default_fields = {"subject","content"} |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
28 completer = completer |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
29 postgres_spec = postgres_spec |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
30 } ) |
596 | 31 |
32 -- this is how you index a field | |
33 -- db.indexed_fields.post_date = Lucene.type.long | |
34 | |
35 return db | |
36 end | |
37 | |
1224 | 38 Db.db = Db.new("site:/private/local/lucene") |
1220 | 39 |
1397 | 40 Db.db.restore_from_postgres() |
1407 | 41 Thread.schedule( Db.db.check, { delay=0, repeating_delay=Time.period{hours=1}, id="blog-db-check" } ) |
1399 | 42 |
1220 | 43 return Db |