Fix a bug where the search pages did not show comments

When comments were added, the search page was not modified
appropriately.
This commit is contained in:
Robin Malley 2023-03-12 05:29:36 +00:00
parent 5c5637ff40
commit f83bf55d3f
2 changed files with 12 additions and 3 deletions

View File

@ -54,7 +54,8 @@ local function search_get(req)
author = row[4],
posted = os.date("%B %d %Y",tonumber(row[5])),
tags = libtags.get(row[1]),
hits = row[6]
hits = row[6],
ncomments = row[7]
})
end
local ret = pages.search{

View File

@ -4,9 +4,11 @@ SELECT
posts.isanon,
authors.name,
posts.post_time,
posts.views
posts.views,
COUNT(comments.id)
FROM
posts,authors
LEFT JOIN comments ON comments.postid = posts.id
WHERE
authors.id = posts.authorid
AND posts.unlisted = 0
@ -25,6 +27,8 @@ WHERE
<% end -%>
<% end -%>
<% end -%>
GROUP BY
posts.id
<% for _,tag in pairs(result.tags) do -%>
INTERSECT
SELECT
@ -33,9 +37,11 @@ SELECT
posts.isanon,
authors.name,
posts.post_time,
posts.views
posts.views,
COUNT(comments.id)
FROM
posts,authors,tags
LEFT JOIN comments ON comments.postid = posts.id
WHERE
posts.authorid = authors.id
AND tags.postid = posts.id
@ -43,4 +49,6 @@ WHERE
<% n = (n == "-" and "NOT" or "") -%>
AND <%= n %> tags.tag = ?
<% end -%>
GROUP BY
posts.id
;