Changeset 324

Show
Ignore:
Timestamp:
05/08/08 01:07:47 (7 months ago)
Author:
eric.dumin..@gmail.com
Message:

Added Query#content_terms for multicolor cache highlighting.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/picolena/templates/app/models/query.rb

    r263 r324  
    44    def extract_from(raw_query) 
    55      parser.parse(convert_to_english(raw_query)) 
     6    end 
     7     
     8    # Returns terms related to content. Useful for cache highlighting 
     9    def content_terms(raw_query) 
     10      Query.extract_from(raw_query).terms(Indexer.index.searcher).select{|term| term.field==:content}.collect{|term| term.text}.uniq 
    611    end 
    712 
  • trunk/lib/picolena/templates/spec/models/query_spec.rb

    r307 r324  
    7777    Query.extract_from("test").should_not == Query.extract_from("tesTe") 
    7878  end 
     79   
     80  it "should be able to extract search terms related to :content" do 
     81    Query.content_terms("plain text").should == %w(plain text) 
     82    Query.content_terms("plain text extension:pdf").should == %w(plain text) 
     83    Query.content_terms("plain AND text").should == %w(plain text) 
     84    Query.content_terms("absorption OR adsorption").should ==%w(absorption adsorption) 
     85    Query.content_terms("filename:plain_text").should be_empty 
     86    Globalite.language = :en 
     87    Query.content_terms("LIKE absorption").include?("adsorption").should be_true 
     88  end 
    7989end