Changeset 152
- Timestamp:
- 04/12/08 11:08:18 (7 months ago)
- Files:
-
- branches/rewrote_indexer/Manifest.txt (modified) (3 diffs)
- branches/rewrote_indexer/lib/picolena/templates/app/models/finder.rb (modified) (4 diffs)
- branches/rewrote_indexer/lib/picolena/templates/app/models/indexer.rb (modified) (1 diff)
- branches/rewrote_indexer/lib/picolena/templates/app/models/query.rb (added)
- branches/rewrote_indexer/lib/picolena/templates/lib/tasks/index.rake (modified) (2 diffs)
- branches/rewrote_indexer/lib/picolena/templates/spec/models/query_spec.rb (added)
- branches/rewrote_indexer/tasks/hack.rake (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/rewrote_indexer/Manifest.txt
r148 r152 25 25 lib/picolena/templates/app/models/index_writer.rb 26 26 lib/picolena/templates/app/models/indexer.rb 27 lib/picolena/templates/app/models/query.rb 27 28 lib/picolena/templates/app/views/documents/_document.html.haml 28 29 lib/picolena/templates/app/views/documents/cached.html.haml … … 47 48 lib/picolena/templates/lang/ui/fr.yml 48 49 lib/picolena/templates/lib/core_exts.rb 49 lib/picolena/templates/lib/ff.rb50 50 lib/picolena/templates/lib/filter.rb 51 51 lib/picolena/templates/lib/filter_DSL.rb … … 123 123 lib/picolena/templates/spec/models/index_writer_spec.rb 124 124 lib/picolena/templates/spec/models/indexer_spec.rb 125 lib/picolena/templates/spec/models/query_spec.rb 125 126 lib/picolena/templates/spec/rcov.opts 126 127 lib/picolena/templates/spec/spec.opts branches/rewrote_indexer/lib/picolena/templates/app/models/finder.rb
r151 r152 11 11 12 12 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) 15 14 @raw_query= raw_query 16 15 Finder.ensure_that_index_exists_on_disk … … 23 22 @matching_documents=[] 24 23 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 38 36 rescue Errno::ENOENT 39 37 #"File has been moved/deleted!" … … 43 41 @time_needed=Time.now-start 44 42 @total_hits=top_docs.total_hits 45 ensure46 #index.close47 end48 43 end 49 44 … … 91 86 private 92 87 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 end108 109 88 def self.index_filename 110 89 Dir.glob(File.join(IndexSavePath,'*.cfs')).first branches/rewrote_indexer/lib/picolena/templates/app/models/indexer.rb
r151 r152 48 48 if File.mtime(complete_path).strftime("%Y%m%d%H%M%S").to_i > d.mtime then 49 49 log :debug => "\thas been modified" 50 delete (complete_path)50 delete_file(complete_path) 51 51 else 52 52 should_be_added = false branches/rewrote_indexer/lib/picolena/templates/lib/tasks/index.rake
r148 r152 3 3 desc 'Clear indexes' 4 4 task :clear => :environment do 5 require 'fileutils'6 5 Dir.glob(File.join(IndexesSavePath,'/**/*')).each{|f| FileUtils.rm(f) if File.file?(f)} 7 6 end … … 9 8 desc 'Create index' 10 9 task :create => :environment do 11 require 'ff' 12 create_index(IndexedDirectories.keys) 10 Indexer.index_every_directory(update=false) 13 11 end 14 12 15 13 desc 'Update index' 16 task :update do17 puts "Implement me!"14 task :update => :environment do 15 Indexer.index_every_directory(update=true) 18 16 end 19 17 branches/rewrote_indexer/tasks/hack.rake
r131 r152 3 3 picolena_root=File.join(File.dirname(__FILE__),'..') 4 4 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") 6 6 } 7 7 puts <<-EXPLAIN
