I’m writing a plugin which stores some extra data against each user (similar to discourse-user-notes, but not staff-only), and would like to be able to search against this.
Presumably this involves patching something in lib/search.rb. I’m aware the Algolia search plugin overrides what appears in the search box popup, but ideally, I’d like this to affect the actual results page too.
Does anyone have any suggestions on where to start?
You can extend search from your plugin, for example you could add an advanced filter like this:
require_dependency 'search'
if Search.respond_to? :advanced_filter
Search.advanced_filter(/with:video/) do |posts|
posts.where("posts.cooked LIKE '%<video %'")
end
end
The above will only display posts containing videos when the search box includes the with:video keyword. See also the badge advanced filter for an example of a search query that takes user data into account.
On the subject, will PluginStore scale well here? I imagine this’ll lead to a lot of full scans (in the absence of a LIKE-friendly index on keys), so would it be better to create a 1-1 table for the extra user data?