Changeset 241
- Timestamp:
- 04/24/08 07:40:36 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/yet_another_index_structure/lib/picolena/templates/app/models/document.rb
r240 r241 86 86 # Returns the id with which the document is indexed. 87 87 def index_id 88 @index_id ||= Document.find_by_complete_path(complete_path).index_id88 @index_id ||= Finder.term_search(:complete_path, complete_path).doc 89 89 end 90 90 … … 110 110 111 111 def self.find_by_unique_id(some_id) 112 #NOTE: No need for Finder.113 Finder.new("probably_unique_id:"<<some_id).matching_document112 doc_id=Finder.term_search(:probably_unique_id, some_id).doc 113 new(Indexer.index[doc_id][:complete_path]) 114 114 end 115 116 def self.find_by_complete_path(complete_path) 117 #NOTE: No need for Finder. 118 Finder.new('complete_path:"'<<complete_path<<'"').matching_document 119 end 120 115 121 116 def in_indexed_directory? 122 117 !indexed_directory.nil? branches/yet_another_index_structure/lib/picolena/templates/app/models/finder.rb
r238 r241 3 3 4 4 def index 5 @@index ||= Indexer.index5 @@index ||= Indexer.index 6 6 end 7 7 … … 29 29 found_doc.index_id=index_id 30 30 @matching_documents<<found_doc 31 rescue Errno::ENOENT32 #"File has been moved/deleted!"33 end31 rescue Errno::ENOENT 32 #"File has been moved/deleted!" 33 end 34 34 } 35 35 @executed=true … … 58 58 # exactly one document is found. 59 59 # Raises otherwise. 60 def matching_document 61 case matching_documents.size 62 when 0 63 raise IndexError, "No document found" 64 when 1 65 matching_documents.first 66 else 67 raise IndexError, "More than one document found" 68 end 69 end 60 def matching_document 61 case matching_documents.size 62 when 0 63 raise IndexError, "No document found" 64 when 1 65 matching_documents.first 66 else 67 raise IndexError, "More than one document found" 68 end 69 end 70 71 class<<self 72 def searcher 73 Ferret::Search::Searcher.new(Picolena::IndexSavePath) 74 end 75 76 def term_search(field,term) 77 query = Ferret::Search::TermQuery.new(field,term) 78 searcher.search(query).hits.first 79 end 80 end 70 81 end
