Commit bcd5cd44f53941cdc13b1d5586d135c8fbe1b17d
1 parent
50c2d5c8
Exists in
master
and in
29 other branches
Update acts_as_solr_reloaded
Showing
23 changed files
with
379 additions
and
286 deletions
Show diff stats
plugins/solr/vendor/plugins/acts_as_solr_reloaded/.travis.yml
1 | +services: | |
2 | + - mongodb | |
3 | + | |
4 | +language: ruby | |
5 | +rvm: | |
6 | + - 1.8.7 | |
7 | + | |
8 | +before_install: | |
9 | + - sudo apt-get update | |
10 | + - sudo apt-get install default-jdk | |
11 | + | |
1 | 12 | before_script: |
2 | 13 | - mongo mydb_test --eval 'db.addUser("travis", "test");' |
3 | 14 | - gem update --system 1.4.1 > /dev/null 2>&1 |
4 | 15 | - rake solr:download |
5 | 16 | - RAILS_ENV=test rake solr:start |
6 | 17 | |
7 | -script: "bundle exec rake $TASK --trace" | |
18 | +script: | |
19 | + - bundle exec rake test --trace | |
20 | + - bundle exec rake test:functional --trace | |
8 | 21 | |
9 | -rvm: | |
10 | - - 1.8.7 | |
11 | -env: | |
12 | - - TASK=test | |
13 | - - TASK=test:functional | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/Gemfile
plugins/solr/vendor/plugins/acts_as_solr_reloaded/Rakefile
1 | 1 | require 'rubygems' |
2 | 2 | require 'rake' |
3 | 3 | require 'rake/testtask' |
4 | -require 'rake/rdoctask' | |
4 | +require 'rdoc/task' | |
5 | 5 | |
6 | 6 | ENV['RAILS_ENV'] = "test" |
7 | 7 | require File.expand_path("#{File.dirname(__FILE__)}/config/solr_environment") |
8 | 8 | |
9 | 9 | Dir["#{File.dirname(__FILE__)}/lib/tasks/*.rake"].sort.each { |ext| load ext } |
10 | 10 | |
11 | -desc "Default Task" | |
12 | -task :default => [:test] | |
13 | - | |
14 | -desc "Runs the unit tests" | |
15 | -task :test => "test:unit" | |
16 | - | |
17 | -namespace :test do | |
18 | - task :setup do | |
19 | - DB ||= 'sqlite' | |
20 | - puts "Using " + DB | |
21 | - %x(mysql -u#{MYSQL_USER} < #{File.dirname(__FILE__) + "/test/fixtures/db_definitions/mysql.sql"}) if DB == 'mysql' | |
22 | - | |
23 | - Rake::Task["test:migrate"].invoke | |
24 | - end | |
25 | - | |
26 | - desc 'Measures test coverage using rcov' | |
27 | - task :rcov => :setup do | |
28 | - rm_f "coverage" | |
29 | - rm_f "coverage.data" | |
30 | - rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib" | |
31 | - | |
32 | - system("#{rcov} --html #{Dir.glob('test/**/*_shoulda.rb').join(' ')}") | |
33 | - system("open coverage/index.html") if PLATFORM['darwin'] | |
34 | - end | |
35 | - | |
36 | - desc 'Runs the functional tests, testing integration with Solr' | |
37 | - Rake::TestTask.new(:functional => :setup) do |t| | |
38 | - t.pattern = "test/functional/*_test.rb" | |
39 | - t.verbose = true | |
40 | - end | |
41 | - | |
42 | - desc "Unit tests" | |
43 | - Rake::TestTask.new(:unit => :setup) do |t| | |
44 | - t.libs << 'test/unit' | |
45 | - t.pattern = "test/unit/*_shoulda.rb" | |
46 | - t.verbose = true | |
47 | - end | |
48 | -end | |
49 | - | |
50 | -Rake::RDocTask.new do |rd| | |
51 | - rd.main = "README.rdoc" | |
52 | - rd.rdoc_dir = "rdoc" | |
53 | - rd.rdoc_files.exclude("lib/solr/**/*.rb", "lib/solr.rb") | |
54 | - rd.rdoc_files.include("README.rdoc", "lib/**/*.rb") | |
55 | -end | |
56 | - | |
57 | -begin | |
58 | - require 'jeweler' | |
59 | - Jeweler::Tasks.new do |s| | |
60 | - s.name = "acts_as_solr_reloaded" | |
61 | - s.summary = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model." | |
62 | - s.email = "dc.rec1@gmail.com" | |
63 | - s.homepage = "http://github.com/dcrec1/acts_as_solr_reloaded" | |
64 | - s.description = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model." | |
65 | - s.authors = ["Diego Carrion"] | |
66 | - s.files = FileList["[A-Z]*", "{bin,generators,config,lib,solr}/**/*"] + | |
67 | - FileList["test/**/*"].reject {|f| f.include?("test/log")}.reject {|f| f.include?("test/tmp")} | |
68 | - end | |
69 | -rescue LoadError | |
70 | - puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler" | |
71 | -end | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/config/solr_environment.rb
... | ... | @@ -6,23 +6,19 @@ require 'net/http' |
6 | 6 | |
7 | 7 | dir = File.dirname(__FILE__) |
8 | 8 | SOLR_PATH = File.expand_path("#{dir}/../solr") unless defined? SOLR_PATH |
9 | -config = YAML::load_file(RAILS_ROOT+'/plugins/solr/config/solr.yml') | |
9 | +config = YAML::load_file("#{Rails.root}/plugins/solr/config/solr.yml") | |
10 | 10 | |
11 | -unless defined? RAILS_ROOT | |
12 | - # define RAILS_ROOT for test environment | |
13 | - RAILS_ROOT = defined?(Rails) ? Rails.root : File.expand_path("#{File.dirname(__FILE__)}/../test") | |
14 | -end | |
15 | 11 | unless defined? RAILS_ENV |
16 | 12 | RAILS_ENV = ENV['RAILS_ENV'] |
17 | 13 | end |
18 | 14 | unless defined? SOLR_LOGS_PATH |
19 | - SOLR_LOGS_PATH = ENV["SOLR_LOGS_PATH"] || "#{RAILS_ROOT}/log" | |
15 | + SOLR_LOGS_PATH = ENV["SOLR_LOGS_PATH"] || "#{Rails.root}/log" | |
20 | 16 | end |
21 | 17 | unless defined? SOLR_PIDS_PATH |
22 | - SOLR_PIDS_PATH = ENV["SOLR_PIDS_PATH"] || "#{RAILS_ROOT}/tmp/pids" | |
18 | + SOLR_PIDS_PATH = ENV["SOLR_PIDS_PATH"] || "#{Rails.root}/tmp/pids" | |
23 | 19 | end |
24 | 20 | unless defined? SOLR_DATA_PATH |
25 | - SOLR_DATA_PATH = ENV["SOLR_DATA_PATH"] || config[ENV['RAILS_ENV']]['data_path'] || "#{RAILS_ROOT}/solr/#{ENV['RAILS_ENV']}" | |
21 | + SOLR_DATA_PATH = ENV["SOLR_DATA_PATH"] || config[ENV['RAILS_ENV']]['data_path'] || "#{Rails.root}/solr/#{ENV['RAILS_ENV']}" | |
26 | 22 | end |
27 | 23 | unless defined? SOLR_CONFIG_PATH |
28 | 24 | SOLR_CONFIG_PATH = ENV["SOLR_CONFIG_PATH"] || "#{SOLR_PATH}/solr" | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr.rb
... | ... | @@ -20,6 +20,7 @@ require File.dirname(__FILE__) + '/acts_as_solr/search_results' |
20 | 20 | require File.dirname(__FILE__) + '/acts_as_solr/lazy_document' |
21 | 21 | require File.dirname(__FILE__) + '/acts_as_solr/mongo_mapper' |
22 | 22 | require File.dirname(__FILE__) + '/acts_as_solr/post' |
23 | +require File.dirname(__FILE__) + '/acts_as_solr/scope_with_applied_names' | |
23 | 24 | |
24 | 25 | # reopen ActiveRecord and include the acts_as_solr method |
25 | 26 | ActiveRecord::Base.extend ActsAsSolr::ActsMethods | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/common_methods.rb
1 | 1 | module ActsAsSolr #:nodoc: |
2 | - | |
2 | + | |
3 | 3 | module CommonMethods |
4 | 4 | |
5 | 5 | TypeMapping = { |
... | ... | @@ -14,6 +14,7 @@ module ActsAsSolr #:nodoc: |
14 | 14 | :range_integer => "ri", |
15 | 15 | :facet => "facet", |
16 | 16 | :text => "t", |
17 | + :ngram_text => "nt", | |
17 | 18 | } |
18 | 19 | |
19 | 20 | # Converts field types into Solr types |
... | ... | @@ -39,39 +40,39 @@ module ActsAsSolr #:nodoc: |
39 | 40 | result = [result] unless result.is_a?(Array) |
40 | 41 | solr_batch_add result |
41 | 42 | end |
42 | - | |
43 | + | |
43 | 44 | # Sends an add command to Solr |
44 | 45 | def solr_add(add_xml) |
45 | 46 | ActsAsSolr::Post.execute(Solr::Request::AddDocument.new(add_xml)) |
46 | 47 | end |
47 | - | |
48 | + | |
48 | 49 | # Sends the delete command to Solr |
49 | 50 | def solr_delete(solr_ids) |
50 | 51 | ActsAsSolr::Post.execute(Solr::Request::Delete.new(:id => solr_ids)) |
51 | 52 | end |
52 | - | |
53 | + | |
53 | 54 | # Sends the commit command to Solr |
54 | 55 | def solr_commit |
55 | 56 | ActsAsSolr::Post.execute(Solr::Request::Commit.new) |
56 | 57 | end |
57 | - | |
58 | + | |
58 | 59 | # Optimizes the Solr index. Solr says: |
59 | - # | |
60 | - # Optimizations can take nearly ten minutes to run. | |
61 | - # We are presuming optimizations should be run once following large | |
60 | + # | |
61 | + # Optimizations can take nearly ten minutes to run. | |
62 | + # We are presuming optimizations should be run once following large | |
62 | 63 | # batch-like updates to the collection and/or once a day. |
63 | - # | |
64 | - # One of the solutions for this would be to create a cron job that | |
64 | + # | |
65 | + # One of the solutions for this would be to create a cron job that | |
65 | 66 | # runs every day at midnight and optmizes the index: |
66 | 67 | # 0 0 * * * /your_rails_dir/script/runner -e production "Model.solr_optimize" |
67 | - # | |
68 | + # | |
68 | 69 | def solr_optimize |
69 | 70 | ActsAsSolr::Post.execute(Solr::Request::Optimize.new) |
70 | 71 | end |
71 | - | |
72 | + | |
72 | 73 | # Returns the id for the given instance |
73 | - def record_id(object) | |
74 | - eval "object.#{object.class.primary_key}" | |
74 | + def record_id object | |
75 | + object.send object.class.primary_key | |
75 | 76 | end |
76 | 77 | end |
77 | 78 | end | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb
... | ... | @@ -4,12 +4,16 @@ module ActsAsSolr #:nodoc: |
4 | 4 | |
5 | 5 | # Method used by mostly all the ClassMethods when doing a search |
6 | 6 | def parse_query(query=nil, options={}) |
7 | - valid_options = [:models, :lazy, :core, :results_format, :sql_options, | |
7 | + valid_options = [ | |
8 | + :models, :lazy, :core, :results_format, :sql_options, | |
8 | 9 | :alternate_query, :boost_functions, :filter_queries, :facets, :sort, |
9 | 10 | :scores, :operator, :latitude, :longitude, :radius, :relevance, :highlight, |
10 | - :offset, :per_page, :limit, :page,] | |
11 | + :offset, :per_page, :limit, :page, | |
12 | + :query_fields, :default_field, | |
13 | + ] | |
11 | 14 | query_options = {} |
12 | 15 | options[:results_format] ||= :objects |
16 | + options[:default_field] ||= 'text' | |
13 | 17 | |
14 | 18 | return if query.nil? |
15 | 19 | raise "Query should be a string" unless query.is_a?(String) |
... | ... | @@ -49,77 +53,95 @@ module ActsAsSolr #:nodoc: |
49 | 53 | query_options[:rows] = per_page |
50 | 54 | query_options[:start] = offset |
51 | 55 | |
56 | + query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions] | |
57 | + | |
58 | + parse_facets query_options, options | |
59 | + parse_highlight query_options, options | |
60 | + parse_sort query_options, options | |
61 | + parse_location query_options, options | |
62 | + parse_query_fields query_options, options | |
63 | + | |
52 | 64 | query_options[:operator] = options[:operator] |
65 | + not_dismax = query_options[:operator] == :or | |
66 | + request = if not_dismax then Solr::Request::Standard.new(query_options) else Solr::Request::Dismax.new query_options end | |
67 | + ActsAsSolr::Post.execute request, options[:core] | |
68 | + rescue | |
69 | + raise "#{$query} There was a problem executing your search\n#{query_options.inspect}\n: #{$!} in #{$!.backtrace.first}" | |
70 | + end | |
71 | + end | |
53 | 72 | |
54 | - query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions] | |
73 | + def parse_query_fields query_options, options | |
74 | + options[:query_fields] ||= [] | |
75 | + query_options[:query_fields] = replace_types([*options[:query_fields]], '').join ' ' | |
76 | + end | |
77 | + | |
78 | + def parse_sort query_options, options | |
79 | + query_options[:sort] = replace_types([*options[:sort]], '')[0] if options[:sort] | |
80 | + end | |
55 | 81 | |
56 | - # first steps on the facet parameter processing | |
57 | - if options[:facets] | |
58 | - query_options[:facets] = {} | |
59 | - query_options[:facets][:limit] = -1 # TODO: make this configurable | |
60 | - query_options[:facets][:sort] = :count if options[:facets][:sort] | |
61 | - query_options[:facets][:mincount] = 0 | |
62 | - query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false | |
63 | - # override the :zeros (it's deprecated anyway) if :mincount exists | |
64 | - query_options[:facets][:mincount] = options[:facets][:mincount] if options[:facets][:mincount] | |
65 | - query_options[:facets][:fields] = options[:facets][:fields].map{ |k| "#{k}_facet" } if options[:facets][:fields] | |
66 | - query_options[:filter_queries] += replace_types([*options[:facets][:browse]]) if options[:facets][:browse] | |
67 | - query_options[:facets][:queries] = replace_types([*options[:facets][:query]]) if options[:facets][:query] | |
68 | - | |
69 | - if options[:facets][:dates] | |
70 | - query_options[:date_facets] = {} | |
71 | - # if options[:facets][:dates][:fields] exists then :start, :end, and :gap must be there | |
72 | - if options[:facets][:dates][:fields] | |
73 | - [:start, :end, :gap].each { |k| raise "#{k} must be present in faceted date query" unless options[:facets][:dates].include?(k) } | |
74 | - query_options[:date_facets][:fields] = [] | |
75 | - options[:facets][:dates][:fields].each { |f| | |
76 | - if f.kind_of? Hash | |
77 | - key = f.keys[0] | |
78 | - query_options[:date_facets][:fields] << {"#{key}_d" => f[key]} | |
79 | - validate_date_facet_other_options(f[key][:other]) if f[key][:other] | |
80 | - else | |
81 | - query_options[:date_facets][:fields] << "#{f}_d" | |
82 | - end | |
83 | - } | |
84 | - end | |
85 | - | |
86 | - query_options[:date_facets][:start] = options[:facets][:dates][:start] if options[:facets][:dates][:start] | |
87 | - query_options[:date_facets][:end] = options[:facets][:dates][:end] if options[:facets][:dates][:end] | |
88 | - query_options[:date_facets][:gap] = options[:facets][:dates][:gap] if options[:facets][:dates][:gap] | |
89 | - query_options[:date_facets][:hardend] = options[:facets][:dates][:hardend] if options[:facets][:dates][:hardend] | |
90 | - query_options[:date_facets][:filter] = replace_types([*options[:facets][:dates][:filter]].collect{|k| "#{k.dup.sub!(/ *:(?!\d) */,"_d:")}"}) if options[:facets][:dates][:filter] | |
91 | - | |
92 | - if options[:facets][:dates][:other] | |
93 | - validate_date_facet_other_options(options[:facets][:dates][:other]) | |
94 | - query_options[:date_facets][:other] = options[:facets][:dates][:other] | |
95 | - end | |
82 | + def parse_location query_options, options | |
83 | + if options[:radius] | |
84 | + query_options[:radius] = options[:radius] | |
85 | + query_options[:filter_queries] << '{!geofilt}' | |
86 | + end | |
87 | + query_options[:latitude] = options[:latitude] | |
88 | + query_options[:longitude] = options[:longitude] | |
89 | + end | |
96 | 90 | |
91 | + def parse_highlight query_options, options | |
92 | + if options[:highlight] | |
93 | + query_options[:highlighting] = {} | |
94 | + query_options[:highlighting][:field_list] = replace_types([*options[:highlight][:fields]], '') if options[:highlight][:fields] | |
95 | + query_options[:highlighting][:require_field_match] = options[:highlight][:require_field_match] if options[:highlight][:require_field_match] | |
96 | + query_options[:highlighting][:max_snippets] = options[:highlight][:max_snippets] if options[:highlight][:max_snippets] | |
97 | + query_options[:highlighting][:prefix] = options[:highlight][:prefix] if options[:highlight][:prefix] | |
98 | + query_options[:highlighting][:suffix] = options[:highlight][:suffix] if options[:highlight][:suffix] | |
99 | + end | |
100 | + end | |
101 | + | |
102 | + def parse_facets query_options, options | |
103 | + # first steps on the facet parameter processing | |
104 | + if options[:facets] | |
105 | + query_options[:facets] = {} | |
106 | + query_options[:facets][:limit] = -1 # TODO: make this configurable | |
107 | + query_options[:facets][:sort] = :count if options[:facets][:sort] | |
108 | + query_options[:facets][:mincount] = 0 | |
109 | + query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false | |
110 | + # override the :zeros (it's deprecated anyway) if :mincount exists | |
111 | + query_options[:facets][:mincount] = options[:facets][:mincount] if options[:facets][:mincount] | |
112 | + query_options[:facets][:fields] = options[:facets][:fields].map{ |k| "#{k}_facet" } if options[:facets][:fields] | |
113 | + query_options[:filter_queries] += replace_types([*options[:facets][:browse]]) if options[:facets][:browse] | |
114 | + query_options[:facets][:queries] = replace_types([*options[:facets][:query]]) if options[:facets][:query] | |
115 | + | |
116 | + if options[:facets][:dates] | |
117 | + query_options[:date_facets] = {} | |
118 | + # if options[:facets][:dates][:fields] exists then :start, :end, and :gap must be there | |
119 | + if options[:facets][:dates][:fields] | |
120 | + [:start, :end, :gap].each { |k| raise "#{k} must be present in faceted date query" unless options[:facets][:dates].include?(k) } | |
121 | + query_options[:date_facets][:fields] = [] | |
122 | + options[:facets][:dates][:fields].each { |f| | |
123 | + if f.kind_of? Hash | |
124 | + key = f.keys[0] | |
125 | + query_options[:date_facets][:fields] << {"#{key}_d" => f[key]} | |
126 | + validate_date_facet_other_options(f[key][:other]) if f[key][:other] | |
127 | + else | |
128 | + query_options[:date_facets][:fields] << "#{f}_d" | |
129 | + end | |
130 | + } | |
97 | 131 | end |
98 | - end | |
99 | 132 | |
100 | - if options[:highlight] | |
101 | - query_options[:highlighting] = {} | |
102 | - query_options[:highlighting][:field_list] = replace_types([*options[:highlight][:fields]], '') if options[:highlight][:fields] | |
103 | - query_options[:highlighting][:require_field_match] = options[:highlight][:require_field_match] if options[:highlight][:require_field_match] | |
104 | - query_options[:highlighting][:max_snippets] = options[:highlight][:max_snippets] if options[:highlight][:max_snippets] | |
105 | - query_options[:highlighting][:prefix] = options[:highlight][:prefix] if options[:highlight][:prefix] | |
106 | - query_options[:highlighting][:suffix] = options[:highlight][:suffix] if options[:highlight][:suffix] | |
107 | - end | |
133 | + query_options[:date_facets][:start] = options[:facets][:dates][:start] if options[:facets][:dates][:start] | |
134 | + query_options[:date_facets][:end] = options[:facets][:dates][:end] if options[:facets][:dates][:end] | |
135 | + query_options[:date_facets][:gap] = options[:facets][:dates][:gap] if options[:facets][:dates][:gap] | |
136 | + query_options[:date_facets][:hardend] = options[:facets][:dates][:hardend] if options[:facets][:dates][:hardend] | |
137 | + query_options[:date_facets][:filter] = replace_types([*options[:facets][:dates][:filter]].collect{|k| "#{k.dup.sub!(/ *:(?!\d) */,"_d:")}"}) if options[:facets][:dates][:filter] | |
108 | 138 | |
109 | - query_options[:sort] = replace_types([*options[:sort]], '')[0] if options[:sort] | |
139 | + if options[:facets][:dates][:other] | |
140 | + validate_date_facet_other_options(options[:facets][:dates][:other]) | |
141 | + query_options[:date_facets][:other] = options[:facets][:dates][:other] | |
142 | + end | |
110 | 143 | |
111 | - if options[:radius] | |
112 | - query_options[:radius] = options[:radius] | |
113 | - query_options[:filter_queries] << '{!geofilt}' | |
114 | 144 | end |
115 | - query_options[:latitude] = options[:latitude] | |
116 | - query_options[:longitude] = options[:longitude] | |
117 | - | |
118 | - not_dismax = query_options[:operator] == :or | |
119 | - request = not_dismax ? Solr::Request::Standard.new(query_options) : Solr::Request::Dismax.new(query_options) | |
120 | - ActsAsSolr::Post.execute(request, options[:core]) | |
121 | - rescue | |
122 | - raise "#{$query} There was a problem executing your search\n#{query_options.inspect}\n: #{$!} in #{$!.backtrace.first}" | |
123 | 145 | end |
124 | 146 | end |
125 | 147 | |
... | ... | @@ -148,21 +170,21 @@ module ActsAsSolr #:nodoc: |
148 | 170 | results.update :start => header['params']['start'] |
149 | 171 | end |
150 | 172 | |
151 | - results.update(:facets => {'facet_fields' => []}) if options[:facets] | |
173 | + results.update(:facets => {'facet_fields' => {}}) if options[:facets] | |
152 | 174 | return SearchResults.new(results) if solr_data.total_hits == 0 |
153 | 175 | |
154 | 176 | results.update(:facets => solr_data.data['facet_counts']) if options[:facets] |
155 | 177 | |
156 | - ids = solr_data.hits.collect {|doc| doc["#{solr_configuration[:primary_key_field]}"]}.flatten | |
157 | - result = find_objects(ids, options) | |
158 | - results.update(:docs => result) | |
178 | + ids = solr_data.hits.collect{ |doc| doc["#{solr_configuration[:primary_key_field]}"] }.flatten | |
179 | + result = find_objects ids, options | |
180 | + results.update :ids => ids, :docs => result | |
159 | 181 | |
160 | 182 | add_scores(result, solr_data) if options[:results_format] == :objects and options[:scores] |
161 | 183 | |
162 | 184 | highlighted = {} |
163 | 185 | solr_data.highlighting.map do |x,y| |
164 | 186 | e={} |
165 | - y1=y.map{|x1,y1| e[x1.gsub(/_[^_]*/,"")]=y1} unless y.nil? | |
187 | + y.map{ |x1,y1| e[x1.gsub(/_[^_]*/,"")]=y1 } unless y.nil? | |
166 | 188 | highlighted[x.gsub(/[^:]*:/,"").to_i]=e |
167 | 189 | end unless solr_data.highlighting.nil? |
168 | 190 | results.update(:highlights => highlighted) |
... | ... | @@ -179,8 +201,12 @@ module ActsAsSolr #:nodoc: |
179 | 201 | ids.collect{ |id| ActsAsSolr::LazyDocument.new(id, self) } |
180 | 202 | elsif options[:results_format] == :objects |
181 | 203 | find_options = options[:sql_options] || {} |
182 | - find_options[:conditions] = self.send :merge_conditions, {self.primary_key => ids}, (find_options[:conditions] || []) | |
183 | - result = self.all(find_options) || [] | |
204 | + if Rails::VERSION::STRING >= '3.0' | |
205 | + result = self.scoped(find_options).where(self.primary_key => ids).all | |
206 | + else | |
207 | + find_options[:conditions] = self.send :merge_conditions, {self.primary_key => ids}, (find_options[:conditions] || []) | |
208 | + result = self.all(find_options) | |
209 | + end | |
184 | 210 | result = reorder(result, ids) unless find_options[:order] |
185 | 211 | result |
186 | 212 | elsif options[:results_format] == :none |
... | ... | @@ -226,22 +252,15 @@ module ActsAsSolr #:nodoc: |
226 | 252 | def add_scores(results, solr_data) |
227 | 253 | with_score = [] |
228 | 254 | solr_data.hits.each do |doc| |
229 | - with_score.push([doc["score"], | |
230 | - results.find {|record| scorable_record?(record, doc) }]) | |
231 | - end | |
232 | - with_score.each do |score, object| | |
233 | - class << object; attr_accessor :solr_score; end | |
234 | - object.solr_score = score | |
255 | + record = results.find do |result| | |
256 | + doc_id = doc["#{solr_configuration[:primary_key_field]}"].first rescue nil | |
257 | + record_id(result).to_s == doc_id | |
258 | + end | |
259 | + with_score.push [doc["score"], record] | |
235 | 260 | end |
236 | - end | |
237 | - | |
238 | - def scorable_record?(record, doc) | |
239 | - doc_id = doc["#{solr_configuration[:primary_key_field]}"] | |
240 | - if doc_id.nil? | |
241 | - doc_id = doc["id"] | |
242 | - "#{record.class.name}:#{record_id(record)}" == doc_id.first.to_s | |
243 | - else | |
244 | - record_id(record).to_s == doc_id.to_s | |
261 | + with_score.each do |score, record| | |
262 | + next unless record | |
263 | + record.solr_score = score | |
245 | 264 | end |
246 | 265 | end |
247 | 266 | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/scope_with_applied_names.rb
0 → 100644
... | ... | @@ -0,0 +1,91 @@ |
1 | + | |
2 | +if Rails::VERSION::STRING >= "3.2" | |
3 | + module ::ActiveRecord | |
4 | + | |
5 | + class Relation | |
6 | + attr_accessor :scopes_applied | |
7 | + end | |
8 | + | |
9 | + module Scoping | |
10 | + module Named | |
11 | + module ClassMethods | |
12 | + attr_accessor :scope_name, :scopes_applied | |
13 | + | |
14 | + def scope_with_applied_names name, scope_options = {} | |
15 | + name = name.to_sym | |
16 | + valid_scope_name?(name) | |
17 | + extension = Module.new(&Proc.new) if block_given? | |
18 | + | |
19 | + scope_proc = lambda do |*args| | |
20 | + options = scope_options.respond_to?(:call) ? unscoped { scope_options.call(*args) } : scope_options | |
21 | + options = scoped.apply_finder_options(options) if options.is_a?(Hash) | |
22 | + | |
23 | + relation = scoped.merge(options) | |
24 | + relation.scopes_applied ||= Set.new | |
25 | + relation.scopes_applied << name | |
26 | + | |
27 | + extension ? relation.extending(extension) : relation | |
28 | + end | |
29 | + | |
30 | + singleton_class.send(:redefine_method, name, &scope_proc) | |
31 | + end | |
32 | + alias_method_chain :scope, :applied_names | |
33 | + | |
34 | + end | |
35 | + end | |
36 | + end | |
37 | + end | |
38 | +else | |
39 | + require_dependency 'active_record/named_scope' | |
40 | + | |
41 | + module ::ActiveRecord | |
42 | + module NamedScope | |
43 | + module ClassMethods | |
44 | + | |
45 | + def named_scope_with_applied_names name, options = {}, &block | |
46 | + named_scope_without_applied_names name, options, &block | |
47 | + | |
48 | + name = name.to_sym | |
49 | + scopes[name] = lambda do |parent_scope, *args| | |
50 | + scope = Scope.new(parent_scope, case options | |
51 | + when Hash | |
52 | + options | |
53 | + when Proc | |
54 | + if self.model_name != parent_scope.model_name | |
55 | + options.bind(parent_scope).call(*args) | |
56 | + else | |
57 | + options.call(*args) | |
58 | + end | |
59 | + end, &block) | |
60 | + scope.scope_name = name | |
61 | + scope | |
62 | + end | |
63 | + end | |
64 | + alias_method_chain :named_scope, :applied_names | |
65 | + end | |
66 | + | |
67 | + class Scope | |
68 | + attr_accessor :scope_name, :scopes_applied | |
69 | + | |
70 | + def initialize_with_applied_names proxy_scope, options, &block | |
71 | + initialize_without_applied_names proxy_scope, options, &block | |
72 | + self.scopes_applied ||= [] | |
73 | + self.scopes_applied += proxy_scope.send :scopes_applied if Scope === proxy_scope | |
74 | + | |
75 | + # unrelated bugfix: use if instead of unless | |
76 | + if (Scope === proxy_scope || ActiveRecord::Associations::AssociationCollection === proxy_scope) | |
77 | + @current_scoped_methods_when_defined = proxy_scope.send(:current_scoped_methods) | |
78 | + end | |
79 | + end | |
80 | + alias_method_chain :initialize, :applied_names | |
81 | + | |
82 | + def scope_name= name | |
83 | + @scope_name = name | |
84 | + self.scopes_applied << @scope_name | |
85 | + end | |
86 | + | |
87 | + end | |
88 | + | |
89 | + end | |
90 | + end | |
91 | +end | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/dismax.rb
... | ... | @@ -12,13 +12,15 @@ |
12 | 12 | |
13 | 13 | class Solr::Request::Dismax < Solr::Request::Standard |
14 | 14 | |
15 | - VALID_PARAMS.replace(VALID_PARAMS + [:tie_breaker, :query_fields, :minimum_match, :phrase_fields, :phrase_slop, | |
16 | - :alternate_query, :boost_query, :boost_functions]) | |
15 | + VALID_PARAMS.replace VALID_PARAMS + [ | |
16 | + :tie_breaker, :query_fields, :minimum_match, :phrase_fields, :phrase_slop, | |
17 | + :alternate_query, :boost_query, :boost_functions, | |
18 | + ] | |
17 | 19 | |
18 | 20 | def initialize(params) |
19 | 21 | super |
20 | 22 | end |
21 | - | |
23 | + | |
22 | 24 | def to_hash |
23 | 25 | hash = super |
24 | 26 | hash[:defType] = 'edismax' | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb
... | ... | @@ -12,40 +12,42 @@ |
12 | 12 | |
13 | 13 | class Solr::Request::Standard < Solr::Request::Select |
14 | 14 | |
15 | - VALID_PARAMS = [:query, :sort, :default_field, :operator, :start, :rows, :shards, :date_facets, | |
16 | - :filter_queries, :field_list, :debug_query, :explain_other, :facets, :highlighting, :mlt, :radius, | |
17 | - :radius, :latitude, :longitude, :spellcheck] | |
18 | - | |
15 | + VALID_PARAMS = [ | |
16 | + :query, :sort, :default_field, :operator, :start, :rows, :shards, :date_facets, | |
17 | + :filter_queries, :field_list, :debug_query, :explain_other, :facets, :highlighting, :mlt, :radius, | |
18 | + :radius, :latitude, :longitude, :spellcheck, | |
19 | + ] | |
20 | + | |
19 | 21 | def initialize(params) |
20 | 22 | super 'search' |
21 | - | |
22 | - raise "Invalid parameters: #{(params.keys - VALID_PARAMS).join(',')}" unless | |
23 | + | |
24 | + raise "Invalid parameters: #{(params.keys - VALID_PARAMS).join(',')}" unless | |
23 | 25 | (params.keys - VALID_PARAMS).empty? |
24 | - | |
26 | + | |
25 | 27 | raise ":query parameter required" unless params[:query] |
26 | - | |
28 | + | |
27 | 29 | @params = params.dup |
28 | - | |
30 | + | |
29 | 31 | # Validate operator |
30 | 32 | if params[:operator] |
31 | - raise "Only :and/:or operators allowed" unless | |
33 | + raise "Only :and/:or operators allowed" unless | |
32 | 34 | [:and, :or].include?(params[:operator]) |
33 | - | |
35 | + | |
34 | 36 | @params[:operator] = params[:operator].to_s.upcase |
35 | 37 | end |
36 | 38 | |
37 | 39 | # Validate start, rows can be transformed to ints |
38 | 40 | @params[:start] = params[:start].to_i if params[:start] |
39 | 41 | @params[:rows] = params[:rows].to_i if params[:rows] |
40 | - | |
42 | + | |
41 | 43 | @params[:field_list] ||= ["*","score"] |
42 | - | |
44 | + | |
43 | 45 | @params[:shards] ||= [] |
44 | 46 | end |
45 | - | |
47 | + | |
46 | 48 | def to_hash |
47 | 49 | hash = {} |
48 | - | |
50 | + | |
49 | 51 | # standard request param processing |
50 | 52 | hash[:sort] = @params[:sort] |
51 | 53 | hash[:q] = @params[:query] |
... | ... | @@ -61,11 +63,11 @@ class Solr::Request::Standard < Solr::Request::Select |
61 | 63 | hash[:debugQuery] = @params[:debug_query] |
62 | 64 | hash[:explainOther] = @params[:explain_other] |
63 | 65 | hash[:shards] = @params[:shards].join(',') unless @params[:shards].empty? |
64 | - | |
66 | + | |
65 | 67 | hash[:sfield] = 'latlng' |
66 | 68 | hash[:d] = @params[:radius] |
67 | 69 | hash[:pt] = "#{@params[:latitude]}, #{@params[:longitude]}" if @params[:latitude] and @params[:longitude] |
68 | - | |
70 | + | |
69 | 71 | # facet parameter processing |
70 | 72 | if @params[:facets] |
71 | 73 | # TODO need validation of all that is under the :facets Hash too |
... | ... | @@ -95,7 +97,7 @@ class Solr::Request::Standard < Solr::Request::Select |
95 | 97 | end |
96 | 98 | end |
97 | 99 | end |
98 | - | |
100 | + | |
99 | 101 | if @params[:date_facets] |
100 | 102 | hash["facet.date"] = [] |
101 | 103 | if @params[:date_facets][:fields] |
... | ... | @@ -125,7 +127,7 @@ class Solr::Request::Standard < Solr::Request::Select |
125 | 127 | end |
126 | 128 | end |
127 | 129 | end |
128 | - | |
130 | + | |
129 | 131 | # highlighting parameter processing - http://wiki.apache.org/solr/HighlightingParameters |
130 | 132 | if @params[:highlighting] |
131 | 133 | hash[:hl] = true |
... | ... | @@ -385,7 +387,7 @@ class Solr::Request::Standard < Solr::Request::Select |
385 | 387 | end |
386 | 388 | |
387 | 389 | end |
388 | - | |
390 | + | |
389 | 391 | if @params[:mlt] |
390 | 392 | hash[:mlt] = true |
391 | 393 | hash["mlt.count"] = @params[:mlt][:count] |
... | ... | @@ -398,10 +400,10 @@ class Solr::Request::Standard < Solr::Request::Select |
398 | 400 | hash["mlt.maxntp"] = @params[:mlt][:max_tokens_parsed] |
399 | 401 | hash["mlt.boost"] = @params[:mlt][:boost] |
400 | 402 | end |
401 | - | |
403 | + | |
402 | 404 | hash[:spellcheck] = true |
403 | 405 | hash['spellcheck.collate'] = true |
404 | - | |
406 | + | |
405 | 407 | hash.merge(super.to_hash) |
406 | 408 | end |
407 | 409 | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/response/ruby.rb
... | ... | @@ -14,13 +14,14 @@ class Solr::Response::Ruby < Solr::Response::Base |
14 | 14 | attr_reader :data, :header |
15 | 15 | |
16 | 16 | def initialize(ruby_code) |
17 | + ruby_code.force_encoding('UTF-8') if RUBY_VERSION >= '1.9' | |
17 | 18 | super |
18 | 19 | begin |
19 | 20 | #TODO: what about pulling up data/header/response to ResponseBase, |
20 | 21 | # or maybe a new middle class like SelectResponseBase since |
21 | 22 | # all Select queries return this same sort of stuff?? |
22 | 23 | # XML (&wt=xml) and Ruby (&wt=ruby) responses contain exactly the same structure. |
23 | - # a goal of solrb is to make it irrelevant which gets used under the hood, | |
24 | + # a goal of solrb is to make it irrelevant which gets used under the hood, | |
24 | 25 | # but favor Ruby responses. |
25 | 26 | @data = eval(ruby_code) |
26 | 27 | @header = @data['responseHeader'] |
... | ... | @@ -38,5 +39,5 @@ class Solr::Response::Ruby < Solr::Response::Base |
38 | 39 | def query_time |
39 | 40 | @header['QTime'] |
40 | 41 | end |
41 | - | |
42 | + | |
42 | 43 | end | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/response/xml.rb
... | ... | @@ -18,7 +18,7 @@ class Solr::Response::Xml < Solr::Response::Base |
18 | 18 | # parse the xml |
19 | 19 | @doc = REXML::Document.new(xml) |
20 | 20 | |
21 | - # look for the result code and string | |
21 | + # look for the result code and string | |
22 | 22 | # <?xml version="1.0" encoding="UTF-8"?> |
23 | 23 | # <response> |
24 | 24 | # <lst name="responseHeader"><int name="status">0</int><int name="QTime">2</int></lst> | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/database.rake
... | ... | @@ -5,12 +5,12 @@ namespace :db do |
5 | 5 | begin |
6 | 6 | ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "*:*")) |
7 | 7 | ActsAsSolr::Post.execute(Solr::Request::Commit.new) |
8 | - (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file| | |
8 | + (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(Rails.root, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file| | |
9 | 9 | ActsAsSolr::SolrFixtures.load(File.basename(fixture_file, '.*')) |
10 | - end | |
11 | - puts "The fixtures loaded have been added to Solr" | |
10 | + end | |
11 | + puts "The fixtures loaded have been added to Solr" | |
12 | 12 | rescue |
13 | 13 | end |
14 | 14 | end |
15 | 15 | end |
16 | -end | |
17 | 16 | \ No newline at end of file |
17 | +end | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/jeweler.rake
0 → 100644
... | ... | @@ -0,0 +1,15 @@ |
1 | +begin | |
2 | + require 'jeweler' | |
3 | +rescue LoadError | |
4 | +end | |
5 | + | |
6 | +Jeweler::Tasks.new do |s| | |
7 | + s.name = "acts_as_solr_reloaded" | |
8 | + s.summary = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model." | |
9 | + s.email = "dc.rec1@gmail.com" | |
10 | + s.homepage = "http://github.com/dcrec1/acts_as_solr_reloaded" | |
11 | + s.description = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model." | |
12 | + s.authors = ["Diego Carrion"] | |
13 | + s.files = FileList["[A-Z]*", "{bin,generators,config,lib,solr}/**/*"] + | |
14 | + FileList["test/**/*"].reject {|f| f.include?("test/log")}.reject {|f| f.include?("test/tmp")} | |
15 | +end if defined? Jeweler | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/rdoc.rake
0 → 100644
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake
... | ... | @@ -158,7 +158,7 @@ namespace :solr do |
158 | 158 | |
159 | 159 | logger = ActiveRecord::Base.logger = Logger.new(STDOUT) |
160 | 160 | logger.level = ActiveSupport::BufferedLogger::INFO unless debug_output |
161 | - Dir["#{RAILS_ROOT}/app/models/*.rb"].each{ |file| require file } | |
161 | + Dir["#{Rails.root}/app/models/*.rb"].each{ |file| require file } | |
162 | 162 | |
163 | 163 | if start_server |
164 | 164 | puts "Starting Solr server..." | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/test.rake
1 | + | |
2 | +desc "Default Task" | |
3 | +task :default => [:test] | |
4 | + | |
5 | +desc "Runs the unit tests" | |
6 | +task :test => "test:unit" | |
7 | + | |
1 | 8 | namespace :test do |
9 | + | |
2 | 10 | task :migrate do |
11 | + ActiveRecord::Base.logger = Logger.new(STDOUT) | |
3 | 12 | ActiveRecord::Migrator.migrate("test/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) |
4 | 13 | end |
14 | + | |
15 | + task :setup do | |
16 | + DB ||= 'sqlite' | |
17 | + puts "Using " + DB | |
18 | + %x(mysql -u#{MYSQL_USER} < #{File.dirname(__FILE__) + "/test/fixtures/db_definitions/mysql.sql"}) if DB == 'mysql' | |
19 | + | |
20 | + Rake::Task["test:migrate"].invoke | |
21 | + end | |
22 | + | |
23 | + desc 'Measures test coverage using rcov' | |
24 | + task :rcov => :setup do | |
25 | + rm_f "coverage" | |
26 | + rm_f "coverage.data" | |
27 | + rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib" | |
28 | + | |
29 | + system("#{rcov} --html #{Dir.glob('test/**/*_shoulda.rb').join(' ')}") | |
30 | + system("open coverage/index.html") if PLATFORM['darwin'] | |
31 | + end | |
32 | + | |
33 | + desc 'Runs the functional tests, testing integration with Solr' | |
34 | + Rake::TestTask.new(:functional => :setup) do |t| | |
35 | + t.pattern = "test/functional/*_test.rb" | |
36 | + t.verbose = true | |
37 | + end | |
38 | + | |
39 | + desc "Unit tests" | |
40 | + Rake::TestTask.new(:unit => :setup) do |t| | |
41 | + t.libs << 'test/unit' | |
42 | + t.pattern = "test/unit/*_shoulda.rb" | |
43 | + t.verbose = true | |
44 | + end | |
5 | 45 | end | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml
... | ... | @@ -57,11 +57,9 @@ |
57 | 57 | <fieldType name="text" class="solr.TextField" autoGeneratePhraseQueries="false"> |
58 | 58 | <analyzer type="index"> |
59 | 59 | <tokenizer class="solr.StandardTokenizerFactory"/> |
60 | - <filter class="solr.RemoveDuplicatesTokenFilterFactory"/> | |
61 | - | |
62 | 60 | <filter class="solr.ASCIIFoldingFilterFactory"/> |
63 | 61 | <filter class="solr.LowerCaseFilterFactory"/> |
64 | - | |
62 | + <filter class="solr.RemoveDuplicatesTokenFilterFactory"/> | |
65 | 63 | <filter class="solr.StopFilterFactory" words="stopwords.pt.txt" /> |
66 | 64 | |
67 | 65 | <!-- stemming |
... | ... | @@ -73,18 +71,12 @@ |
73 | 71 | <filter class="solr.HunspellStemFilterFactory" dictionary="en_US.dic" affix="en_US.aff" ignoreCase="true" /> |
74 | 72 | <filter class="solr.HunspellStemFilterFactory" dictionary="pt_PT.dic" affix="pt_PT.aff" ignoreCase="true" /> |
75 | 73 | --> |
76 | - | |
77 | - <!-- improvised stemming | |
78 | - <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="20" side="front"/> | |
79 | - --> | |
80 | 74 | </analyzer> |
81 | 75 | <analyzer type="query"> |
82 | 76 | <tokenizer class="solr.StandardTokenizerFactory"/> |
83 | - <filter class="solr.RemoveDuplicatesTokenFilterFactory"/> | |
84 | - | |
85 | 77 | <filter class="solr.ASCIIFoldingFilterFactory"/> |
86 | 78 | <filter class="solr.LowerCaseFilterFactory"/> |
87 | - | |
79 | + <filter class="solr.RemoveDuplicatesTokenFilterFactory"/> | |
88 | 80 | <filter class="solr.StopFilterFactory" words="stopwords.pt.txt" /> |
89 | 81 | |
90 | 82 | <!-- stemming |
... | ... | @@ -96,10 +88,23 @@ |
96 | 88 | <filter class="solr.HunspellStemFilterFactory" dictionary="en_US.dic" affix="en_US.aff" ignoreCase="true" /> |
97 | 89 | <filter class="solr.HunspellStemFilterFactory" dictionary="pt_PT.dic" affix="pt_PT.aff" ignoreCase="true" /> |
98 | 90 | --> |
91 | + </analyzer> | |
92 | + </fieldType> | |
99 | 93 | |
100 | - <!-- improvised stemming | |
101 | - <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="20" side="front"/> | |
102 | - --> | |
94 | + <fieldType name="ngramText" class="solr.TextField" positionIncrementGap="100"> | |
95 | + <analyzer type="index"> | |
96 | + <tokenizer class="solr.StandardTokenizerFactory"/> | |
97 | + <filter class="solr.ASCIIFoldingFilterFactory"/> | |
98 | + <filter class="solr.LowerCaseFilterFactory"/> | |
99 | + <filter class="solr.RemoveDuplicatesTokenFilterFactory"/> | |
100 | + | |
101 | + <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="20" side="front"/> | |
102 | + </analyzer> | |
103 | + <analyzer type="query"> | |
104 | + <tokenizer class="solr.StandardTokenizerFactory"/> | |
105 | + <filter class="solr.ASCIIFoldingFilterFactory"/> | |
106 | + <filter class="solr.LowerCaseFilterFactory"/> | |
107 | + <filter class="solr.RemoveDuplicatesTokenFilterFactory"/> | |
103 | 108 | </analyzer> |
104 | 109 | </fieldType> |
105 | 110 | |
... | ... | @@ -151,6 +156,7 @@ |
151 | 156 | <dynamicField name="*sortable_do" type="sdouble" indexed="true" stored="false" multiValued="false"/> |
152 | 157 | |
153 | 158 | <dynamicField name="*_t" type="text" indexed="true" stored="true" multiValued="true"/> |
159 | + <dynamicField name="*_nt" type="ngramText" indexed="true" stored="true" multiValued="true"/> | |
154 | 160 | <dynamicField name="*_s" type="text" indexed="true" stored="true" multiValued="false"/> |
155 | 161 | <dynamicField name="*_i" type="integer" indexed="true" stored="false" multiValued="true"/> |
156 | 162 | <dynamicField name="*_f" type="float" indexed="true" stored="true" multiValued="false"/> |
... | ... | @@ -168,6 +174,7 @@ |
168 | 174 | <field name="geo_distance" type="sdouble"/> <!-- Optional but used for distributed searching --> |
169 | 175 | |
170 | 176 | <field name="text" type="text" indexed="true" stored="false" multiValued="true"/> |
177 | + <field name="ngramText" type="ngramText" indexed="true" stored="false" multiValued="true"/> | |
171 | 178 | <field name="spell" type="textSpell" indexed="true" stored="true" multiValued="true"/> |
172 | 179 | |
173 | 180 | <dynamicField name="*_s_mv" type="string" indexed="true" stored="false" multiValued="true"/> |
... | ... | @@ -187,6 +194,10 @@ |
187 | 194 | <copyField source="*_do" dest="text"/> |
188 | 195 | <copyField source="*_facet" dest="text"/> |
189 | 196 | |
197 | + <copyField source="*_s" dest="ngramText"/> | |
198 | + <copyField source="*_t" dest="ngramText"/> | |
199 | + <copyField source="*_nt" dest="ngramText"/> | |
200 | + | |
190 | 201 | <copyField source="*_s" dest="spell"/> |
191 | 202 | <copyField source="*_t" dest="spell"/> |
192 | 203 | <copyField source="*_facet" dest="spell"/> | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/solr_test_rakefile.rb
plugins/solr/vendor/plugins/acts_as_solr_reloaded/test/fixtures/locals.yml
0 → 100644
plugins/solr/vendor/plugins/acts_as_solr_reloaded/test/test_helper.rb
... | ... | @@ -16,7 +16,7 @@ require 'mongo_mapper' |
16 | 16 | |
17 | 17 | class Rails |
18 | 18 | def self.root |
19 | - RAILS_ROOT | |
19 | + Rails.root | |
20 | 20 | end |
21 | 21 | |
22 | 22 | def self.env |
... | ... | @@ -26,13 +26,14 @@ end |
26 | 26 | |
27 | 27 | MongoMapper.database = "acts_as_solr_reloaded-test" |
28 | 28 | |
29 | -RAILS_ROOT = File.dirname(__FILE__) unless defined? RAILS_ROOT | |
30 | -RAILS_ENV = 'test' unless defined? RAILS_ENV | |
29 | +RAILS_ENV = 'test' unless defined? RAILS_ENV | |
31 | 30 | ENV["RAILS_ENV"] = "test" |
32 | 31 | |
33 | 32 | require File.expand_path(File.dirname(__FILE__) + '/../config/solr_environment') |
34 | 33 | require File.expand_path(File.dirname(__FILE__) + '/../lib/acts_as_solr') |
35 | 34 | |
35 | +ActiveRecord::Base.logger = Logger.new('/dev/null') | |
36 | + | |
36 | 37 | # Load Models |
37 | 38 | models_dir = File.join(File.dirname( __FILE__ ), 'models') |
38 | 39 | require "#{models_dir}/book.rb" |
... | ... | @@ -60,10 +61,10 @@ class Test::Unit::TestCase |
60 | 61 | klass = instance_eval table_name.to_s.capitalize.singularize |
61 | 62 | klass.find(:all).each{|content| content.solr_save} |
62 | 63 | end |
63 | - | |
64 | + | |
64 | 65 | clear_from_solr(:novels) |
65 | 66 | end |
66 | - | |
67 | + | |
67 | 68 | private |
68 | 69 | def self.clear_from_solr(table_name) |
69 | 70 | ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "type_s:#{table_name.to_s.capitalize.singularize}")) | ... | ... |
plugins/solr/vendor/plugins/named_scope_with_applied_names/init.rb
... | ... | @@ -1,57 +0,0 @@ |
1 | -require_dependency 'active_record/named_scope' | |
2 | - | |
3 | -if Rails::VERSION::STRING < "2.3.99" | |
4 | - | |
5 | - module ::ActiveRecord | |
6 | - | |
7 | - module NamedScope | |
8 | - | |
9 | - module ClassMethods | |
10 | - | |
11 | - def named_scope_with_applied_names name, options = {}, &block | |
12 | - named_scope_without_applied_names name, options, &block | |
13 | - | |
14 | - name = name.to_sym | |
15 | - scopes[name] = lambda do |parent_scope, *args| | |
16 | - scope = Scope.new(parent_scope, case options | |
17 | - when Hash | |
18 | - options | |
19 | - when Proc | |
20 | - if self.model_name != parent_scope.model_name | |
21 | - options.bind(parent_scope).call(*args) | |
22 | - else | |
23 | - options.call(*args) | |
24 | - end | |
25 | - end, &block) | |
26 | - scope.scope_name = name | |
27 | - scope | |
28 | - end | |
29 | - end | |
30 | - alias_method_chain :named_scope, :applied_names | |
31 | - end | |
32 | - | |
33 | - class Scope | |
34 | - attr_accessor :scope_name, :scopes_applied | |
35 | - | |
36 | - def initialize_with_applied_names proxy_scope, options, &block | |
37 | - initialize_without_applied_names proxy_scope, options, &block | |
38 | - self.scopes_applied ||= [] | |
39 | - self.scopes_applied += proxy_scope.send :scopes_applied if Scope === proxy_scope | |
40 | - | |
41 | - # unrelated bugfix: use if instead of unless | |
42 | - if (Scope === proxy_scope || ActiveRecord::Associations::AssociationCollection === proxy_scope) | |
43 | - @current_scoped_methods_when_defined = proxy_scope.send(:current_scoped_methods) | |
44 | - end | |
45 | - end | |
46 | - alias_method_chain :initialize, :applied_names | |
47 | - | |
48 | - def scope_name= name | |
49 | - @scope_name = name | |
50 | - self.scopes_applied << @scope_name | |
51 | - end | |
52 | - | |
53 | - end | |
54 | - | |
55 | - end | |
56 | - end | |
57 | -end |