view 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
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local new_error = Luan.new_error or error()
local ipairs = Luan.ipairs or error()
local Lucene = require "luan:lucene/Lucene.luan"
local Io = require "luan:Io.luan"
local uri = Io.uri or error()
local Http = require "luan:http/Http.luan"
local Thread = require "luan:Thread.luan"
local Time = require "luan:Time.luan"
local Logging = require "luan:logging/Logging.luan"
local logger = Logging.logger "Db"


local dir = uri("site:/private/local/lucene")

local Db = Lucene.index( dir, {
	log_dir = uri("site:/private/local/lucene_log")
	name = "lucene"
	version = 1
} )

Db.indexed_fields.user_email = Lucene.type.lowercase
Db.indexed_fields.user_name = Lucene.type.lowercase
Db.indexed_fields.user_registered = Lucene.type.long

Db.indexed_fields.link_owner_id = Lucene.type.long
Db.indexed_fields.link_user_id = Lucene.type.long
Db.indexed_fields.link_order = Lucene.type.float

Db.indexed_fields.pic_user_id = Lucene.type.long
Db.indexed_fields.pic_order = Lucene.type.float

Db.indexed_fields.icon_name = Lucene.type.string
Db.indexed_fields.icon_user_id = Lucene.type.long
Db.indexed_fields.icon_order = Lucene.type.float

function Db.not_in_transaction()
	logger.error(new_error("not in transaction"))
end

Db.restore_from_log()

Db.update{
	[1] = function()
		local docs = Db.search("type:pic",1,1000000)
		for _, doc in ipairs(docs) do
			if doc.title == nil then
				doc.title = "Error"
				Db.save(doc)
			end
		end
	end
}

if Http.is_serving then
	Thread.schedule( Db.check, { delay=0, repeating_delay=Time.period{hours=1} } )
end

return Db