Changeset 333

Show
Ignore:
Timestamp:
05/09/08 04:35:55 (7 months ago)
Author:
eric.dumin..@gmail.com
Message:

Some more documentation

Files:

Legend:

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

    r312 r333  
    1919 
    2020 
     21  # Returns complete path as well as matching score and language if available. 
     22  #  ../spec/test_dirs/indexed/just_one_doc/for_test.txt (56.3%) (language:en) 
     23  # Used for example by 
     24  #  rake index:search query="some query" 
    2125  def inspect 
    2226    [self,("(#{pretty_score})" if @score),("(language:#{language})" if language)].compact.join(" ") 
    2327  end 
    24  
    25  
    2628 
    2729  # Returns filename without extension 
     
    7375  end 
    7476   
     77  # Returns cached content with matching terms between '<<' '>>'. 
    7578  def highlighted_cache(raw_query) 
    76     #TODO: Report to Ferret. Highlight should accept :key and not only :doc_id. 
    7779    Indexer.index.highlight(Query.extract_from(raw_query), doc_id, 
    7880                            :field => :content, :excerpt_length => :all, 
     
    8385  # Returns the last modification date before the document got indexed. 
    8486  # Useful to know how old a document is, and to which version the cache corresponds. 
     87  #   >> doc.pretty_date 
     88  #   => "2008-05-09" 
    8589  def pretty_date 
    8690    from_index[:modified].sub(/(\d{4})(\d{2})(\d{2})\d{6}/,'\1-\2-\3') 
    8791  end 
    8892   
     93  # Returns the last modification time before the document got indexed. 
     94  #   >> doc.pretty_mtime 
     95  #   => "2008-05-09 09:39:51" 
    8996  def pretty_mtime 
    9097    from_index[:modified].sub(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/,'\1-\2-\3 \4:\5:\6') 
    9198  end 
    9299 
     100  # Returns the last modification time before the document got indexed, as YYYYMMDDHHMMSS integer. 
     101  #   >> doc.mtime 
     102  #   => 20080509093951 
    93103  def mtime 
    94104    from_index[:modified].to_i 
    95105  end 
    96106 
    97   # Returns language
     107  # Returns found language, if any
    98108  def language 
    99109    from_index[:language] 
    100110  end 
    101111 
     112  # Returns matching score as a percentage, e.g. 56.3% 
    102113  def pretty_score 
    103114    "%3.1f%" % (@score*100)