Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
598:e930f92d0f61 | 599:50540f0813e2 |
---|---|
2 local error = Luan.error | 2 local error = Luan.error |
3 local ipairs = Luan.ipairs or error() | 3 local ipairs = Luan.ipairs or error() |
4 local assert_string = Luan.assert_string or error() | 4 local assert_string = Luan.assert_string or error() |
5 local Time = require "luan:Time" | 5 local Time = require "luan:Time" |
6 local now = Time.now or error() | 6 local now = Time.now or error() |
7 local String = require "luan:String" | |
8 local trim = String.trim or error() | |
7 local Db = require "site:/lib/Db" | 9 local Db = require "site:/lib/Db" |
8 | 10 |
9 | 11 |
10 local M = {} | 12 local M = {} |
11 | 13 |
50 posts[#posts+1] = from_doc(doc) | 52 posts[#posts+1] = from_doc(doc) |
51 end | 53 end |
52 return posts | 54 return posts |
53 end | 55 end |
54 | 56 |
57 function M.search(query) | |
58 query = trim(query) | |
59 if #query == 0 then | |
60 return M.get_all() | |
61 end | |
62 local docs = Db.search(query,1,1000) | |
63 local posts = {} | |
64 for _, doc in ipairs(docs) do | |
65 posts[#posts+1] = from_doc(doc) | |
66 end | |
67 return posts | |
68 end | |
69 | |
55 return M | 70 return M |