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

Include track titles in search #317

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def link_to_song(song, term = nil)
link_to(title, "/#{song.slug}")
end

def link_to_track(track, term = nil)
title = track.title
title = highlight(title, term) if term.present?
link_to(title, "/#{track.show.date}/#{track.slug}")
end

def song_title_with_alias(song)
title = song.title
title += " (aka #{song.alias})" if song.alias.present?
Expand Down
34 changes: 27 additions & 7 deletions app/services/search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
class SearchService
attr_reader :term

LIMIT = 200

def initialize(term)
@term = term || ''
end
Expand Down Expand Up @@ -30,12 +32,13 @@ def date_results

def text_results
{
show_tags:,
songs:,
venues:,
tours:,
tags:,
show_tags:,
track_tags:
tours:,
track_tags:,
tracks:,
venues:
}
end

Expand All @@ -62,8 +65,9 @@ def shows_on_day_of_year
end

def songs
return @songs if defined?(@songs)
return [] if term_is_date?
Song.where(
@songs = Song.where(
'title ILIKE :term OR alias ILIKE :term',
term: "%#{term}%"
).order(title: :asc)
Expand Down Expand Up @@ -98,13 +102,29 @@ def show_tags
ShowTag.includes(:tag, :show)
.where('notes ILIKE ?', "%#{term}%")
.order('tags.name, shows.date')
.limit(200)
.limit(LIMIT)
end

def track_tags
TrackTag.includes(:tag, track: :show)
.where('notes ILIKE ?', "%#{term}%")
.order('tags.name, shows.date, tracks.position')
.limit(200)
.limit(LIMIT)
end

def song_titles
@song_titles ||= songs.map(&:title)
end

# Return only tracks that don't have a song title that matches the search term
# since those would produce essentially duplicate search results
def tracks
tracks_by_title.reject { |track| track.title.in?(song_titles) }
end

def tracks_by_title
Track.where('title ILIKE ?', "%#{term}%")
.order(title: :asc)
.limit(LIMIT)
end
end
7 changes: 7 additions & 0 deletions app/views/search/_results_tracks.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
h2 Matched #{pluralize_with_delimiter(@tracks.size, 'Track')}
ul.item_list.clickable
- @tracks.each do |track|
li name=track.slug
h2.wide = link_to_track(track, params[:term])
h3.alt = link_to_show(track.show, show_abbrev: false)
= clear_both
1 change: 1 addition & 0 deletions app/views/search/results.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
= render partial: 'results_exact_show' if @exact_show.present?
= render partial: 'results_other_shows' if @other_shows.any?
= render partial: 'results_songs' if @songs.any?
= render partial: 'results_tracks' if @tracks.any?
= render partial: 'results_venues' if @venues.any?
= render partial: 'results_tours' if @tours.any?
= render partial: 'results_tags' if @tags.any?
Expand Down
Loading