diff src/lib/Db.luan @ 1:bd2abcd7190a

mostly done
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 20 Sep 2022 19:40:39 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/Db.luan	Tue Sep 20 19:40:39 2022 -0600
@@ -0,0 +1,40 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local Io = require "luan:Io.luan"
+local uri = Io.uri or error()
+local Table = require "luan:Table.luan"
+local concat = Table.concat or error()
+local Lucene = require "luan:lucene/Lucene.luan"
+local Shared = require "site:/lib/Shared.luan"
+local to_list = Shared.to_list or error()
+
+
+local function supplementer(doc)
+	local t = {}
+	t[#t+1] = doc.user_name
+	if doc.category ~= nil then
+		t[#t+1] = concat(to_list(doc.category)," ")
+	end
+	t[#t+1] = doc.description
+	return {
+		free = concat(t," ")
+	}
+end
+
+local dir = uri("site:/lucene")
+
+local options = {
+	supplementer = supplementer
+	default_type = Lucene.type.english
+	default_fields = {"free"}
+}
+
+local Db = Lucene.index(dir,options)
+
+Db.indexed_fields.free = Lucene.type.english
+Db.indexed_fields.user_id = Lucene.type.string
+Db.indexed_fields.user_name = Lucene.type.english
+Db.indexed_fields.category = Lucene.type.english
+Db.indexed_fields.description = Lucene.type.english
+
+return Db