To edit pages or tickets please login with username/password: aaf/aaf

Changeset 346

Show
Ignore:
Timestamp:
05/20/08 08:54:48 (5 months ago)
Author:
jk
Message:

allow per query options, i.e. for specifying a special analyzer to be used for this query

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plugin/acts_as_ferret/lib/ferret_find_methods.rb

    r332 r346  
    8383      stored_fields = determine_stored_fields options 
    8484 
    85       q = process_query(query
     85      q = process_query(query, options
    8686      q = scope_query_to_models q, options[:models] #if shared? 
    8787      logger.debug "query: #{query}\n-->#{q}" 
  • trunk/plugin/acts_as_ferret/lib/local_index.rb

    r327 r346  
    6161 
    6262    # Parses the given query string into a Ferret Query object. 
    63     def process_query(query) 
    64       # work around ferret bug in #process_query (doesn't ensure the 
    65       # reader is open) 
     63    def process_query(query, options = {}) 
     64      return query unless String === query 
    6665      ferret_index.synchronize do 
    67         ferret_index.send(:ensure_reader_open) 
    68         original_query = ferret_index.process_query(query) 
     66        if options[:analyzer] 
     67          # use per-query analyzer if present 
     68          qp = Ferret::QueryParser.new ferret_index.instance_variable_get('@options').merge(options) 
     69          reader = ferret_index.reader 
     70          qp.fields = 
     71              reader.fields unless options[:all_fields] || options[:fields] 
     72          qp.tokenized_fields = 
     73              reader.tokenized_fields unless options[:tokenized_fields] 
     74          return qp.parse query 
     75        else 
     76          # work around ferret bug in #process_query (doesn't ensure the 
     77          # reader is open) 
     78          ferret_index.send(:ensure_reader_open) 
     79          return ferret_index.process_query(query) 
     80        end 
    6981      end 
    7082    end 
  • trunk/plugin/acts_as_ferret/lib/multi_index.rb

    r322 r346  
    5858     
    5959    def search(query, options={}) 
    60       query = process_query(query
     60      query = process_query(query, options
    6161      logger.debug "parsed query: #{query.to_s}" 
    6262      searcher.search(query, options) 
     
    6464 
    6565    def search_each(query, options = {}, &block) 
    66       query = process_query(query
     66      query = process_query(query, options
    6767      searcher.search_each(query, options, &block) 
    6868    end 
     
    9393    end 
    9494     
    95     def process_query(query
     95    def process_query(query, options = {}
    9696      query = query_parser.parse(query) if query.is_a?(String) 
    9797      return query 
  • trunk/plugin/acts_as_ferret/recipes/aaf_recipes.rb

    r327 r346  
    4646  desc "Stop the Ferret DRb server" 
    4747  task :stop, :roles => :app do 
    48     run "cd #{current_path}; script/ferret_server -e #{rails_env} stop" 
     48    rails_env = fetch(:rails_env, 'production') 
     49    run "cd #{current_path}; script/ferret_server -e #{rails_env} stop || true" 
    4950  end 
    5051 
    5152  desc "Start the Ferret DRb server" 
    5253  task :start, :roles => :app do 
     54    rails_env = fetch(:rails_env, 'production') 
    5355    run "cd #{current_path}; script/ferret_server -e #{rails_env} start" 
    5456  end 
     
    6668    task :rebuild, :roles => :app do 
    6769      rake = fetch(:rake, 'rake') 
     70      rails_env = fetch(:rails_env, 'production') 
    6871      indexes = fetch(:ferret_indexes, nil) 
    6972      if indexes and indexes.any? 

To edit pages or tickets please login with username/password: aaf/aaf