module DocumentsHelper # Returns true if no document as been found for a given query. def nothing_found? @matching_documents.nil? or @matching_documents.entries.empty? end # Very basic pagination. # Provides liks to Next, Prev and FirstPage when needed. def should_paginate(page,query, sort) [(link_to("←←", :action => :show, :id => query, :sort=>sort) if page.number>2), (link_to("←", :action => :show, :id => query, :page => page.prev.number, :sort=>sort) if page.prev?), (link_to("→", :action => :show, :id => query, :page => page.next.number, :sort=>sort) if page.next?)].compact.join(" | ") end # Returns a localized sentence like "Results 1-10 of 12 for Zimbabwe (0.472s)" or # "Résultats 1-2 parmi 2 pour whatever (0.012s)" def describe_results(page, total_hits, dt, query) [:results.l, content_tag(:strong,"#{page.first_item_number}-#{page.last_item_number}"), :of.l, content_tag(:strong,total_hits), :for.l, content_tag(:strong,query), show_time_needed(dt) ].join(' ') end # Returns the time needed to treat the query and launch the search, with a ms precision : (0.472s) def show_time_needed(dt) content_tag(:small,'('<\1').gsub(/\v|\f/,'')) }) if document.matching_content end def language_icon_for(document) lang=document.language link_to(image_tag("flags/#{lang}.png"), document_url('lang:'<'_blank' end # For any indexed document, returns a link to show its content. def link_to_plain_text_content(document) link_name=image_tag('icons/plain_text_small.png')<<' '< document.probably_unique_id, :query => query) end def highlighted_cache(document, query) h(document.highlighted_cache(query)).gsub(/\n/,'
').gsub(/<<(.*?)>>/,content_tag(:span, '\1', :class=>"matching_content")) end def sort_by_date_or_relevance(query) [link_to_unless_current('By date', document_path(query, :sort=>'by_date')), link_to_unless_current('By relevance', document_path(query))].join(" ") end end