Skip to content

Commit

Permalink
Highlight matched search terms
Browse files Browse the repository at this point in the history
  • Loading branch information
samrat committed Jan 24, 2025
1 parent 70ec40d commit 3d9a7d5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/components/all_releases_table_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
<div class="text-left">
<ul class="list-disc list-inside">
<% release.pull_requests.each do |pr| %>
<li><a href="<%= pr[:url] %>"><%= pr[:message] %></a></li>
<li><a href="<%= pr[:url] %>"><%= pr[:message].html_safe %></a></li>
<% end %>
<% release.commits.each do |commit| %>
<li><a href="<%= commit[:url] %>"><%= commit[:message] %></a></li>
<li><a href="<%= commit[:url] %>"><%= commit[:message].html_safe %></a></li>
<% end %>

</ul>
Expand Down
4 changes: 3 additions & 1 deletion app/libs/queries/releases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def selected_records
"relevant_releases.slug", "relevant_releases.status", "relevant_releases.created_at")
.joins("JOIN (#{relevant_releases.to_sql}) AS relevant_releases ON commits.release_id = relevant_releases.id")
.search_by_message(params.search_query)
.with_pg_search_highlight


filtered_pull_requests = PullRequest
Expand All @@ -80,6 +81,7 @@ def selected_records
"relevant_releases.slug", "relevant_releases.status", "relevant_releases.created_at")
.joins("JOIN (#{relevant_releases.to_sql}) AS relevant_releases ON pull_requests.release_id = relevant_releases.id")
.search_by_title(params.search_query)
.with_pg_search_highlight

# Final query with CTEs
Release
Expand All @@ -92,7 +94,7 @@ def selected_records
.from("filtered_commits_and_pull_requests")
.select(:release_id,
"array_agg(type) as types",
"array_agg(matched_message) as matched_messages",
"array_agg(pg_search_highlight) as matched_messages",
"array_agg(url) as urls",
:slug,
:status,
Expand Down
12 changes: 11 additions & 1 deletion app/models/commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ class Commit < ApplicationRecord
using: {
tsearch: {
prefix: true,
any_word: true
any_word: true,
highlight: {
StartSel: '<b>',
StopSel: '</b>',
MinWords: 123,
MaxWords: 456,
ShortWord: 4,
HighlightAll: true,
MaxFragments: 3,
FragmentDelimiter: '&hellip;'
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion app/models/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ class UnsupportedPullRequestSource < StandardError; end
using: {
tsearch: {
prefix: true,
any_word: true
any_word: true,
highlight: {
StartSel: '<b>',
StopSel: '</b>',
MinWords: 123,
MaxWords: 456,
ShortWord: 4,
HighlightAll: true,
MaxFragments: 3,
FragmentDelimiter: '&hellip;'
}
}
}
# rubocop:disable Rails/SkipsModelValidations
Expand Down

0 comments on commit 3d9a7d5

Please sign in to comment.