Mercurial Hosting > luan
annotate examples/blog/src/lib/Db.luan @ 1398:67c0e47b5be3
more lucene
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 11 Sep 2019 15:48:49 -0600 |
parents | 0dc9837c16be |
children | 38a1c1b4279a |
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" |
1392 | 6 local Hosting = require "luan:host/Hosting.luan" |
7 local Logging = require "luan:logging/Logging.luan" | |
8 local logger = Logging.logger "Db" | |
596 | 9 |
10 | |
1220 | 11 local Db = {} |
596 | 12 |
1392 | 13 local postgres_spec = Hosting.postgres_spec and Hosting.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 |
1224 | 20 function Db.new(lucene_dir) |
1369
709f7498a363
change Lucene.index() and add Lucene.recover()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1224
diff
changeset
|
21 local dir = Io.uri(lucene_dir) |
1395
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
22 local db = Lucene.index( dir, { |
1398 | 23 version = "2" |
1395
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
24 default_type = Lucene.type.english |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
25 default_fields = {"subject","content"} |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
26 completer = completer |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
27 postgres_spec = postgres_spec |
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1393
diff
changeset
|
28 } ) |
596 | 29 |
30 -- this is how you index a field | |
31 -- db.indexed_fields.post_date = Lucene.type.long | |
32 | |
33 return db | |
34 end | |
35 | |
1224 | 36 Db.db = Db.new("site:/private/local/lucene") |
1220 | 37 |
1397 | 38 Db.db.restore_from_postgres() |
1391 | 39 Db.db.check() |
1220 | 40 return Db |