Patching Discourse's search

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.

9 Likes