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], author = row[4],
posted = os.date("%B %d %Y",tonumber(row[5])), posted = os.date("%B %d %Y",tonumber(row[5])),
tags = libtags.get(row[1]), tags = libtags.get(row[1]),
hits = row[6] hits = row[6],
ncomments = row[7]
}) })
end end
local ret = pages.search{ local ret = pages.search{

View File

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