summaryrefslogtreecommitdiffstats
path: root/app.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app.rb')
-rw-r--r--app.rb23
1 files changed, 17 insertions, 6 deletions
diff --git a/app.rb b/app.rb
index 7d6489a..c5f533b 100644
--- a/app.rb
+++ b/app.rb
@@ -556,15 +556,26 @@ end
get '/search' do
q = params[:q].to_s.strip
- @title = q.empty? ? 'Search' : "Search: #{q}"
+ @title = q.empty? ? 'Album Search' : "Album Search: #{q}"
@search_query = q
unless q.empty?
- ast = search_parse(q)
- index = search_index
- all = index.select { |d| (admin? || d[:visible]) && eval_search(ast, d[:text]) }
- @total = all.length
- @results = all.first(300)
+ ast = search_parse(q)
+ index = search_index
+ matched = index.select { |d| (admin? || d[:visible]) && eval_search(ast, d[:text]) }
+
+ by_dir = matched.each_with_object({}) { |d, h| (h[d[:dir_rel]] ||= []) << d }
+ @results = by_dir.map do |dir_rel, docs|
+ dir = dir_rel.empty? ? MEDIA_ROOT : File.join(MEDIA_ROOT, dir_rel)
+ data = load_album(dir)
+ {
+ dir_rel: dir_rel,
+ title: data['title'] || (dir_rel.empty? ? '(root)' : File.basename(dir_rel)),
+ cover: album_cover(dir, data),
+ count: docs.length,
+ }
+ end
+ @total = @results.length
end
erb :search