Changeset 152

Show
Ignore:
Timestamp:
04/12/08 11:08:18 (7 months ago)
Author:
eric.dumin..@gmail.com
Message:

Somewhat skinnier Finder.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/rewrote_indexer/Manifest.txt

    r148 r152  
    2525lib/picolena/templates/app/models/index_writer.rb 
    2626lib/picolena/templates/app/models/indexer.rb 
     27lib/picolena/templates/app/models/query.rb 
    2728lib/picolena/templates/app/views/documents/_document.html.haml 
    2829lib/picolena/templates/app/views/documents/cached.html.haml 
     
    4748lib/picolena/templates/lang/ui/fr.yml 
    4849lib/picolena/templates/lib/core_exts.rb 
    49 lib/picolena/templates/lib/ff.rb 
    5050lib/picolena/templates/lib/filter.rb 
    5151lib/picolena/templates/lib/filter_DSL.rb 
     
    123123lib/picolena/templates/spec/models/index_writer_spec.rb 
    124124lib/picolena/templates/spec/models/indexer_spec.rb 
     125lib/picolena/templates/spec/models/query_spec.rb 
    125126lib/picolena/templates/spec/rcov.opts 
    126127lib/picolena/templates/spec/spec.opts 
  • branches/rewrote_indexer/lib/picolena/templates/app/models/finder.rb

    r151 r152  
    1111   
    1212  def initialize(raw_query,page=1,results_per_page=ResultsPerPage) 
    13     query_parser = Ferret::QueryParser.new(:fields => [:content, :file, :basename, :filetype, :date], :or_default => false, :analyzer=>Analyzer) 
    14     @query = query_parser.parse(convert_to_english(raw_query)) 
     13    @query = Query.extract_from(raw_query) 
    1514    @raw_query= raw_query 
    1615    Finder.ensure_that_index_exists_on_disk 
     
    2322    @matching_documents=[] 
    2423    start=Time.now 
    25     begin 
    26       top_docs=Finder.index.search(query, :limit => @per_page, :offset=>@offset) 
    27       top_docs.hits.each{|hit| 
    28         index_id,score=hit.doc,hit.score 
    29         begin 
    30           found_doc=Document.new(Finder.index[index_id][:complete_path]) 
    31           found_doc.matching_content=Finder.index.highlight(query, index_id, 
    32                                                      :field => :content, :excerpt_length => 80, 
    33                                                      :pre_tag => "<<", :post_tag => ">>" 
    34           ) unless @raw_query=~/^\*+\.\w*$/ 
    35           found_doc.score=score 
    36           found_doc.index_id=index_id 
    37           @matching_documents<<found_doc 
     24    top_docs=Finder.index.search(query, :limit => @per_page, :offset=>@offset) 
     25    top_docs.hits.each{|hit| 
     26      index_id,score=hit.doc,hit.score 
     27      begin 
     28        found_doc=Document.new(Finder.index[index_id][:complete_path]) 
     29        found_doc.matching_content=Finder.index.highlight(query, index_id, 
     30                                                          :field => :content, :excerpt_length => 80, 
     31                                                          :pre_tag => "<<", :post_tag => ">>" 
     32        ) unless @raw_query=~/^\*+\.\w*$/ 
     33        found_doc.score=score 
     34        found_doc.index_id=index_id 
     35        @matching_documents<<found_doc 
    3836        rescue Errno::ENOENT 
    3937          #"File has been moved/deleted!" 
     
    4341      @time_needed=Time.now-start 
    4442      @total_hits=top_docs.total_hits 
    45     ensure 
    46       #index.close 
    47     end 
    4843  end 
    4944   
     
    9186   private 
    9287    
    93    # Convert query keywords to english so they can be parsed by Ferret. 
    94    def convert_to_english(query) 
    95      to_en={ 
    96        /\b#{:AND.l}\b/=>'AND', 
    97        /\b#{:OR.l}\b/=>'OR', 
    98        /\b#{:NOT.l}\b/=>'NOT', 
    99        /(#{:filetype.l}):/=>'filetype:', 
    100        /#{:content.l}:/ => 'content:', 
    101        /#{:date.l}:/ => 'date:', 
    102        /\b#{:LIKE.l}\s+(\S+)/=>'\1~' 
    103      } 
    104      to_en.inject(query){|mem,non_english_to_english_keyword| 
    105        mem.gsub(*non_english_to_english_keyword) 
    106      } 
    107    end 
    108     
    10988   def self.index_filename 
    11089     Dir.glob(File.join(IndexSavePath,'*.cfs')).first 
  • branches/rewrote_indexer/lib/picolena/templates/app/models/indexer.rb

    r151 r152  
    4848          if File.mtime(complete_path).strftime("%Y%m%d%H%M%S").to_i > d.mtime then 
    4949            log :debug => "\thas been modified" 
    50             delete(complete_path) 
     50            delete_file(complete_path) 
    5151          else 
    5252            should_be_added = false 
  • branches/rewrote_indexer/lib/picolena/templates/lib/tasks/index.rake

    r148 r152  
    33  desc 'Clear indexes' 
    44  task :clear => :environment do 
    5     require 'fileutils' 
    65    Dir.glob(File.join(IndexesSavePath,'/**/*')).each{|f| FileUtils.rm(f) if File.file?(f)} 
    76  end 
     
    98  desc 'Create index' 
    109  task :create => :environment do 
    11     require 'ff' 
    12     create_index(IndexedDirectories.keys) 
     10    Indexer.index_every_directory(update=false) 
    1311  end 
    1412 
    1513  desc 'Update index' 
    16   task :update do 
    17     puts "Implement me!" 
     14  task :update => :environment do 
     15    Indexer.index_every_directory(update=true) 
    1816  end 
    1917   
  • branches/rewrote_indexer/tasks/hack.rake

    r131 r152  
    33  picolena_root=File.join(File.dirname(__FILE__),'..') 
    44  Dir.chdir(picolena_root){ 
    5     system("ruby bin/picolena lib/picolena/templates/spec/test_dirs --skip --no-index --no-spec --destination=lib/picolena/templates") 
     5    system("ruby bin/picolena lib/picolena/templates/spec/test_dirs/indexed --skip --no-index --no-spec --destination=lib/picolena/templates") 
    66  } 
    77  puts <<-EXPLAIN