view examples/blog/src/lib/Db.luan @ 1696:2958cf04d844

remove postgres backup
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 26 Jun 2022 14:40:08 -0600
parents 8dd8c556c449
children fc224a1bb6ea
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local stringify = Luan.stringify or error()
local Lucene = require "luan:lucene/Lucene.luan"
local Io = require "luan:Io.luan"
local uri = Io.uri or error()
local Time = require "luan:Time.luan"
local Thread = require "luan:Thread.luan"
local Hosted = require "luan:host/Hosted.luan"
local Logging = require "luan:logging/Logging.luan"
local logger = Logging.logger "Db"


if not Hosted.is_hosted then
	require "java"
	local BackupIndexWriter = require "java:goodjava.lucene.backup.BackupIndexWriter"
	BackupIndexWriter.backupDomains = {"localhost"}
end

local dir = uri("site:/private/local/lucene")
local Db = Lucene.index( dir, {
	default_type = Lucene.type.english
	default_fields = {"subject","content"}
	log_dir = uri("site:/private/local/lucene_log")
} )

--	this is how you index a field
--	db.indexed_fields.post_date = Lucene.type.long

Db.restore_from_log()
Db.update{
	[1] = function()
		logger.info "update"
	end
}
Thread.schedule( Db.check, { delay=0, repeating_delay=Time.period{hours=1}, id="blog-db-check" } )

return Db