Changeset 283
- Timestamp:
- 04/27/08 10:27:52 (7 months ago)
- Files:
-
- trunk/History.txt (modified) (1 diff)
- trunk/lib/picolena/templates/app/controllers/documents_controller.rb (modified) (1 diff)
- trunk/lib/picolena/templates/app/helpers/documents_helper.rb (modified) (4 diffs)
- trunk/lib/picolena/templates/app/models/finder.rb (modified) (4 diffs)
- trunk/lib/picolena/templates/app/models/indexer.rb (modified) (1 diff)
- trunk/lib/picolena/templates/app/views/documents/show.html.haml (modified) (1 diff)
- trunk/lib/picolena/templates/public/stylesheets/style.css (modified) (2 diffs)
- trunk/lib/picolena/templates/spec/models/basic_finder_spec.rb (modified) (1 diff)
- trunk/lib/picolena/templates/spec/models/finder_spec.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/History.txt
r281 r283 1 1 == 0.1.7 2008-04- 2 2 3 * 1minor enhancement:3 * 4 minor enhancement: 4 4 * added cache highlighting à la Google 5 5 * rake index:update implemented as described in Ferret book by David Balmain 6 6 * rake index:prune removes missing files from indexer. 7 * possibility to sort results by relevance / by date 7 8 8 9 == 0.1.6 2008-04-25 trunk/lib/picolena/templates/app/controllers/documents_controller.rb
r277 r283 23 23 start=Time.now 24 24 @query=[params[:id],params.delete(:format)].compact.join('.') 25 sort=params[:sort] 25 26 page=params[:page]||1 26 finder=Finder.new(@query, page)27 finder=Finder.new(@query,sort,page) 27 28 finder.execute! 28 29 pager=::Paginator.new(finder.total_hits, Picolena::ResultsPerPage) do trunk/lib/picolena/templates/app/helpers/documents_helper.rb
r277 r283 4 4 @matching_documents.nil? or @matching_documents.entries.empty? 5 5 end 6 6 7 7 # Very basic pagination. 8 8 # Provides liks to Next, Prev and FirstPage when needed. … … 12 12 (link_to("→", :action => :show, :id => query, :page => page.next.number) if page.next?)].compact.join(" | ") 13 13 end 14 14 15 15 # Returns a localized sentence like "Results 1-10 of 12 for Zimbabwe (0.472s)" or 16 16 # "Résultats 1-2 parmi 2 pour whatever (0.012s)" … … 25 25 ].join(' ') 26 26 end 27 27 28 28 # Returns the time needed to treat the query and launch the search, with a ms precision : (0.472s) 29 29 def show_time_needed(dt) … … 80 80 h(document.highlighted_cache(query)).gsub(/\n/,'<br/>').gsub(/<<(.*?)>>/,content_tag(:span, '\1', :class=>"matching_content")) 81 81 end 82 83 def sort_by_date_or_relevance(query) 84 [link_to_unless_current('By date', document_path(query, :sort=>'by_date')), 85 link_to_unless_current('By relevance', document_path(query))].join(" ") 86 end 82 87 end trunk/lib/picolena/templates/app/models/finder.rb
r276 r283 6 6 end 7 7 8 def initialize(raw_query, page=1,results_per_page=Picolena::ResultsPerPage)8 def initialize(raw_query,by_date=false, page=1,results_per_page=Picolena::ResultsPerPage) 9 9 @query = Query.extract_from(raw_query) 10 10 @raw_query= raw_query … … 12 12 @per_page=results_per_page 13 13 @offset=(page.to_i-1)*results_per_page 14 @by_date=by_date 14 15 index_should_have_documents 15 16 end … … 18 19 @matching_documents=[] 19 20 start=Time.now 20 @total_hits = index.search_each(query, :limit => @per_page, :offset=>@offset ){|index_id, score|21 @total_hits = index.search_each(query, :limit => @per_page, :offset=>@offset, :sort => (sort_by_date if @by_date)){|index_id, score| 21 22 begin 22 23 found_doc=Document.new(index[index_id][:complete_path]) … … 57 58 58 59 private 60 61 def sort_by_date 62 Ferret::Search::SortField.new(:modified, :type => :byte, :reverse => true) 63 end 59 64 60 65 def index_should_have_documents trunk/lib/picolena/templates/app/models/indexer.rb
r282 r283 147 147 field_infos.add_field(:modified, :store => :yes, :index => :untokenized) 148 148 field_infos.add_field(:probably_unique_id, :store => :no, :index => :untokenized) 149 field_infos.add_field(:language, :store => :yes, :index => : yes)149 field_infos.add_field(:language, :store => :yes, :index => :untokenized) 150 150 end 151 151 end trunk/lib/picolena/templates/app/views/documents/show.html.haml
r277 r283 10 10 %span{:class=>'pagination'}=should_paginate(@matching_documents, @query) 11 11 =describe_results(@matching_documents, @total_hits, @time_needed, h(@query)) 12 -unless nothing_found? 13 %p 14 %span{:class=>'sort_by'}=sort_by_date_or_relevance(@query) 12 15 = render :partial =>'document', :collection => @matching_documents, :locals => { :query => @query} trunk/lib/picolena/templates/public/stylesheets/style.css
r277 r283 80 80 color: #fff; 81 81 font-weight: bold; 82 text-decoration:none; 83 } 84 85 .sort_by { 86 float:right; 87 font-size: 13px; 88 color:#000; 89 } 90 91 .sort_by a{ 92 color: #EE8907; 82 93 text-decoration:none; 83 94 } … … 117 128 #results { 118 129 width:778px; 119 padding-top: 25px;130 padding-top: 15px; 120 131 } 121 132 trunk/lib/picolena/templates/spec/models/basic_finder_spec.rb
r263 r283 51 51 end 52 52 53 it "should accept one parameter as query, and 2 optionals for paginating" do53 it "should accept one parameter as query, 1 optional for sorting results and 2 optionals for paginating" do 54 54 lambda {Finder.new}.should raise_error(ArgumentError, "wrong number of arguments (0 for 1)") 55 55 # show first page with 10 results per page 56 56 lambda {Finder.new("a b")}.should_not raise_error 57 57 # show second page 58 lambda {Finder.new("a", 2)}.should_not raise_error58 lambda {Finder.new("a", "by_date")}.should_not raise_error 59 59 # show first page with 15 results 60 lambda {Finder.new("a", 1, 15)}.should_not raise_error60 lambda {Finder.new("a", "by_date", 1, 15)}.should_not raise_error 61 61 # Too many parameters 62 lambda {Finder.new("a", 10, 20, 30)}.should raise_error(ArgumentError, "wrong number of arguments (4 for 3)")62 lambda {Finder.new("a", "by_date", 10, 20, 30)}.should raise_error(ArgumentError, "wrong number of arguments (5 for 4)") 63 63 end 64 64 trunk/lib/picolena/templates/spec/models/finder_spec.rb
r270 r283 9 9 10 10 def matching_document_for(query) 11 # Returns matching document for any given query only if12 # exactly one document is found.13 # Specs don't pass otherwise.11 # Returns matching document for any given query only if 12 # exactly one document is found. 13 # Specs don't pass otherwise. 14 14 matching_documents=Finder.new(query).matching_documents 15 15 matching_documents.size.should == 1
