Mercurial Hosting > luan
annotate examples/blog/src/lib/Db.luan @ 1395:9dfff82dfc59
finish postgres work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 09 Sep 2019 01:22:23 -0600 |
parents | cc0dbca576dc |
children | a5f61890ad84 |
rev | line source |
---|---|
693
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
599
diff
changeset
|
1 local Lucene = require "luan:lucene/Lucene.luan" |
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
599
diff
changeset
|
2 local Io = require "luan:Io.luan" |
1392 | 3 local Hosting = require "luan:host/Hosting.luan" |
4 local Logging = require "luan:logging/Logging.luan" | |
5 local logger = Logging.logger "Db" | |
596 | 6 |
7 | |
1220 | 8 local Db = {} |
596 | 9 |
1392 | 10 local postgres_spec = Hosting.postgres_spec and Hosting.postgres_spec() |
1395
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
11 |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
12 local function completer(doc) |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
13 return doc |
1387
bc40bc9aab3a
start postgres backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
1369
diff
changeset
|
14 end |
bc40bc9aab3a
start postgres backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
1369
diff
changeset
|
15 |
1224 | 16 function Db.new(lucene_dir) |
1369
709f7498a363
change Lucene.index() and add Lucene.recover()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1224
diff
changeset
|
17 local dir = Io.uri(lucene_dir) |
1395
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
18 local db = Lucene.index( dir, { |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
19 default_type = Lucene.type.english |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
20 default_fields = {"subject","content"} |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
21 completer = completer |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
22 postgres_spec = postgres_spec |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
23 } ) |
596 | 24 |
25 -- this is how you index a field | |
26 -- db.indexed_fields.post_date = Lucene.type.long | |
27 | |
28 return db | |
29 end | |
30 | |
1224 | 31 Db.db = Db.new("site:/private/local/lucene") |
1220 | 32 |
1388
2024d23ddd64
add restore_from_postgres
Franklin Schmidt <fschmidt@gmail.com>
parents:
1387
diff
changeset
|
33 --Db.db.restore_from_postgres() |
1391 | 34 Db.db.check() |
1220 | 35 return Db |