Changeset 277

Show
Ignore:
Timestamp:
04/26/08 05:00:57 (7 months ago)
Author:
eric.dumin..@gmail.com
Message:

Ugly cache highlighting à la Google

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/History.txt

    r272 r277  
     1== 0.1.7  2008-04- 
     2 
     3* 1 minor enhancement: 
     4  * added cache highlighting à la Google 
     5 
    16== 0.1.6  2008-04-25 
    27 
     
    510 
    611* bug fixes: 
    7   * Added forgotten public/images/flags to generator file. 
     12  * Added forgotten public/images/flags to generator file 
    813 
    914== 0.1.5  2008-04-25 
     
    2530 
    2631* 1 bug fix: 
    27   * removed verbose debug info. 
     32  * removed verbose debug info 
    2833 
    2934== 0.1.2  2008-04-20 
     
    5055  * can now be installed on win32 (doesn't pass every spec though) 
    5156  * moved rails_plugins away from lib/ so that they don't get parsed by rdoc/ri 
    52   * shorter and prettier base26_hash id for documents. 
     57  * shorter and prettier base26_hash id for documents 
    5358 
    5459== 0.0.99  2008-04-06 
  • trunk/lib/picolena/templates/app/controllers/documents_controller.rb

    r265 r277  
    4848  # similar to Google cache. 
    4949  def cached 
     50    @query=[params[:query],params.delete(:format)].compact.join('.') 
    5051  end 
    5152 
  • trunk/lib/picolena/templates/app/helpers/documents_helper.rb

    r268 r277  
    7272 
    7373  # For any indexed document, returns a link to show its cached content. 
    74   def link_to_cached_content(document
     74  def link_to_cached_content(document, query
    7575    link_name="("<<content_tag(:small,:cached.l)<<")" 
    76     link_to link_name, cached_document_path(document.probably_unique_id) 
     76    link_to link_name, cached_document_path(:id => document.probably_unique_id, :query => query) 
     77  end 
     78   
     79  def highlighted_cache(document, query) 
     80    h(document.highlighted_cache(query)).gsub(/\n/,'<br/>').gsub(/&lt;&lt;(.*?)&gt;&gt;/,content_tag(:span, '\1', :class=>"matching_content")) 
    7781  end 
    7882end 
  • trunk/lib/picolena/templates/app/models/document.rb

    r274 r277  
    6565    from_index[:content] 
    6666  end 
     67   
     68  def highlighted_cache(raw_query) 
     69    #TODO: Report to Ferret. Highlight should accept :key and not only :doc_id. 
     70    Indexer.index.highlight(Query.extract_from(raw_query), doc_id, 
     71                            :field => :content, :excerpt_length => :all, 
     72                            :pre_tag => "<<", :post_tag => ">>" 
     73    ) 
     74  end 
    6775 
    6876  # Returns the last modification date before the document got indexed. 
     
    98106 
    99107  private 
     108   
     109  # FIXME: Is there a way to easily retrieve doc_id for a given document? 
     110  # Better yet, fix Index#highlight to accept :probably_unique_id and stop using :doc_id. 
     111  def doc_id 
     112    Indexer.index.search(Ferret::Search::TermQuery.new(:probably_unique_id,probably_unique_id)).hits.first.doc 
     113  end 
    100114 
    101115  # Retrieves the document from the index. 
  • trunk/lib/picolena/templates/app/views/documents/_document.html.haml

    r274 r277  
    1313    =document.pretty_date 
    1414    &#45; 
    15     =link_to_cached_content(document
     15    =link_to_cached_content(document,query
    1616%hr/ 
  • trunk/lib/picolena/templates/app/views/documents/cached.html.haml

    r274 r277  
    66  ) 
    77%p=link_to_containing_directory(@document) 
    8 %blockquote=h(@document.cached).gsub(/\n/,'<br/>'
     8%blockquote=highlighted_cache(@document, @query
  • trunk/lib/picolena/templates/app/views/documents/show.html.haml

    r256 r277  
    1010        %span{:class=>'pagination'}=should_paginate(@matching_documents, @query) 
    1111        =describe_results(@matching_documents, @total_hits, @time_needed, h(@query)) 
    12 = render :partial =>'document', :collection => @matching_documents 
     12= render :partial =>'document', :collection => @matching_documents, :locals => { :query => @query} 
  • trunk/lib/picolena/templates/public/stylesheets/style.css

    r263 r277  
    138138} 
    139139 
     140#results .matching_content{ 
     141        background-color:#ffff66; 
     142} 
     143 
     144 
    140145#results a, #results small{ 
    141146        font-family:"Trebuchet MS";