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: mark highlight search #2370

Merged
merged 7 commits into from
Jan 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/controllers/avo/search_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require_dependency "avo/application_controller"

include ActionView::Helpers::TextHelper

Check failure on line 3 in app/controllers/avo/search_controller.rb

View workflow job for this annotation

GitHub Actions / lint / runner / standardrb

[rubocop] reported by reviewdog 🐶 Style/MixinUsage: include is used at the top level. Use inside class or module. Raw Output: app/controllers/avo/search_controller.rb:3:1: C: Style/MixinUsage: include is used at the top level. Use inside class or module. include ActionView::Helpers::TextHelper ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gabrielgiroe1 marked this conversation as resolved.
Show resolved Hide resolved

module Avo
class SearchController < ApplicationController
include Rails.application.routes.url_helpers
Expand Down Expand Up @@ -61,13 +63,21 @@
result_object = {
header: header,
help: resource.fetch_search(:help) || "",
results: results,
results: highlight_search_results(results, params[:q]),
gabrielgiroe1 marked this conversation as resolved.
Show resolved Hide resolved
count: results.count
}

[resource.name.pluralize.downcase, result_object]
end

gabrielgiroe1 marked this conversation as resolved.
Show resolved Hide resolved
def highlight_search_results(results, search_term)
results.map do |result|
result.transform_values do |value|
highlight(value.to_s, search_term)
end
end
end

# When searching in a `has_many` association and will scope out the records against the parent record.
# This is also used when looking for `belongs_to` associations, and this method applies the parents `attach_scope` if present.
def apply_scope(query)
Expand Down