diff options
Diffstat (limited to 'app.rb')
| -rw-r--r-- | app.rb | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -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 |
