view examples/blog/src/lib/Db.luan @ 1428:d21a7cf8fa9e

fix postgres check
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 24 Nov 2019 21:02:38 -0700
parents 732b5de211fc
children 82415c9c0015
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 Hosted = require "luan:host/Hosted.luan"
local Time = require "luan:Time.luan"
local Thread = require "luan:Thread.luan"
local Logging = require "luan:logging/Logging.luan"
local logger = Logging.logger "Db"


local Db = {}

local postgres_spec = Hosted.postgres_spec()
--logger.info(stringify(postgres_spec))

local function completer(doc)
	return doc
end

function Db.new(lucene_dir)
	local dir = Io.uri(lucene_dir)
	local db = Lucene.index( dir, {
		version = "2"
		default_type = Lucene.type.english
		default_fields = {"subject","content"}
		completer = completer
		postgres_spec = postgres_spec
	} )
	
--	this is how you index a field
--	db.indexed_fields.post_date = Lucene.type.long

	return db
end

Db.db = Db.new("site:/private/local/lucene")

Db.db.restore_from_postgres()
Thread.schedule( Db.db.check, { delay=0, repeating_delay=Time.period{hours=1}, id="blog-db-check" } )

return Db