2020-12-28 05:01:07 +01:00
|
|
|
SELECT
|
|
|
|
posts.id,
|
|
|
|
posts.post_title,
|
|
|
|
posts.isanon,
|
|
|
|
authors.name,
|
2021-01-04 03:48:29 +01:00
|
|
|
posts.post_time,
|
|
|
|
posts.views
|
2020-12-28 05:01:07 +01:00
|
|
|
FROM
|
|
|
|
posts,authors
|
|
|
|
WHERE
|
|
|
|
authors.id = posts.authorid
|
2021-01-11 04:34:22 +01:00
|
|
|
AND posts.unlisted = 0
|
2020-12-28 05:01:07 +01:00
|
|
|
<% for field, values in pairs(result) do -%>
|
|
|
|
<% for _,value in pairs(values) do -%>
|
|
|
|
<% local pn,expr,value = unpack(value) -%>
|
|
|
|
<% local n = (pn == "+" and "" or "NOT") -%>
|
|
|
|
<% if field == "title" then -%>
|
|
|
|
AND <%= n %> posts.post_title LIKE ?
|
|
|
|
<% elseif field == "author" then -%>
|
|
|
|
AND <%= n %> authors.name LIKE ?
|
|
|
|
<% elseif field == "date" then -%>
|
|
|
|
AND <%= n %> posts.post_time <%- expr %> ?
|
|
|
|
<% elseif field == "hits" then -%>
|
|
|
|
AND posts.views <%- expr -%> ?
|
|
|
|
<% end -%>
|
|
|
|
<% end -%>
|
|
|
|
<% end -%>
|
|
|
|
<% for _,tag in pairs(result.tags) do -%>
|
|
|
|
INTERSECT
|
|
|
|
SELECT
|
|
|
|
posts.id,
|
|
|
|
posts.post_title,
|
|
|
|
posts.isanon,
|
|
|
|
authors.name,
|
2021-01-04 03:48:29 +01:00
|
|
|
posts.post_time,
|
|
|
|
posts.views
|
2020-12-28 05:01:07 +01:00
|
|
|
FROM
|
|
|
|
posts,authors,tags
|
|
|
|
WHERE
|
|
|
|
posts.authorid = authors.id
|
|
|
|
AND tags.postid = posts.id
|
|
|
|
<% local n,v,t = unpack(tag) -%>
|
|
|
|
<% n = (n == "-" and "NOT" or "") -%>
|
|
|
|
AND <%= n %> tags.tag = ?
|
|
|
|
<% end -%>
|
|
|
|
;
|