diff blog/src/lib/Post.luan @ 599:50540f0813e2

support default search fields in lucene; add search to blog;
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 16 Sep 2015 20:55:49 -0600
parents 6bb0c83116e9
children b73f005f3735
line wrap: on
line diff
--- a/blog/src/lib/Post.luan	Wed Sep 16 14:32:52 2015 -0600
+++ b/blog/src/lib/Post.luan	Wed Sep 16 20:55:49 2015 -0600
@@ -4,6 +4,8 @@
 local assert_string = Luan.assert_string or error()
 local Time = require "luan:Time"
 local now = Time.now or error()
+local String = require "luan:String"
+local trim = String.trim or error()
 local Db = require "site:/lib/Db"
 
 
@@ -52,4 +54,17 @@
 	return posts
 end
 
+function M.search(query)
+	query = trim(query)
+	if #query == 0 then
+		return M.get_all()
+	end
+	local docs = Db.search(query,1,1000)
+	local posts = {}
+	for _, doc in ipairs(docs) do
+		posts[#posts+1] = from_doc(doc)
+	end
+	return posts
+end
+
 return M