Changeset 333
- Timestamp:
- 05/09/08 04:35:55 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/picolena/templates/app/models/document.rb
r312 r333 19 19 20 20 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" 21 25 def inspect 22 26 [self,("(#{pretty_score})" if @score),("(language:#{language})" if language)].compact.join(" ") 23 27 end 24 25 26 28 27 29 # Returns filename without extension … … 73 75 end 74 76 77 # Returns cached content with matching terms between '<<' '>>'. 75 78 def highlighted_cache(raw_query) 76 #TODO: Report to Ferret. Highlight should accept :key and not only :doc_id.77 79 Indexer.index.highlight(Query.extract_from(raw_query), doc_id, 78 80 :field => :content, :excerpt_length => :all, … … 83 85 # Returns the last modification date before the document got indexed. 84 86 # Useful to know how old a document is, and to which version the cache corresponds. 87 # >> doc.pretty_date 88 # => "2008-05-09" 85 89 def pretty_date 86 90 from_index[:modified].sub(/(\d{4})(\d{2})(\d{2})\d{6}/,'\1-\2-\3') 87 91 end 88 92 93 # Returns the last modification time before the document got indexed. 94 # >> doc.pretty_mtime 95 # => "2008-05-09 09:39:51" 89 96 def pretty_mtime 90 97 from_index[:modified].sub(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/,'\1-\2-\3 \4:\5:\6') 91 98 end 92 99 100 # Returns the last modification time before the document got indexed, as YYYYMMDDHHMMSS integer. 101 # >> doc.mtime 102 # => 20080509093951 93 103 def mtime 94 104 from_index[:modified].to_i 95 105 end 96 106 97 # Returns language.107 # Returns found language, if any. 98 108 def language 99 109 from_index[:language] 100 110 end 101 111 112 # Returns matching score as a percentage, e.g. 56.3% 102 113 def pretty_score 103 114 "%3.1f%" % (@score*100)
