Skip to content
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: process search results #3310

Merged
merged 1 commit into from
Oct 5, 2024
Merged

Conversation

adrianthedev
Copy link
Collaborator

@adrianthedev adrianthedev commented Oct 5, 2024

Description

Fixes #3301
Related PR: https://github.com/avo-hq/avo-pro/pull/92

You can now monkeypatch the process_results method with something like this:

# avo.rb initializer
Rails.configuration.to_prepare do
  Avo::SearchController.prepend SearchControllerExtensions
end

# app/controllers/concerns/search_controller_extensions.rb
module SearchControllerExtensions
  def process_results(resources, request: nil)
    regex = /.*\/resources\/(.*).*/

      if request&.referrer.present?
        resource_path = request.referrer.match(regex).captures.first

        if resource_path.present?
          resource_class = Avo.resource_manager.get_resource_by_plural_name resource_path
        end
      end
    results = super
	#  {"posts": {...}, "users": {...}
    
    # process results somehow to make the resource you want stand out

    # return the results
	results
  end
end

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Copy link

codeclimate bot commented Oct 5, 2024

Code Climate has analyzed commit 93ba273 and detected 0 issues on this pull request.

View more on Code Climate.

@adrianthedev adrianthedev merged commit a53f9a0 into main Oct 5, 2024
23 checks passed
@adrianthedev adrianthedev deleted the feature/search-process-results branch October 5, 2024 14:45
Copy link
Contributor

github-actions bot commented Oct 5, 2024

This PR has been merged into main. The functionality will be available in the next release.

Please check the release guide for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

global search resource ordering / priority to currently open resource
1 participant