Changeset 241

Show
Ignore:
Timestamp:
04/24/08 07:40:36 (7 months ago)
Author:
eric.dumin..@gmail.com
Message:

149 examples, 6 failures, 6 pending

Files:

Legend:

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

    r240 r241  
    8686  # Returns the id with which the document is indexed. 
    8787  def index_id 
    88     @index_id ||= Document.find_by_complete_path(complete_path).index_id 
     88    @index_id ||= Finder.term_search(:complete_path, complete_path).doc 
    8989  end 
    9090   
     
    110110   
    111111  def self.find_by_unique_id(some_id) 
    112     #NOTE: No need for Finder. 
    113     Finder.new("probably_unique_id:"<<some_id).matching_document 
     112    doc_id=Finder.term_search(:probably_unique_id, some_id).doc 
     113    new(Indexer.index[doc_id][:complete_path]) 
    114114  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  
    121116  def in_indexed_directory? 
    122117    !indexed_directory.nil? 
  • branches/yet_another_index_structure/lib/picolena/templates/app/models/finder.rb

    r238 r241  
    33   
    44  def index 
    5     @@index ||= Indexer.index 
     5    @@index ||= Indexer.index 
    66  end 
    77   
     
    2929        found_doc.index_id=index_id 
    3030        @matching_documents<<found_doc 
    31         rescue Errno::ENOENT 
    32           #"File has been moved/deleted!" 
    33         end 
     31      rescue Errno::ENOENT 
     32        #"File has been moved/deleted!" 
     33      end 
    3434      } 
    3535      @executed=true 
     
    5858   # exactly one document is found. 
    5959   # 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 
    7081end