Mercurial Hosting > linkmystyle
comparison src/lib/Db.luan @ 0:8f4df159f06b
start public repo
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Fri, 11 Jul 2025 20:57:49 -0600 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:8f4df159f06b |
|---|---|
| 1 local Luan = require "luan:Luan.luan" | |
| 2 local error = Luan.error | |
| 3 local new_error = Luan.new_error or error() | |
| 4 local ipairs = Luan.ipairs or error() | |
| 5 local Lucene = require "luan:lucene/Lucene.luan" | |
| 6 local Io = require "luan:Io.luan" | |
| 7 local uri = Io.uri or error() | |
| 8 local Http = require "luan:http/Http.luan" | |
| 9 local Thread = require "luan:Thread.luan" | |
| 10 local Time = require "luan:Time.luan" | |
| 11 local Logging = require "luan:logging/Logging.luan" | |
| 12 local logger = Logging.logger "Db" | |
| 13 | |
| 14 | |
| 15 local dir = uri("site:/private/local/lucene") | |
| 16 | |
| 17 local Db = Lucene.index( dir, { | |
| 18 log_dir = uri("site:/private/local/lucene_log") | |
| 19 name = "lucene" | |
| 20 version = 1 | |
| 21 } ) | |
| 22 | |
| 23 Db.indexed_fields.user_email = Lucene.type.lowercase | |
| 24 Db.indexed_fields.user_name = Lucene.type.lowercase | |
| 25 Db.indexed_fields.user_registered = Lucene.type.long | |
| 26 | |
| 27 Db.indexed_fields.link_owner_id = Lucene.type.long | |
| 28 Db.indexed_fields.link_user_id = Lucene.type.long | |
| 29 Db.indexed_fields.link_order = Lucene.type.float | |
| 30 | |
| 31 Db.indexed_fields.pic_user_id = Lucene.type.long | |
| 32 Db.indexed_fields.pic_order = Lucene.type.float | |
| 33 | |
| 34 Db.indexed_fields.icon_name = Lucene.type.string | |
| 35 Db.indexed_fields.icon_user_id = Lucene.type.long | |
| 36 Db.indexed_fields.icon_order = Lucene.type.float | |
| 37 | |
| 38 function Db.not_in_transaction() | |
| 39 logger.error(new_error("not in transaction")) | |
| 40 end | |
| 41 | |
| 42 Db.restore_from_log() | |
| 43 | |
| 44 Db.update{ | |
| 45 [1] = function() | |
| 46 local docs = Db.search("type:pic",1,1000000) | |
| 47 for _, doc in ipairs(docs) do | |
| 48 if doc.title == nil then | |
| 49 doc.title = "Error" | |
| 50 Db.save(doc) | |
| 51 end | |
| 52 end | |
| 53 end | |
| 54 } | |
| 55 | |
| 56 if Http.is_serving then | |
| 57 Thread.schedule( Db.check, { delay=0, repeating_delay=Time.period{hours=1} } ) | |
| 58 end | |
| 59 | |
| 60 return Db |
