New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEATURE: include tag and category context in search #217
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,17 +154,33 @@ def process(**search_args) | |
end | ||
|
||
@last_num_results = posts.length | ||
# this is the general pattern from core | ||
# if there are millions of hidden tags it may fail | ||
hidden_tags = nil | ||
|
||
if posts.blank? | ||
{ args: search_args, rows: [], instruction: "nothing was found, expand your search" } | ||
else | ||
format_results(posts, args: search_args) do |post| | ||
{ | ||
category_names = [ | ||
post.topic.category&.parent_category&.name, | ||
post.topic.category&.name, | ||
].compact.join(" > ") | ||
row = { | ||
title: post.topic.title, | ||
url: Discourse.base_path + post.url, | ||
excerpt: post.excerpt, | ||
created: post.created_at, | ||
category: category_names, | ||
} | ||
|
||
if SiteSetting.tagging_enabled | ||
hidden_tags ||= DiscourseTagging.hidden_tag_names | ||
# using map over pluck to avoid n+1 (assuming caller preloading) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of assuming can we check whether the association is loaded or not? like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is the responsibility of Search or SemanticSearch ... but maybe we can raise a warning in case this happens. |
||
tags = post.topic.tags.map(&:name) - hidden_tags | ||
row[:tags] = tags.join(", ") if tags.present? | ||
end | ||
row | ||
end | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how the search command is executed in the background. Will it cause n+1 in category and parent_category attributes too?