Commit ce943de2cce501077ef9eda802167df1a255afb1
1 parent
0ffb2519
Exists in
master
and in
29 other branches
Update acts_as_solr_reloaded
Changes from https://github.com/coletivoEITA/acts_as_solr_reloaded
Showing
35 changed files
with
497 additions
and
378 deletions
Show diff stats
vendor/plugins/acts_as_solr_reloaded/.gitignore
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +before_script: | ||
2 | + - mongo mydb_test --eval 'db.addUser("travis", "test");' | ||
3 | + - gem update --system 1.4.1 > /dev/null 2>&1 | ||
4 | + - rake solr:download | ||
5 | + - RAILS_ENV=test rake solr:start | ||
6 | + | ||
7 | +script: "bundle exec rake $TASK --trace" | ||
8 | + | ||
9 | +rvm: | ||
10 | + - 1.8.7 | ||
11 | +env: | ||
12 | + - TASK=test | ||
13 | + - TASK=test:functional |
vendor/plugins/acts_as_solr_reloaded/README.markdown
1 | +[](http://travis-ci.org/coletivoEITA/acts_as_solr_reloaded) | ||
2 | + | ||
1 | Description | 3 | Description |
2 | ====== | 4 | ====== |
3 | This plugin adds full text search capabilities and many other nifty features from Apache's [Solr](http://lucene.apache.org/solr/) to any Rails model. | 5 | This plugin adds full text search capabilities and many other nifty features from Apache's [Solr](http://lucene.apache.org/solr/) to any Rails model. |
@@ -6,6 +8,8 @@ It was based on the first draft by Erik Hatcher. | @@ -6,6 +8,8 @@ It was based on the first draft by Erik Hatcher. | ||
6 | This plugin is intended for use in old versions of Rails. For newer versions, I strongly advice using Sunspot! | 8 | This plugin is intended for use in old versions of Rails. For newer versions, I strongly advice using Sunspot! |
7 | Nevertheless, this plugin is used for Noosfero project in production. Any problem please open an issue. | 9 | Nevertheless, this plugin is used for Noosfero project in production. Any problem please open an issue. |
8 | 10 | ||
11 | +It should support Rails 2.1 (and greater 2.x) and is developed latest Solr versions, so don't expect it to run on older Solr. | ||
12 | + | ||
9 | Installation | 13 | Installation |
10 | ====== | 14 | ====== |
11 | 15 |
vendor/plugins/acts_as_solr_reloaded/Rakefile
@@ -3,6 +3,9 @@ require 'rake' | @@ -3,6 +3,9 @@ require 'rake' | ||
3 | require 'rake/testtask' | 3 | require 'rake/testtask' |
4 | require 'rake/rdoctask' | 4 | require 'rake/rdoctask' |
5 | 5 | ||
6 | +ENV['RAILS_ENV'] = "test" | ||
7 | +require File.expand_path("#{File.dirname(__FILE__)}/config/solr_environment") | ||
8 | + | ||
6 | Dir["#{File.dirname(__FILE__)}/lib/tasks/*.rake"].sort.each { |ext| load ext } | 9 | Dir["#{File.dirname(__FILE__)}/lib/tasks/*.rake"].sort.each { |ext| load ext } |
7 | 10 | ||
8 | desc "Default Task" | 11 | desc "Default Task" |
@@ -13,10 +16,7 @@ task :test => "test:unit" | @@ -13,10 +16,7 @@ task :test => "test:unit" | ||
13 | 16 | ||
14 | namespace :test do | 17 | namespace :test do |
15 | task :setup do | 18 | task :setup do |
16 | - RAILS_ROOT = File.expand_path("#{File.dirname(__FILE__)}/test") unless defined? RAILS_ROOT | ||
17 | - ENV['RAILS_ENV'] = "test" | ||
18 | - ENV["ACTS_AS_SOLR_TEST"] = "true" | ||
19 | - require File.expand_path("#{File.dirname(__FILE__)}/config/solr_environment") | 19 | + DB ||= 'sqlite' |
20 | puts "Using " + DB | 20 | puts "Using " + DB |
21 | %x(mysql -u#{MYSQL_USER} < #{File.dirname(__FILE__) + "/test/fixtures/db_definitions/mysql.sql"}) if DB == 'mysql' | 21 | %x(mysql -u#{MYSQL_USER} < #{File.dirname(__FILE__) + "/test/fixtures/db_definitions/mysql.sql"}) if DB == 'mysql' |
22 | 22 | ||
@@ -34,13 +34,13 @@ namespace :test do | @@ -34,13 +34,13 @@ namespace :test do | ||
34 | end | 34 | end |
35 | 35 | ||
36 | desc 'Runs the functional tests, testing integration with Solr' | 36 | desc 'Runs the functional tests, testing integration with Solr' |
37 | - Rake::TestTask.new('functional' => :setup) do |t| | 37 | + Rake::TestTask.new(:functional => :setup) do |t| |
38 | t.pattern = "test/functional/*_test.rb" | 38 | t.pattern = "test/functional/*_test.rb" |
39 | t.verbose = true | 39 | t.verbose = true |
40 | end | 40 | end |
41 | 41 | ||
42 | desc "Unit tests" | 42 | desc "Unit tests" |
43 | - Rake::TestTask.new(:unit) do |t| | 43 | + Rake::TestTask.new(:unit => :setup) do |t| |
44 | t.libs << 'test/unit' | 44 | t.libs << 'test/unit' |
45 | t.pattern = "test/unit/*_shoulda.rb" | 45 | t.pattern = "test/unit/*_shoulda.rb" |
46 | t.verbose = true | 46 | t.verbose = true |
vendor/plugins/acts_as_solr_reloaded/TESTING_THE_PLUGIN
1 | acts_as_solr comes with a quick and fast unit test suite, and with a longer-running | 1 | acts_as_solr comes with a quick and fast unit test suite, and with a longer-running |
2 | functional test suite, the latter testing the actual integration with Solr. | 2 | functional test suite, the latter testing the actual integration with Solr. |
3 | 3 | ||
4 | -The unit test suite is written using Shoulda, so make sure you have a recent version | ||
5 | -installed. | 4 | +== Install dependencies |
5 | +sudo apt-get install mongodb-server | ||
6 | +bundle install | ||
7 | +gem update --system 1.4.1 | ||
6 | 8 | ||
7 | -Running `rake test` or just `rake` will run both test suites. Use `rake test:unit` to | ||
8 | -just run the unit test suite. | ||
9 | - | ||
10 | -== How to run functional tests for this plugin: | 9 | +== Running test |
11 | To run the acts_as_solr's plugin tests run the following steps: | 10 | To run the acts_as_solr's plugin tests run the following steps: |
12 | 11 | ||
13 | -- create a MySQL database called "actsassolr_test" (if you want to use MySQL) | 12 | +- RAILS_ENV=test rake solr:start |
14 | 13 | ||
15 | -- create a new Rails project, if needed (the plugin can only be tested from within a Rails project); move/checkout acts_as_solr into its vendor/plugins/, as usual | ||
16 | - | ||
17 | -- copy vendor/plugins/acts_as_solr_reloaded/config/solr.yml to config/ (the Rails config folder) | ||
18 | - | ||
19 | -- rake solr:start RAILS_ENV=test | 14 | +- rake test:unit |
15 | +(or just rake test) | ||
20 | 16 | ||
21 | - rake test:functional (Accepts the following arguments: DB=sqlite|mysql and MYSQL_USER=user) | 17 | - rake test:functional (Accepts the following arguments: DB=sqlite|mysql and MYSQL_USER=user) |
22 | 18 |
vendor/plugins/acts_as_solr_reloaded/config/solr_environment.rb
1 | -ENV['RAILS_ENV'] = (ENV['RAILS_ENV'] || 'development').dup | 1 | +ENV['RAILS_ENV'] = (ENV['RAILS_ENV'] || 'development').dup |
2 | require "uri" | 2 | require "uri" |
3 | require "fileutils" | 3 | require "fileutils" |
4 | require "yaml" | 4 | require "yaml" |
5 | +require 'net/http' | ||
6 | + | ||
5 | dir = File.dirname(__FILE__) | 7 | dir = File.dirname(__FILE__) |
6 | SOLR_PATH = File.expand_path("#{dir}/../solr") unless defined? SOLR_PATH | 8 | SOLR_PATH = File.expand_path("#{dir}/../solr") unless defined? SOLR_PATH |
7 | 9 | ||
8 | -# RAILS_ROOT isn't defined yet, so figure it out. | ||
9 | unless defined? RAILS_ROOT | 10 | unless defined? RAILS_ROOT |
10 | - RAILS_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../test") | 11 | + # define RAILS_ROOT for test environment |
12 | + RAILS_ROOT = defined?(Rails) ? Rails.root : File.expand_path("#{File.dirname(__FILE__)}/../test") | ||
13 | +end | ||
14 | +unless defined? RAILS_ENV | ||
15 | + RAILS_ENV = ENV['RAILS_ENV'] | ||
11 | end | 16 | end |
12 | unless defined? SOLR_LOGS_PATH | 17 | unless defined? SOLR_LOGS_PATH |
13 | SOLR_LOGS_PATH = ENV["SOLR_LOGS_PATH"] || "#{RAILS_ROOT}/log" | 18 | SOLR_LOGS_PATH = ENV["SOLR_LOGS_PATH"] || "#{RAILS_ROOT}/log" |
@@ -35,9 +40,10 @@ end | @@ -35,9 +40,10 @@ end | ||
35 | 40 | ||
36 | SOLR_JVM_OPTIONS = config[ENV['RAILS_ENV']]['jvm_options'] unless defined? SOLR_JVM_OPTIONS | 41 | SOLR_JVM_OPTIONS = config[ENV['RAILS_ENV']]['jvm_options'] unless defined? SOLR_JVM_OPTIONS |
37 | 42 | ||
38 | -if ENV["ACTS_AS_SOLR_TEST"] | ||
39 | - require "activerecord" | 43 | +if ENV["RAILS_ENV"] == 'test' |
44 | + require "active_record" | ||
40 | DB = (ENV['DB'] ? ENV['DB'] : 'sqlite') unless defined?(DB) | 45 | DB = (ENV['DB'] ? ENV['DB'] : 'sqlite') unless defined?(DB) |
41 | MYSQL_USER = (ENV['MYSQL_USER'].nil? ? 'root' : ENV['MYSQL_USER']) unless defined? MYSQL_USER | 46 | MYSQL_USER = (ENV['MYSQL_USER'].nil? ? 'root' : ENV['MYSQL_USER']) unless defined? MYSQL_USER |
42 | require File.join(File.dirname(File.expand_path(__FILE__)), '..', 'test', 'db', 'connections', DB, 'connection.rb') | 47 | require File.join(File.dirname(File.expand_path(__FILE__)), '..', 'test', 'db', 'connections', DB, 'connection.rb') |
43 | end | 48 | end |
49 | + |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb
@@ -262,6 +262,7 @@ module ActsAsSolr #:nodoc: | @@ -262,6 +262,7 @@ module ActsAsSolr #:nodoc: | ||
262 | def process_solr_options(options={}, solr_options={}) | 262 | def process_solr_options(options={}, solr_options={}) |
263 | self.configuration = { | 263 | self.configuration = { |
264 | :fields => nil, | 264 | :fields => nil, |
265 | + :format => :objects, | ||
265 | :additional_fields => nil, | 266 | :additional_fields => nil, |
266 | :dynamic_attributes => false, | 267 | :dynamic_attributes => false, |
267 | :exclude_fields => [], | 268 | :exclude_fields => [], |
@@ -279,6 +280,7 @@ module ActsAsSolr #:nodoc: | @@ -279,6 +280,7 @@ module ActsAsSolr #:nodoc: | ||
279 | :default_boost => 1.0, | 280 | :default_boost => 1.0, |
280 | } | 281 | } |
281 | 282 | ||
283 | + solr_options ||= {} | ||
282 | raise "Invalid options: #{(options.keys-configuration.keys).join(',')}" unless (options.keys-configuration.keys).empty? | 284 | raise "Invalid options: #{(options.keys-configuration.keys).join(',')}" unless (options.keys-configuration.keys).empty? |
283 | raise "Invalid solr options: #{(solr_options.keys-solr_configuration.keys).join(',')}" unless (solr_options.keys-solr_configuration.keys).empty? | 285 | raise "Invalid solr options: #{(solr_options.keys-solr_configuration.keys).join(',')}" unless (solr_options.keys-solr_configuration.keys).empty? |
284 | 286 | ||
@@ -366,7 +368,7 @@ module ActsAsSolr #:nodoc: | @@ -366,7 +368,7 @@ module ActsAsSolr #:nodoc: | ||
366 | column_type = format_column_type(column.type) | 368 | column_type = format_column_type(column.type) |
367 | 369 | ||
368 | case column_type | 370 | case column_type |
369 | - when :string then :text | 371 | + when :string then :string |
370 | when :datetime then :date | 372 | when :datetime then :date |
371 | when :time then :date | 373 | when :time then :date |
372 | else column_type | 374 | else column_type |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/class_methods.rb
@@ -24,9 +24,9 @@ module ActsAsSolr #:nodoc: | @@ -24,9 +24,9 @@ module ActsAsSolr #:nodoc: | ||
24 | # | 24 | # |
25 | # Book.find_by_solr 'ruby', :filter_queries => ['price:5'] | 25 | # Book.find_by_solr 'ruby', :filter_queries => ['price:5'] |
26 | # | 26 | # |
27 | - # order:: - Orders (sort by) the result set using a given criteria: | 27 | + # sort:: - Orders (sort by) the result set using a given criteria: |
28 | # | 28 | # |
29 | - # Book.find_by_solr 'ruby', :order => 'description asc' | 29 | + # Book.find_by_solr 'ruby', :sort => 'description asc' |
30 | # | 30 | # |
31 | # field_types:: This option is deprecated and will be obsolete by version 1.0. | 31 | # field_types:: This option is deprecated and will be obsolete by version 1.0. |
32 | # There's no need to specify the :field_types anymore when doing a | 32 | # There's no need to specify the :field_types anymore when doing a |
@@ -156,9 +156,8 @@ module ActsAsSolr #:nodoc: | @@ -156,9 +156,8 @@ module ActsAsSolr #:nodoc: | ||
156 | # => 0.12321548 | 156 | # => 0.12321548 |
157 | # | 157 | # |
158 | def multi_solr_search(query, options = {}) | 158 | def multi_solr_search(query, options = {}) |
159 | - models = multi_model_suffix(options) | ||
160 | options.update(:results_format => :objects) unless options[:results_format] | 159 | options.update(:results_format => :objects) unless options[:results_format] |
161 | - data = parse_query(query, options, models) | 160 | + data = parse_query(query, options) |
162 | 161 | ||
163 | if data.nil? or data.total_hits == 0 | 162 | if data.nil? or data.total_hits == 0 |
164 | return SearchResults.new(:docs => [], :total => 0) | 163 | return SearchResults.new(:docs => [], :total => 0) |
@@ -184,12 +183,6 @@ module ActsAsSolr #:nodoc: | @@ -184,12 +183,6 @@ module ActsAsSolr #:nodoc: | ||
184 | result | 183 | result |
185 | end | 184 | end |
186 | 185 | ||
187 | - def multi_model_suffix(options) | ||
188 | - models = "AND (#{solr_configuration[:type_field]}:\"#{self.name}\"" | ||
189 | - models << " OR " + options[:models].collect {|m| "#{solr_configuration[:type_field]}:\"" + m.to_s + "\""}.join(" OR ") if options[:models].is_a?(Array) | ||
190 | - models << ")" | ||
191 | - end | ||
192 | - | ||
193 | # returns the total number of documents found in the query specified: | 186 | # returns the total number of documents found in the query specified: |
194 | # Book.count_by_solr 'rails' => 3 | 187 | # Book.count_by_solr 'rails' => 3 |
195 | # | 188 | # |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/deprecation.rb
@@ -29,7 +29,7 @@ module ActsAsSolr #:nodoc: | @@ -29,7 +29,7 @@ module ActsAsSolr #:nodoc: | ||
29 | "The field types are automatically traced back when you specify a field type in your model." | 29 | "The field types are automatically traced back when you specify a field type in your model." |
30 | end | 30 | end |
31 | if options[:sort_by] | 31 | if options[:sort_by] |
32 | - plog "The option :sort_by is deprecated, use :order instead!" | 32 | + plog "The option :sort_by is deprecated, use :sort instead!" |
33 | options[:sort] ||= options[:sort_by] | 33 | options[:sort] ||= options[:sort_by] |
34 | end | 34 | end |
35 | if options[:start] | 35 | if options[:start] |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/instance_methods.rb
@@ -51,7 +51,7 @@ module ActsAsSolr #:nodoc: | @@ -51,7 +51,7 @@ module ActsAsSolr #:nodoc: | ||
51 | field_type = get_solr_field_type(options[:type]) | 51 | field_type = get_solr_field_type(options[:type]) |
52 | solr_name = options[:as] || field_name | 52 | solr_name = options[:as] || field_name |
53 | 53 | ||
54 | - value = self.send("#{field_name}_for_solr") | 54 | + value = self.send("#{field_name}_for_solr") rescue nil |
55 | next if value.nil? | 55 | next if value.nil? |
56 | 56 | ||
57 | suffix = get_solr_field_type(field_type) | 57 | suffix = get_solr_field_type(field_type) |
@@ -60,7 +60,7 @@ module ActsAsSolr #:nodoc: | @@ -60,7 +60,7 @@ module ActsAsSolr #:nodoc: | ||
60 | 60 | ||
61 | field = Solr::Field.new(:name => "#{solr_name}_#{suffix}", :value => value) | 61 | field = Solr::Field.new(:name => "#{solr_name}_#{suffix}", :value => value) |
62 | processed_boost = validate_boost(field_boost) | 62 | processed_boost = validate_boost(field_boost) |
63 | - field.boost = processed_boost if processed_boost != solr_configuration[:default_boost] | 63 | + field.boost = processed_boost |
64 | doc << field | 64 | doc << field |
65 | end | 65 | end |
66 | 66 | ||
@@ -81,8 +81,8 @@ module ActsAsSolr #:nodoc: | @@ -81,8 +81,8 @@ module ActsAsSolr #:nodoc: | ||
81 | 81 | ||
82 | def add_space(doc) | 82 | def add_space(doc) |
83 | if configuration[:spatial] and local | 83 | if configuration[:spatial] and local |
84 | - doc << Solr::Field.new(:name => "lat", :value => local.latitude) | ||
85 | - doc << Solr::Field.new(:name => "lng", :value => local.longitude) | 84 | + doc << Solr::Field.new(:name => "lat_f", :value => local.latitude) |
85 | + doc << Solr::Field.new(:name => "lng_f", :value => local.longitude) | ||
86 | end | 86 | end |
87 | end | 87 | end |
88 | 88 | ||
@@ -96,8 +96,8 @@ module ActsAsSolr #:nodoc: | @@ -96,8 +96,8 @@ module ActsAsSolr #:nodoc: | ||
96 | def add_dynamic_attributes(doc) | 96 | def add_dynamic_attributes(doc) |
97 | dynamic_attributes.each do |attribute| | 97 | dynamic_attributes.each do |attribute| |
98 | value = ERB::Util.html_escape(attribute.value) | 98 | value = ERB::Util.html_escape(attribute.value) |
99 | - doc << Solr::Field.new(:name => "#{attribute.name}_t", :value => value) | ||
100 | - doc << Solr::Field.new(:name => "#{attribute.name}_facet", :value => value) | 99 | + doc << Solr::Field.new(:name => "#{attribute.name.downcase}_t", :value => value) |
100 | + doc << Solr::Field.new(:name => "#{attribute.name.downcase}_facet", :value => value) | ||
101 | end if configuration[:dynamic_attributes] | 101 | end if configuration[:dynamic_attributes] |
102 | end | 102 | end |
103 | 103 | ||
@@ -117,7 +117,7 @@ module ActsAsSolr #:nodoc: | @@ -117,7 +117,7 @@ module ActsAsSolr #:nodoc: | ||
117 | Array(data).each do |value| | 117 | Array(data).each do |value| |
118 | field = Solr::Field.new(:name => "#{field_name}_#{suffix}", :value => value) | 118 | field = Solr::Field.new(:name => "#{field_name}_#{suffix}", :value => value) |
119 | processed_boost = validate_boost(field_boost) | 119 | processed_boost = validate_boost(field_boost) |
120 | - field.boost = processed_boost if processed_boost != solr_configuration[:default_boost] | 120 | + field.boost = processed_boost |
121 | doc << field | 121 | doc << field |
122 | end | 122 | end |
123 | end | 123 | end |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/mongo_mapper.rb
@@ -13,14 +13,11 @@ module ActsAsSolr | @@ -13,14 +13,11 @@ module ActsAsSolr | ||
13 | def primary_key | 13 | def primary_key |
14 | 'id' | 14 | 'id' |
15 | end | 15 | end |
16 | - | ||
17 | - def find(*args) | ||
18 | - if args.first.instance_of? Array | ||
19 | - ids = args.first.map { |id| Mongo::ObjectID.from_string(id) } | ||
20 | - super :all, :conditions => {primary_key => ids} | ||
21 | - else | ||
22 | - super *args | ||
23 | - end | 16 | + |
17 | + def merge_conditions(*args) | ||
18 | + ret = {} | ||
19 | + args.each{ |a| ret.merge!(a) if a.is_a?(Hash) } | ||
20 | + ret | ||
24 | end | 21 | end |
25 | end | 22 | end |
26 | end | 23 | end |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb
@@ -3,38 +3,43 @@ module ActsAsSolr #:nodoc: | @@ -3,38 +3,43 @@ module ActsAsSolr #:nodoc: | ||
3 | protected | 3 | protected |
4 | 4 | ||
5 | # Method used by mostly all the ClassMethods when doing a search | 5 | # Method used by mostly all the ClassMethods when doing a search |
6 | - def parse_query(query=nil, options={}, models=nil) | ||
7 | - valid_options = [ :alternate_query, :boost_functions, :filter_queries, :facets, :models, :sort, | ||
8 | - :scores, :operator, :lazy, :core, :latitude, :longitude, :radius, :relevance, :highlight, | ||
9 | - :offset, :per_page, :limit, :page, | ||
10 | - :results_format, :sql_options] | 6 | + def parse_query(query=nil, options={}) |
7 | + valid_options = [:models, :lazy, :core, :results_format, :sql_options, | ||
8 | + :alternate_query, :boost_functions, :filter_queries, :facets, :sort, | ||
9 | + :scores, :operator, :latitude, :longitude, :radius, :relevance, :highlight, | ||
10 | + :offset, :per_page, :limit, :page,] | ||
11 | query_options = {} | 11 | query_options = {} |
12 | 12 | ||
13 | - field_list = models.nil? ? solr_configuration[:primary_key_field] : "id" | ||
14 | - query_options[:field_list] = [field_list, 'score'] | ||
15 | - query_options[:filter_queries] = [] | ||
16 | - #allow empty queries as a type search will also be done | ||
17 | - query = nil if (query.nil? || query == '') | ||
18 | - if query.nil? | ||
19 | - query = solr_type_condition | ||
20 | - else | ||
21 | - query = sanitize_query(query) | ||
22 | - query_options[:filter_queries].push(solr_type_condition) | ||
23 | - end | ||
24 | - query_options[:query] = "#{options[:alternate_query]} #{query}" | ||
25 | - | 13 | + return if query.nil? |
14 | + raise "Query should be a string" unless query.is_a?(String) | ||
26 | raise "Invalid parameters: #{(options.keys - valid_options).join(',')}" unless (options.keys - valid_options).empty? | 15 | raise "Invalid parameters: #{(options.keys - valid_options).join(',')}" unless (options.keys - valid_options).empty? |
27 | begin | 16 | begin |
28 | Deprecation.validate_query(options) | 17 | Deprecation.validate_query(options) |
18 | + | ||
19 | + if options[:alternate_query] | ||
20 | + query = query.blank? ? '*:*' : sanitize_query(query) | ||
21 | + query = "#{options[:alternate_query]} #{query}" | ||
22 | + else | ||
23 | + query = query.blank? ? '*:*' : sanitize_query(query) | ||
24 | + end | ||
25 | + | ||
26 | + query = replace_types([*query], ':').first # put types on filtered fields | ||
27 | + query = add_relevance query, options[:relevance] | ||
28 | + query_options[:query] = query | ||
29 | + | ||
30 | + field_list = options[:models].nil? ? solr_configuration[:primary_key_field] : "id" | ||
31 | + query_options[:field_list] = [field_list, 'score'] | ||
32 | + | ||
29 | per_page = options[:per_page] || options[:limit] || 30 | 33 | per_page = options[:per_page] || options[:limit] || 30 |
30 | offset = options[:offset] || (((options[:page] || 1).to_i - 1) * per_page) | 34 | offset = options[:offset] || (((options[:page] || 1).to_i - 1) * per_page) |
31 | query_options[:rows] = per_page | 35 | query_options[:rows] = per_page |
32 | query_options[:start] = offset | 36 | query_options[:start] = offset |
33 | - query_options[:operator] = options[:operator] | ||
34 | 37 | ||
35 | - query = add_relevance query, options[:relevance] | 38 | + query_options[:operator] = options[:operator] |
36 | 39 | ||
40 | + query_options[:filter_queries] = [solr_type_condition(options)] | ||
37 | query_options[:filter_queries] += replace_types([*options[:filter_queries]], '') if options[:filter_queries] | 41 | query_options[:filter_queries] += replace_types([*options[:filter_queries]], '') if options[:filter_queries] |
42 | + | ||
38 | query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions] | 43 | query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions] |
39 | 44 | ||
40 | # first steps on the facet parameter processing | 45 | # first steps on the facet parameter processing |
@@ -46,9 +51,9 @@ module ActsAsSolr #:nodoc: | @@ -46,9 +51,9 @@ module ActsAsSolr #:nodoc: | ||
46 | query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false | 51 | query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false |
47 | # override the :zeros (it's deprecated anyway) if :mincount exists | 52 | # override the :zeros (it's deprecated anyway) if :mincount exists |
48 | query_options[:facets][:mincount] = options[:facets][:mincount] if options[:facets][:mincount] | 53 | query_options[:facets][:mincount] = options[:facets][:mincount] if options[:facets][:mincount] |
49 | - query_options[:facets][:fields] = options[:facets][:fields].collect{|k| "#{k}_facet"} if options[:facets][:fields] | 54 | + query_options[:facets][:fields] = options[:facets][:fields].map{ |k| "#{k}_facet" } if options[:facets][:fields] |
50 | query_options[:filter_queries] += replace_types([*options[:facets][:browse]]) if options[:facets][:browse] | 55 | query_options[:filter_queries] += replace_types([*options[:facets][:browse]]) if options[:facets][:browse] |
51 | - query_options[:facets][:queries] = replace_types(options[:facets][:query]) if options[:facets][:query] | 56 | + query_options[:facets][:queries] = replace_types([*options[:facets][:query]]) if options[:facets][:query] |
52 | 57 | ||
53 | if options[:facets][:dates] | 58 | if options[:facets][:dates] |
54 | query_options[:date_facets] = {} | 59 | query_options[:date_facets] = {} |
@@ -75,7 +80,7 @@ module ActsAsSolr #:nodoc: | @@ -75,7 +80,7 @@ module ActsAsSolr #:nodoc: | ||
75 | 80 | ||
76 | if options[:facets][:dates][:other] | 81 | if options[:facets][:dates][:other] |
77 | validate_date_facet_other_options(options[:facets][:dates][:other]) | 82 | validate_date_facet_other_options(options[:facets][:dates][:other]) |
78 | - query_options[:date_facets][:other] = options[:facets][:dates][:other] | 83 | + query_options[:date_facets][:other] = options[:facets][:dates][:other] |
79 | end | 84 | end |
80 | 85 | ||
81 | end | 86 | end |
@@ -83,30 +88,36 @@ module ActsAsSolr #:nodoc: | @@ -83,30 +88,36 @@ module ActsAsSolr #:nodoc: | ||
83 | 88 | ||
84 | if options[:highlight] | 89 | if options[:highlight] |
85 | query_options[:highlighting] = {} | 90 | query_options[:highlighting] = {} |
86 | - query_options[:highlighting][:field_list] = [] | ||
87 | - query_options[:highlighting][:field_list] << options[:highlight][:fields].collect {|k| "#{k}_t"} if options[:highlight][:fields] | 91 | + query_options[:highlighting][:field_list] = replace_types([*options[:highlight][:fields]], '') if options[:highlight][:fields] |
88 | query_options[:highlighting][:require_field_match] = options[:highlight][:require_field_match] if options[:highlight][:require_field_match] | 92 | query_options[:highlighting][:require_field_match] = options[:highlight][:require_field_match] if options[:highlight][:require_field_match] |
89 | query_options[:highlighting][:max_snippets] = options[:highlight][:max_snippets] if options[:highlight][:max_snippets] | 93 | query_options[:highlighting][:max_snippets] = options[:highlight][:max_snippets] if options[:highlight][:max_snippets] |
90 | query_options[:highlighting][:prefix] = options[:highlight][:prefix] if options[:highlight][:prefix] | 94 | query_options[:highlighting][:prefix] = options[:highlight][:prefix] if options[:highlight][:prefix] |
91 | query_options[:highlighting][:suffix] = options[:highlight][:suffix] if options[:highlight][:suffix] | 95 | query_options[:highlighting][:suffix] = options[:highlight][:suffix] if options[:highlight][:suffix] |
92 | end | 96 | end |
93 | 97 | ||
94 | - query_options[:sort] = replace_types([options[:sort]], '')[0] if options[:sort] | 98 | + query_options[:sort] = replace_types([*options[:sort]], '')[0] if options[:sort] |
95 | 99 | ||
96 | - query_options[:radius] = options[:radius] | 100 | + if options[:radius] |
101 | + query_options[:radius] = options[:radius] | ||
102 | + query_options[:filter_queries] << '{!geofilt}' | ||
103 | + end | ||
97 | query_options[:latitude] = options[:latitude] | 104 | query_options[:latitude] = options[:latitude] |
98 | query_options[:longitude] = options[:longitude] | 105 | query_options[:longitude] = options[:longitude] |
99 | 106 | ||
100 | - ActsAsSolr::Post.execute(Solr::Request::Dismax.new(query_options), options[:core]) | 107 | + not_dismax = query_options[:operator] == :or |
108 | + request = not_dismax ? Solr::Request::Standard.new(query_options) : Solr::Request::Dismax.new(query_options) | ||
109 | + ActsAsSolr::Post.execute(request, options[:core]) | ||
101 | rescue | 110 | rescue |
102 | raise "#{$query} There was a problem executing your search\n#{query_options.inspect}\n: #{$!} in #{$!.backtrace.first}" | 111 | raise "#{$query} There was a problem executing your search\n#{query_options.inspect}\n: #{$!} in #{$!.backtrace.first}" |
103 | end | 112 | end |
104 | end | 113 | end |
105 | 114 | ||
106 | - def solr_type_condition | ||
107 | - (subclasses || []).inject("(#{solr_configuration[:type_field]}:\"#{self.name}\"") do |condition, subclass| | ||
108 | - condition << (subclass.name.empty? ? "" : " OR #{solr_configuration[:type_field]}:\"#{subclass.name}\"") | ||
109 | - end << ')' | 115 | + def solr_type_condition(options = {}) |
116 | + classes = [self] + (self.subclasses || []) + (options[:models] || []) | ||
117 | + classes.map do |klass| | ||
118 | + next if klass.name.empty? | ||
119 | + "#{solr_configuration[:type_field]}:\"#{klass.name}\"" | ||
120 | + end.compact.join(' OR ') | ||
110 | end | 121 | end |
111 | 122 | ||
112 | # Parses the data returned from Solr | 123 | # Parses the data returned from Solr |
@@ -155,8 +166,8 @@ module ActsAsSolr #:nodoc: | @@ -155,8 +166,8 @@ module ActsAsSolr #:nodoc: | ||
155 | ids.collect {|id| ActsAsSolr::LazyDocument.new(id, self)} | 166 | ids.collect {|id| ActsAsSolr::LazyDocument.new(id, self)} |
156 | elsif configuration[:format] == :objects | 167 | elsif configuration[:format] == :objects |
157 | find_options = options[:sql_options] || {} | 168 | find_options = options[:sql_options] || {} |
158 | - find_options[:conditions] = self.send :merge_conditions, {:id => ids}, (find_options[:conditions] || []) | ||
159 | - result = self.all(find_options) | 169 | + find_options[:conditions] = self.send :merge_conditions, {self.primary_key => ids}, (find_options[:conditions] || []) |
170 | + result = self.all(find_options) || [] | ||
160 | result = reorder(result, ids) unless find_options[:order] | 171 | result = reorder(result, ids) unless find_options[:order] |
161 | result | 172 | result |
162 | else | 173 | else |
@@ -170,8 +181,8 @@ module ActsAsSolr #:nodoc: | @@ -170,8 +181,8 @@ module ActsAsSolr #:nodoc: | ||
170 | def reorder(things, ids) | 181 | def reorder(things, ids) |
171 | ordered_things = [] | 182 | ordered_things = [] |
172 | ids.each do |id| | 183 | ids.each do |id| |
173 | - thing = things.find { |t| t.id.to_s == id.to_s } | ||
174 | - ordered_things |= [thing] if thing | 184 | + thing = things.find{ |t| t.id.to_s == id.to_s } |
185 | + ordered_things |= [thing] if thing | ||
175 | end | 186 | end |
176 | ordered_things | 187 | ordered_things |
177 | end | 188 | end |
@@ -229,25 +240,22 @@ module ActsAsSolr #:nodoc: | @@ -229,25 +240,22 @@ module ActsAsSolr #:nodoc: | ||
229 | end | 240 | end |
230 | 241 | ||
231 | def sanitize_query(query) | 242 | def sanitize_query(query) |
232 | - Solr::Util::query_parser_escape query | 243 | + fields = self.configuration[:solr_fields].keys |
244 | + fields += DynamicAttribute.all(:select => 'name', :group => 'name').map(&:name) if DynamicAttribute.table_exists? | ||
245 | + Solr::Util::query_parser_escape query, fields | ||
233 | end | 246 | end |
234 | 247 | ||
235 | private | 248 | private |
236 | 249 | ||
237 | def add_relevance(query, relevance) | 250 | def add_relevance(query, relevance) |
238 | - return query if relevance.nil? | ||
239 | - q = if query.include? ':' | ||
240 | - q = query.split(":").first.split(" ") | ||
241 | - q.pop | ||
242 | - return query if q.empty? | ||
243 | - q.join ' ' | ||
244 | - else | ||
245 | - query | ||
246 | - end | ||
247 | - relevance.each do |attribute, value| | ||
248 | - query = "#{query} OR #{attribute}:(#{q})^#{value}" | 251 | + return query if relevance.nil? or query.include? ':' |
252 | + | ||
253 | + query = [query] + relevance.map do |attribute, value| | ||
254 | + "#{attribute}:(#{query})^#{value}" | ||
249 | end | 255 | end |
250 | - query | 256 | + query = query.join(' OR ') |
257 | + | ||
258 | + replace_types([query], '').first | ||
251 | end | 259 | end |
252 | 260 | ||
253 | end | 261 | end |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/search_results.rb
@@ -72,7 +72,7 @@ module ActsAsSolr #:nodoc: | @@ -72,7 +72,7 @@ module ActsAsSolr #:nodoc: | ||
72 | 72 | ||
73 | # Returns a suggested query | 73 | # Returns a suggested query |
74 | def suggest | 74 | def suggest |
75 | - @solr_data[:spellcheck]['suggestions']['collation'].match(/\((.+)\) /)[1] | 75 | + Hash[@solr_data[:spellcheck]['suggestions']]['collation'] |
76 | end | 76 | end |
77 | 77 | ||
78 | # Returns the number of documents per page | 78 | # Returns the number of documents per page |
@@ -82,12 +82,12 @@ module ActsAsSolr #:nodoc: | @@ -82,12 +82,12 @@ module ActsAsSolr #:nodoc: | ||
82 | 82 | ||
83 | # Returns the number of pages found | 83 | # Returns the number of pages found |
84 | def total_pages | 84 | def total_pages |
85 | - (total / per_page.to_f).ceil | 85 | + per_page.zero? ? 0 : (total / per_page.to_f).ceil |
86 | end | 86 | end |
87 | 87 | ||
88 | # Returns the current page | 88 | # Returns the current page |
89 | def current_page | 89 | def current_page |
90 | - (@solr_data[:start].to_i / per_page) + 1 | 90 | + per_page.zero? ? 0 : (@solr_data[:start].to_i / per_page) + 1 |
91 | end | 91 | end |
92 | 92 | ||
93 | def blank? | 93 | def blank? |
vendor/plugins/acts_as_solr_reloaded/lib/solr.rb
@@ -23,4 +23,5 @@ require File.expand_path("#{File.dirname(__FILE__)}/solr/xml") | @@ -23,4 +23,5 @@ require File.expand_path("#{File.dirname(__FILE__)}/solr/xml") | ||
23 | require File.expand_path("#{File.dirname(__FILE__)}/solr/field") | 23 | require File.expand_path("#{File.dirname(__FILE__)}/solr/field") |
24 | require File.expand_path("#{File.dirname(__FILE__)}/solr/request/base") | 24 | require File.expand_path("#{File.dirname(__FILE__)}/solr/request/base") |
25 | require File.expand_path("#{File.dirname(__FILE__)}/solr/document") | 25 | require File.expand_path("#{File.dirname(__FILE__)}/solr/document") |
26 | +require File.expand_path("#{File.dirname(__FILE__)}/solr/request/json_update") | ||
26 | require File.expand_path("#{File.dirname(__FILE__)}/solr/request/update") | 27 | require File.expand_path("#{File.dirname(__FILE__)}/solr/request/update") |
vendor/plugins/acts_as_solr_reloaded/lib/solr/field.rb
@@ -18,7 +18,7 @@ class Solr::Field | @@ -18,7 +18,7 @@ class Solr::Field | ||
18 | 18 | ||
19 | # Accepts an optional <tt>:boost</tt> parameter, used to boost the relevance of a particular field. | 19 | # Accepts an optional <tt>:boost</tt> parameter, used to boost the relevance of a particular field. |
20 | def initialize(params) | 20 | def initialize(params) |
21 | - @boost = params[:boost] == 1.0 ? nil : params[:boost] | 21 | + boost = params[:boost] |
22 | @name = params[:name].to_s | 22 | @name = params[:name].to_s |
23 | @value = params[:value] | 23 | @value = params[:value] |
24 | # Convert any Time values into UTC/XML schema format (which Solr requires). | 24 | # Convert any Time values into UTC/XML schema format (which Solr requires). |
@@ -29,6 +29,10 @@ class Solr::Field | @@ -29,6 +29,10 @@ class Solr::Field | ||
29 | @boost.nil? ? @value : {'boost' => @boost, 'value' => @value} | 29 | @boost.nil? ? @value : {'boost' => @boost, 'value' => @value} |
30 | end | 30 | end |
31 | 31 | ||
32 | + def boost=(value) | ||
33 | + @boost = value == 1.0 ? nil : value | ||
34 | + end | ||
35 | + | ||
32 | def to_xml | 36 | def to_xml |
33 | e = Solr::XML::Element.new 'field' | 37 | e = Solr::XML::Element.new 'field' |
34 | e.attributes['name'] = @name | 38 | e.attributes['name'] = @name |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/add_document.rb
@@ -10,6 +10,8 @@ | @@ -10,6 +10,8 @@ | ||
10 | # See the License for the specific language governing permissions and | 10 | # See the License for the specific language governing permissions and |
11 | # limitations under the License. | 11 | # limitations under the License. |
12 | 12 | ||
13 | +require File.expand_path(File.dirname(__FILE__) + '/json_update') | ||
14 | + | ||
13 | class Solr::Request::AddDocument < Solr::Request::JsonUpdate | 15 | class Solr::Request::AddDocument < Solr::Request::JsonUpdate |
14 | 16 | ||
15 | # create the request, optionally passing in a Solr::Document | 17 | # create the request, optionally passing in a Solr::Document |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb
@@ -64,7 +64,7 @@ class Solr::Request::Standard < Solr::Request::Select | @@ -64,7 +64,7 @@ class Solr::Request::Standard < Solr::Request::Select | ||
64 | 64 | ||
65 | hash[:sfield] = 'latlng' | 65 | hash[:sfield] = 'latlng' |
66 | hash[:d] = @params[:radius] | 66 | hash[:d] = @params[:radius] |
67 | - hash[:pt] = "#{@params[:latitude]}, #{@params[:longitude]}" | 67 | + hash[:pt] = "#{@params[:latitude]}, #{@params[:longitude]}" if @params[:latitude] and @params[:longitude] |
68 | 68 | ||
69 | # facet parameter processing | 69 | # facet parameter processing |
70 | if @params[:facets] | 70 | if @params[:facets] |
vendor/plugins/acts_as_solr_reloaded/lib/solr/util.rb
@@ -26,11 +26,21 @@ class Solr::Util | @@ -26,11 +26,21 @@ class Solr::Util | ||
26 | end | 26 | end |
27 | 27 | ||
28 | # from http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html#Escaping Special Characters | 28 | # from http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html#Escaping Special Characters |
29 | - ESCAPES = %w[+ - && || ! ( ) { } \[ \] ^ " ~ * ? : \] | 29 | + ESCAPES = %w[+ - && || ! ( ) { } \[ \] " ~ * ? \] |
30 | 30 | ||
31 | - def self.query_parser_escape(string) | ||
32 | - string = string.dup | 31 | + def self.query_parser_escape(string, fields = []) |
32 | + string = string.split(' ').map do |str| | ||
33 | + if /(\w+):(.*)/ =~ str # escape : considering fields | ||
34 | + (!$2.empty? and fields.include?($1.to_sym)) ? "#{$1}:#{$2}" : "#{$1}\\:#{$2}" | ||
35 | + elsif /^\^(.*)/ =~ str # escape ^ | ||
36 | + "\\^#{$1}" | ||
37 | + else | ||
38 | + str | ||
39 | + end | ||
40 | + end.join(' ') | ||
41 | + | ||
33 | ESCAPES.each { |e| string.gsub! e, "\\#{e}" } | 42 | ESCAPES.each { |e| string.gsub! e, "\\#{e}" } |
34 | string | 43 | string |
35 | end | 44 | end |
45 | + | ||
36 | end | 46 | end |
vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake
@@ -6,9 +6,12 @@ namespace :solr do | @@ -6,9 +6,12 @@ namespace :solr do | ||
6 | SOLR_DIR = "apache-solr-#{SOLR_VERSION}" | 6 | SOLR_DIR = "apache-solr-#{SOLR_VERSION}" |
7 | SOLR_URL = "#{APACHE_MIRROR}/lucene/solr/#{SOLR_VERSION}/#{SOLR_FILENAME}" | 7 | SOLR_URL = "#{APACHE_MIRROR}/lucene/solr/#{SOLR_VERSION}/#{SOLR_FILENAME}" |
8 | 8 | ||
9 | + # change path if it is on testing environment | ||
10 | + PLUGIN_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../..") | ||
11 | + | ||
9 | desc "Download and install Solr+Jetty #{SOLR_VERSION}." | 12 | desc "Download and install Solr+Jetty #{SOLR_VERSION}." |
10 | task :download do | 13 | task :download do |
11 | - if File.exists?(Rails.root + 'vendor/plugins/acts_as_solr_reloaded/solr/start.jar') | 14 | + if File.exists?("#{PLUGIN_ROOT}/solr/start.jar") |
12 | puts 'Solr already downloaded.' | 15 | puts 'Solr already downloaded.' |
13 | else | 16 | else |
14 | Dir.chdir '/tmp' do | 17 | Dir.chdir '/tmp' do |
@@ -17,16 +20,16 @@ namespace :solr do | @@ -17,16 +20,16 @@ namespace :solr do | ||
17 | sh "tar xzf apache-solr-#{SOLR_VERSION}.tgz" | 20 | sh "tar xzf apache-solr-#{SOLR_VERSION}.tgz" |
18 | end | 21 | end |
19 | cd "apache-solr-#{SOLR_VERSION}/example" | 22 | cd "apache-solr-#{SOLR_VERSION}/example" |
20 | - cp_r ['../LICENSE.txt', '../NOTICE.txt', 'README.txt', 'etc', 'lib', 'start.jar', 'webapps', 'work'], Rails.root + 'vendor/plugins/acts_as_solr_reloaded/solr', :verbose => true | 23 | + cp_r ['../LICENSE.txt', '../NOTICE.txt', 'README.txt', 'etc', 'lib', 'start.jar', 'webapps', 'work'], "#{PLUGIN_ROOT}/solr", :verbose => true |
21 | cd 'solr' | 24 | cd 'solr' |
22 | - cp_r ['README.txt', 'bin', 'solr.xml'], Rails.root + 'vendor/plugins/acts_as_solr_reloaded/solr/solr', :verbose => true | 25 | + cp_r ['README.txt', 'bin', 'solr.xml'], "#{PLUGIN_ROOT}/solr/solr", :verbose => true |
23 | end | 26 | end |
24 | end | 27 | end |
25 | end | 28 | end |
26 | 29 | ||
27 | desc 'Remove Solr instalation from the tree.' | 30 | desc 'Remove Solr instalation from the tree.' |
28 | task :remove do | 31 | task :remove do |
29 | - solr_root = Rails.root + 'vendor/plugins/acts_as_solr_reloaded/solr/' | 32 | + solr_root = "#{PLUGIN_ROOT}/solr/" |
30 | rm_r ['README.txt', 'bin', 'solr.xml'].map{ |i| File.join(solr_root, 'solr', i) }, :verbose => true, :force => true | 33 | rm_r ['README.txt', 'bin', 'solr.xml'].map{ |i| File.join(solr_root, 'solr', i) }, :verbose => true, :force => true |
31 | rm_r ['LICENSE.txt', 'NOTICE.txt', 'README.txt', 'etc', 'lib', 'start.jar', 'webapps', 'work'].map{ |i| File.join(solr_root, i) }, :verbose => true, :force => true | 34 | rm_r ['LICENSE.txt', 'NOTICE.txt', 'README.txt', 'etc', 'lib', 'start.jar', 'webapps', 'work'].map{ |i| File.join(solr_root, i) }, :verbose => true, :force => true |
32 | end | 35 | end |
@@ -36,8 +39,9 @@ namespace :solr do | @@ -36,8 +39,9 @@ namespace :solr do | ||
36 | end | 39 | end |
37 | 40 | ||
38 | desc 'Starts Solr. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.' | 41 | desc 'Starts Solr. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.' |
39 | - task :start => [:download, :environment] do | ||
40 | - require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment") | 42 | + task :start => [:download] do |
43 | + require File.expand_path(File.dirname(__FILE__) + '/../../config/solr_environment') | ||
44 | + | ||
41 | FileUtils.mkdir_p(SOLR_LOGS_PATH) | 45 | FileUtils.mkdir_p(SOLR_LOGS_PATH) |
42 | FileUtils.mkdir_p(SOLR_DATA_PATH) | 46 | FileUtils.mkdir_p(SOLR_DATA_PATH) |
43 | FileUtils.mkdir_p(SOLR_PIDS_PATH) | 47 | FileUtils.mkdir_p(SOLR_PIDS_PATH) |
@@ -73,8 +77,9 @@ namespace :solr do | @@ -73,8 +77,9 @@ namespace :solr do | ||
73 | end | 77 | end |
74 | 78 | ||
75 | desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.' | 79 | desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.' |
76 | - task :stop => :environment do | 80 | + task :stop do |
77 | require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment") | 81 | require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment") |
82 | + | ||
78 | if File.exists?(SOLR_PID_FILE) | 83 | if File.exists?(SOLR_PID_FILE) |
79 | killed = false | 84 | killed = false |
80 | File.open(SOLR_PID_FILE, "r") do |f| | 85 | File.open(SOLR_PID_FILE, "r") do |f| |
@@ -95,7 +100,7 @@ namespace :solr do | @@ -95,7 +100,7 @@ namespace :solr do | ||
95 | end | 100 | end |
96 | 101 | ||
97 | desc 'Restart Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.' | 102 | desc 'Restart Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.' |
98 | - task :restart => :environment do | 103 | + task :restart do |
99 | Rake::Task["solr:stop"].invoke | 104 | Rake::Task["solr:stop"].invoke |
100 | Rake::Task["solr:start"].invoke | 105 | Rake::Task["solr:start"].invoke |
101 | end | 106 | end |
@@ -129,7 +134,7 @@ namespace :solr do | @@ -129,7 +134,7 @@ namespace :solr do | ||
129 | 134 | ||
130 | logger = ActiveRecord::Base.logger = Logger.new(STDOUT) | 135 | logger = ActiveRecord::Base.logger = Logger.new(STDOUT) |
131 | logger.level = ActiveSupport::BufferedLogger::INFO unless debug_output | 136 | logger.level = ActiveSupport::BufferedLogger::INFO unless debug_output |
132 | - Dir["#{Rails.root}/app/models/*.rb"].each{ |file| require file } | 137 | + Dir["#{RAILS_ROOT}/app/models/*.rb"].each{ |file| require file } |
133 | 138 | ||
134 | if start_server | 139 | if start_server |
135 | puts "Starting Solr server..." | 140 | puts "Starting Solr server..." |
@@ -148,7 +153,7 @@ namespace :solr do | @@ -148,7 +153,7 @@ namespace :solr do | ||
148 | models.each do |model| | 153 | models.each do |model| |
149 | if clear_first | 154 | if clear_first |
150 | puts "Clearing index for #{model}..." | 155 | puts "Clearing index for #{model}..." |
151 | - ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:#{model}")) | 156 | + ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:\"#{model}\"")) |
152 | ActsAsSolr::Post.execute(Solr::Request::Commit.new) | 157 | ActsAsSolr::Post.execute(Solr::Request::Commit.new) |
153 | end | 158 | end |
154 | 159 |
vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml
@@ -31,24 +31,22 @@ | @@ -31,24 +31,22 @@ | ||
31 | 31 | ||
32 | <schema name="acts_as_solr" version="0.9"> | 32 | <schema name="acts_as_solr" version="0.9"> |
33 | <types> | 33 | <types> |
34 | - <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="false"/> | ||
35 | - <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" omitNorms="false"/> | ||
36 | - <fieldType name="integer" class="solr.IntField" omitNorms="false"/> | ||
37 | - <fieldType name="long" class="solr.LongField" omitNorms="false"/> | ||
38 | - <fieldType name="float" class="solr.FloatField" omitNorms="false"/> | ||
39 | - <fieldType name="double" class="solr.DoubleField" omitNorms="false"/> | ||
40 | - <fieldType name="sint" class="solr.SortableIntField" sortMissingLast="true" omitNorms="false"/> | ||
41 | - <fieldType name="slong" class="solr.SortableLongField" sortMissingLast="true" omitNorms="false"/> | ||
42 | - <fieldType name="sfloat" class="solr.SortableFloatField" sortMissingLast="true" omitNorms="false"/> | ||
43 | - <fieldType name="sdouble" class="solr.SortableDoubleField" sortMissingLast="true" omitNorms="false"/> | ||
44 | - <fieldType name="date" class="solr.TrieDateField" sortMissingLast="true" omitNorms="false"/> | ||
45 | - <fieldType name="text_ws" class="solr.TextField" positionIncrementGap="100"> | ||
46 | - <analyzer> | ||
47 | - <tokenizer class="solr.WhitespaceTokenizerFactory"/> | ||
48 | - </analyzer> | ||
49 | - </fieldType> | ||
50 | - | ||
51 | - <fieldType name="text" class="solr.TextField" autoGeneratePhraseQueries="false"> | 34 | + <fieldType name="id" class="solr.StrField" sortMissingLast="true" omitNorms="false"/> |
35 | + <fieldType name="facet" class="solr.StrField" sortMissingLast="true" omitNorms="false"/> | ||
36 | + <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="false"/> | ||
37 | + <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" omitNorms="false"/> | ||
38 | + <fieldType name="integer" class="solr.IntField" omitNorms="false"/> | ||
39 | + <fieldType name="float" class="solr.FloatField" omitNorms="false"/> | ||
40 | + <fieldType name="double" class="solr.DoubleField" omitNorms="false"/> | ||
41 | + <fieldType name="date" class="solr.TrieDateField" sortMissingLast="true" omitNorms="false"/> | ||
42 | + | ||
43 | + <!-- sortable versions --> | ||
44 | + <fieldType name="sstring" class="solr.StrField" sortMissingLast="true" omitNorms="false"/> | ||
45 | + <fieldType name="sinteger" class="solr.SortableIntField" sortMissingLast="true" omitNorms="false"/> | ||
46 | + <fieldType name="sfloat" class="solr.SortableFloatField" sortMissingLast="true" omitNorms="false"/> | ||
47 | + <fieldType name="sdouble" class="solr.SortableDoubleField" sortMissingLast="true" omitNorms="false"/> | ||
48 | + | ||
49 | + <fieldType name="text" class="solr.TextField" autoGeneratePhraseQueries="false"> | ||
52 | <analyzer type="index"> | 50 | <analyzer type="index"> |
53 | <tokenizer class="solr.StandardTokenizerFactory"/> | 51 | <tokenizer class="solr.StandardTokenizerFactory"/> |
54 | <filter class="solr.RemoveDuplicatesTokenFilterFactory"/> | 52 | <filter class="solr.RemoveDuplicatesTokenFilterFactory"/> |
@@ -62,6 +60,7 @@ | @@ -62,6 +60,7 @@ | ||
62 | --> | 60 | --> |
63 | <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.pt.txt" /> | 61 | <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.pt.txt" /> |
64 | <filter class="solr.PortugueseStemFilterFactory" /> | 62 | <filter class="solr.PortugueseStemFilterFactory" /> |
63 | + <filter class="solr.PorterStemFilterFactory" /> | ||
65 | <!-- too slow | 64 | <!-- too slow |
66 | <filter class="solr.HunspellStemFilterFactory" dictionary="en_US.dic" affix="en_US.aff" ignoreCase="true" /> | 65 | <filter class="solr.HunspellStemFilterFactory" dictionary="en_US.dic" affix="en_US.aff" ignoreCase="true" /> |
67 | <filter class="solr.HunspellStemFilterFactory" dictionary="pt_PT.dic" affix="pt_PT.aff" ignoreCase="true" /> | 66 | <filter class="solr.HunspellStemFilterFactory" dictionary="pt_PT.dic" affix="pt_PT.aff" ignoreCase="true" /> |
@@ -84,6 +83,7 @@ | @@ -84,6 +83,7 @@ | ||
84 | --> | 83 | --> |
85 | <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.pt.txt" /> | 84 | <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.pt.txt" /> |
86 | <filter class="solr.PortugueseStemFilterFactory" /> | 85 | <filter class="solr.PortugueseStemFilterFactory" /> |
86 | + <filter class="solr.PorterStemFilterFactory" /> | ||
87 | <!-- too slow | 87 | <!-- too slow |
88 | <filter class="solr.HunspellStemFilterFactory" dictionary="en_US.dic" affix="en_US.aff" ignoreCase="true" /> | 88 | <filter class="solr.HunspellStemFilterFactory" dictionary="en_US.dic" affix="en_US.aff" ignoreCase="true" /> |
89 | <filter class="solr.HunspellStemFilterFactory" dictionary="pt_PT.dic" affix="pt_PT.aff" ignoreCase="true" /> | 89 | <filter class="solr.HunspellStemFilterFactory" dictionary="pt_PT.dic" affix="pt_PT.aff" ignoreCase="true" /> |
@@ -94,19 +94,6 @@ | @@ -94,19 +94,6 @@ | ||
94 | --> | 94 | --> |
95 | </analyzer> | 95 | </analyzer> |
96 | </fieldType> | 96 | </fieldType> |
97 | - | ||
98 | - <fieldType name="alphaOnlySort" class="solr.TextField" sortMissingLast="true" omitNorms="false"> | ||
99 | - <analyzer> | ||
100 | - <tokenizer class="solr.KeywordTokenizerFactory"/> | ||
101 | - <filter class="solr.LowerCaseFilterFactory" /> | ||
102 | - <filter class="solr.TrimFilterFactory" /> | ||
103 | - <filter class="solr.PatternReplaceFilterFactory" pattern="([^a-z])" replacement="" replace="all"/> | ||
104 | - </analyzer> | ||
105 | - </fieldType> | ||
106 | - | ||
107 | - <fieldtype name="text_zh" class="solr.TextField"> | ||
108 | - <analyzer class="org.apache.lucene.analysis.cn.ChineseAnalyzer"/> | ||
109 | - </fieldtype> | ||
110 | 97 | ||
111 | <fieldType name="textSpell" class="solr.TextField" positionIncrementGap="100" > | 98 | <fieldType name="textSpell" class="solr.TextField" positionIncrementGap="100" > |
112 | <analyzer> | 99 | <analyzer> |
@@ -117,54 +104,74 @@ | @@ -117,54 +104,74 @@ | ||
117 | </analyzer> | 104 | </analyzer> |
118 | </fieldType> | 105 | </fieldType> |
119 | 106 | ||
120 | - <fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/> | 107 | + <fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/> |
121 | 108 | ||
109 | + <fieldtype name="text_zh" class="solr.TextField"> | ||
110 | + <analyzer class="org.apache.lucene.analysis.cn.ChineseAnalyzer"/> | ||
111 | + </fieldtype> | ||
122 | </types> | 112 | </types> |
123 | 113 | ||
124 | 114 | ||
125 | <fields> | 115 | <fields> |
126 | - <field name="latlng" type="location" indexed="true" stored="true" /> | ||
127 | - <field name="latlng_0_coordinate" type="sdouble" indexed="true" stored="true" multiValued="false"/> | ||
128 | - <field name="latlng_1_coordinate" type="sdouble" indexed="true" stored="true" multiValued="false"/> | ||
129 | - | ||
130 | - <field name="id" type="string" indexed="true" stored="true" required="true" /> | ||
131 | - <field name="pk_i" type="integer" indexed="true" stored="true"/> | ||
132 | - <field name="pk_s" type="string" indexed="true" stored="true"/> | ||
133 | - <field name="text" type="text" indexed="true" stored="false" multiValued="true"/> | ||
134 | - <field name="spell" type="textSpell" indexed="true" stored="true" multiValued="true"/> | ||
135 | - | ||
136 | - <dynamicField name="*_i" type="integer" indexed="true" stored="false" multiValued="true"/> | ||
137 | - <dynamicField name="*_t" type="text" indexed="true" stored="true" multiValued="true"/> | ||
138 | - <dynamicField name="*_f" type="float" indexed="true" stored="false" multiValued="false"/> | ||
139 | - <dynamicField name="*_do" type="double" indexed="true" stored="false" multiValued="false"/> | ||
140 | - <dynamicField name="*_b" type="boolean" indexed="true" stored="false" multiValued="true"/> | ||
141 | - <dynamicField name="*_d" type="date" indexed="true" stored="false" multiValued="false"/> | ||
142 | - <dynamicField name="*_s" type="string" indexed="true" stored="true" multiValued="false"/> | ||
143 | - <dynamicField name="*_ri" type="sint" indexed="true" stored="false" multiValued="true"/> | ||
144 | - <dynamicField name="*_rf" type="sfloat" indexed="true" stored="false" multiValued="true"/> | ||
145 | - <dynamicField name="*_facet" type="string" indexed="true" stored="false" multiValued="true"/> | ||
146 | - <dynamicField name="*_s_mv" type="string" indexed="true" stored="false" multiValued="true"/> | ||
147 | - <dynamicField name="*_zh_text" type="text_zh" indexed="true" stored="false" multiValued="true"/> | ||
148 | - <dynamicField name="*_display" type="text" indexed="false" stored="true" multiValued="true"/> | ||
149 | - | ||
150 | - <field name="lat" type="sdouble" indexed="true" stored="true"/><!-- must match the latField in solrconfig.xml --> | ||
151 | - <field name="lng" type="sdouble" indexed="true" stored="true"/><!-- must match the lngField in solrconfig.xml --> | ||
152 | - <field name="geo_distance" type="sdouble"/> <!-- Optional but used for distributed searching --> | ||
153 | - <dynamicField name="_local*" type="sdouble" indexed="true" stored="true"/><!-- used internally by localsolr --> | 116 | + <field name="latlng" type="location" indexed="true" stored="true" /> |
117 | + <field name="latlng_0_coordinate" type="sdouble" indexed="true" stored="true" multiValued="false"/> | ||
118 | + <field name="latlng_1_coordinate" type="sdouble" indexed="true" stored="true" multiValued="false"/> | ||
119 | + | ||
120 | + <field name="id" type="id" indexed="true" stored="true" multiValued="true" required="true"/> | ||
121 | + <field name="_id_s" type="id" indexed="true" stored="true" multiValued="true"/> | ||
122 | + <field name="pk_i" type="integer" indexed="true" stored="true" multiValued="true"/> | ||
123 | + <field name="pk_s" type="id" indexed="true" stored="true" multiValued="true"/> | ||
124 | + <field name="type_s" type="string" indexed="true" stored="true" multiValued="true" required="true"/> | ||
125 | + | ||
126 | + <!-- sortable versions --> | ||
127 | + <dynamicField name="*sortable_s" type="sstring" indexed="true" stored="false" multiValued="false"/> | ||
128 | + <dynamicField name="*sortable_i" type="sinteger" indexed="true" stored="false" multiValued="false"/> | ||
129 | + <dynamicField name="*sortable_f" type="sfloat" indexed="true" stored="false" multiValued="false"/> | ||
130 | + <dynamicField name="*sortable_do" type="sdouble" indexed="true" stored="false" multiValued="false"/> | ||
131 | + | ||
132 | + <dynamicField name="*_t" type="text" indexed="true" stored="true" multiValued="true"/> | ||
133 | + <dynamicField name="*_s" type="text" indexed="true" stored="true" multiValued="false"/> | ||
134 | + <dynamicField name="*_i" type="integer" indexed="true" stored="false" multiValued="true"/> | ||
135 | + <dynamicField name="*_f" type="float" indexed="true" stored="true" multiValued="false"/> | ||
136 | + <dynamicField name="*_do" type="double" indexed="true" stored="false" multiValued="false"/> | ||
137 | + <dynamicField name="*_b" type="boolean" indexed="true" stored="false" multiValued="true"/> | ||
138 | + <dynamicField name="*_d" type="date" indexed="true" stored="false" multiValued="false"/> | ||
139 | + <dynamicField name="*_ri" type="sinteger" indexed="true" stored="false" multiValued="false"/> | ||
140 | + <dynamicField name="*_rf" type="sfloat" indexed="true" stored="false" multiValued="false"/> | ||
141 | + <dynamicField name="*_facet" type="facet" indexed="true" stored="false" multiValued="true"/> | ||
142 | + | ||
143 | + <field name="lat" type="sdouble" indexed="true" stored="true"/> | ||
144 | + <field name="lng" type="sdouble" indexed="true" stored="true"/> | ||
145 | + <dynamicField name="_local*" type="sdouble" indexed="true" stored="true"/> <!-- used internally by localsolr --> | ||
146 | + <field name="geo_distance" type="sdouble"/> <!-- Optional but used for distributed searching --> | ||
147 | + | ||
148 | + <field name="text" type="text" indexed="true" stored="false" multiValued="true"/> | ||
149 | + <field name="spell" type="textSpell" indexed="true" stored="true" multiValued="true"/> | ||
150 | + | ||
151 | + <dynamicField name="*_s_mv" type="string" indexed="true" stored="false" multiValued="true"/> | ||
152 | + <dynamicField name="*_zh_text" type="text_zh" indexed="true" stored="false" multiValued="true"/> | ||
153 | + <dynamicField name="*_display" type="text" indexed="false" stored="true" multiValued="true"/> | ||
154 | + | ||
154 | </fields> | 155 | </fields> |
155 | 156 | ||
156 | <uniqueKey>id</uniqueKey> | 157 | <uniqueKey>id</uniqueKey> |
158 | + | ||
157 | <defaultSearchField>text</defaultSearchField> | 159 | <defaultSearchField>text</defaultSearchField> |
160 | + <copyField source="*_s" dest="text"/> | ||
161 | + <copyField source="*_t" dest="text"/> | ||
162 | + <copyField source="*_i" dest="text"/> | ||
163 | + <copyField source="*_f" dest="text"/> | ||
164 | + <copyField source="*_d" dest="text"/> | ||
165 | + <copyField source="*_do" dest="text"/> | ||
166 | + <copyField source="*_facet" dest="text"/> | ||
167 | + | ||
168 | + <copyField source="*_s" dest="spell"/> | ||
169 | + <copyField source="*_t" dest="spell"/> | ||
170 | + <copyField source="*_facet" dest="spell"/> | ||
158 | 171 | ||
159 | <copyField source="lat_f" dest="latlng_0_coordinate"/> | 172 | <copyField source="lat_f" dest="latlng_0_coordinate"/> |
160 | <copyField source="lng_f" dest="latlng_1_coordinate"/> | 173 | <copyField source="lng_f" dest="latlng_1_coordinate"/> |
161 | 174 | ||
162 | - <copyField source="*_s" dest="text"/> | ||
163 | - <copyField source="*_s" dest="spell"/> | ||
164 | - <copyField source="*_t" dest="text"/> | ||
165 | - <copyField source="*_t" dest="spell"/> | ||
166 | - <copyField source="*_facet" dest="text"/> | ||
167 | - <copyField source="*_facet" dest="spell"/> | ||
168 | <solrQueryParser defaultOperator="AND"/> | 175 | <solrQueryParser defaultOperator="AND"/> |
169 | 176 | ||
170 | </schema> | 177 | </schema> |
vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/solrconfig.xml
@@ -776,7 +776,11 @@ | @@ -776,7 +776,11 @@ | ||
776 | <str>nameOfCustomComponent2</str> | 776 | <str>nameOfCustomComponent2</str> |
777 | </arr> | 777 | </arr> |
778 | --> | 778 | --> |
779 | - </requestHandler> | 779 | + <arr name="last-components"> |
780 | + <str>spellcheck</str> | ||
781 | + </arr> | ||
782 | + | ||
783 | + </requestHandler> | ||
780 | 784 | ||
781 | <!-- DisMaxRequestHandler allows easy searching across multiple fields | 785 | <!-- DisMaxRequestHandler allows easy searching across multiple fields |
782 | for simple user-entered phrases. It's implementation is now | 786 | for simple user-entered phrases. It's implementation is now |
@@ -1099,24 +1103,22 @@ | @@ -1099,24 +1103,22 @@ | ||
1099 | --> | 1103 | --> |
1100 | <lst name="spellchecker"> | 1104 | <lst name="spellchecker"> |
1101 | <str name="name">default</str> | 1105 | <str name="name">default</str> |
1102 | - <str name="field">name</str> | 1106 | + <str name="field">spell</str> |
1103 | <str name="spellcheckIndexDir">spellchecker</str> | 1107 | <str name="spellcheckIndexDir">spellchecker</str> |
1108 | + <str name="buildOnCommit">true</str> | ||
1109 | + <str name="buildOnOptimize">true</str> | ||
1104 | <!-- uncomment this to require terms to occur in 1% of the documents in order to be included in the dictionary | 1110 | <!-- uncomment this to require terms to occur in 1% of the documents in order to be included in the dictionary |
1105 | <float name="thresholdTokenFrequency">.01</float> | 1111 | <float name="thresholdTokenFrequency">.01</float> |
1106 | --> | 1112 | --> |
1107 | </lst> | 1113 | </lst> |
1108 | 1114 | ||
1109 | <!-- a spellchecker that uses a different distance measure --> | 1115 | <!-- a spellchecker that uses a different distance measure --> |
1110 | - <!-- | ||
1111 | - <lst name="spellchecker"> | ||
1112 | - <str name="name">jarowinkler</str> | ||
1113 | - <str name="field">spell</str> | ||
1114 | - <str name="distanceMeasure"> | ||
1115 | - org.apache.lucene.search.spell.JaroWinklerDistance | ||
1116 | - </str> | ||
1117 | - <str name="spellcheckIndexDir">spellcheckerJaro</str> | ||
1118 | - </lst> | ||
1119 | - --> | 1116 | + <lst name="spellchecker"> |
1117 | + <str name="name">jarowinkler</str> | ||
1118 | + <str name="field">spell</str> | ||
1119 | + <str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str> | ||
1120 | + <str name="spellcheckIndexDir">spellcheckerJaro</str> | ||
1121 | + </lst> | ||
1120 | 1122 | ||
1121 | <!-- a spellchecker that use an alternate comparator | 1123 | <!-- a spellchecker that use an alternate comparator |
1122 | 1124 | ||
@@ -1135,15 +1137,13 @@ | @@ -1135,15 +1137,13 @@ | ||
1135 | --> | 1137 | --> |
1136 | 1138 | ||
1137 | <!-- A spellchecker that reads the list of words from a file --> | 1139 | <!-- A spellchecker that reads the list of words from a file --> |
1138 | - <!-- | ||
1139 | - <lst name="spellchecker"> | ||
1140 | - <str name="classname">solr.FileBasedSpellChecker</str> | ||
1141 | - <str name="name">file</str> | ||
1142 | - <str name="sourceLocation">spellings.txt</str> | ||
1143 | - <str name="characterEncoding">UTF-8</str> | ||
1144 | - <str name="spellcheckIndexDir">spellcheckerFile</str> | ||
1145 | - </lst> | ||
1146 | - --> | 1140 | + <lst name="spellchecker"> |
1141 | + <str name="classname">solr.FileBasedSpellChecker</str> | ||
1142 | + <str name="name">file</str> | ||
1143 | + <str name="sourceLocation">spellings.en.txt</str> | ||
1144 | + <str name="characterEncoding">UTF-8</str> | ||
1145 | + <str name="spellcheckIndexDir">spellcheckerFile</str> | ||
1146 | + </lst> | ||
1147 | </searchComponent> | 1147 | </searchComponent> |
1148 | 1148 | ||
1149 | <!-- A request handler for demonstrating the spellcheck component. | 1149 | <!-- A request handler for demonstrating the spellcheck component. |
@@ -1444,6 +1444,7 @@ | @@ -1444,6 +1444,7 @@ | ||
1444 | <str name="hl.bs.country">US</str> | 1444 | <str name="hl.bs.country">US</str> |
1445 | </lst> | 1445 | </lst> |
1446 | </boundaryScanner> | 1446 | </boundaryScanner> |
1447 | + | ||
1447 | </highlighting> | 1448 | </highlighting> |
1448 | </searchComponent> | 1449 | </searchComponent> |
1449 | 1450 |
vendor/plugins/acts_as_solr_reloaded/test/config/solr.yml
vendor/plugins/acts_as_solr_reloaded/test/functional/acts_as_solr_test.rb
@@ -5,16 +5,10 @@ class ActsAsSolrTest < Test::Unit::TestCase | @@ -5,16 +5,10 @@ class ActsAsSolrTest < Test::Unit::TestCase | ||
5 | 5 | ||
6 | fixtures :books, :movies, :electronics, :postings, :authors, :advertises | 6 | fixtures :books, :movies, :electronics, :postings, :authors, :advertises |
7 | 7 | ||
8 | + MongoMapper.connection = Mongo::Connection.new("127.0.0.1", 27017, :slave_ok => true, :pool_size => 16, :timeout => 10) | ||
9 | + MongoMapper.database = "#mydb_test" | ||
8 | Document.destroy_all | 10 | Document.destroy_all |
9 | 11 | ||
10 | - DynamicAttribute.delete_all | ||
11 | - Advertise.first.dynamic_attributes.create! :name => 'Description', :value => 'A very cool bike' | ||
12 | - Advertise.first.dynamic_attributes.create! :name => 'Price', :value => '1000' | ||
13 | - | ||
14 | - Local.delete_all | ||
15 | - Local.create! :localizable => Advertise.find(1), :longitude => '-77.4027', :latitude => '39.36' | ||
16 | - Local.create! :localizable => Advertise.find(2), :longitude => '77.4027', :latitude => '-38.36' | ||
17 | - | ||
18 | # Inserting new data into Solr and making sure it's getting indexed | 12 | # Inserting new data into Solr and making sure it's getting indexed |
19 | def test_insert_new_data | 13 | def test_insert_new_data |
20 | assert_equal 2, Book.count_by_solr('ruby OR splinter OR bob') | 14 | assert_equal 2, Book.count_by_solr('ruby OR splinter OR bob') |
@@ -102,16 +96,30 @@ class ActsAsSolrTest < Test::Unit::TestCase | @@ -102,16 +96,30 @@ class ActsAsSolrTest < Test::Unit::TestCase | ||
102 | # The method current_time above gets indexed as being part of the | 96 | # The method current_time above gets indexed as being part of the |
103 | # Movie model and it's available for search as well | 97 | # Movie model and it's available for search as well |
104 | def test_find_with_dynamic_fields | 98 | def test_find_with_dynamic_fields |
99 | + DynamicAttribute.delete_all | ||
100 | + Movie.first.dynamic_attributes.create! :name => 'description', :value => 'A very cool bike' | ||
101 | + Movie.first.solr_save | ||
102 | + | ||
105 | date = Time.now.strftime('%b %d %Y') | 103 | date = Time.now.strftime('%b %d %Y') |
106 | - ["dynamite AND #{date}", "description:goofy AND #{date}", "goofy napoleon #{date}", | ||
107 | - "goofiness #{date}"].each do |term| | ||
108 | - records = Movie.find_by_solr term | 104 | + ["dynamite AND #{date}", "description_t:bike AND #{date}", "goofy napoleon #{date}", "goofy #{date}"].each do |term| |
105 | + records = Movie.find_by_solr '', :alternate_query => term | ||
109 | assert_equal 1, records.total | 106 | assert_equal 1, records.total |
110 | assert_equal ({"id" => 1, "name" => "Napoleon Dynamite", | 107 | assert_equal ({"id" => 1, "name" => "Napoleon Dynamite", |
111 | "description" => "Cool movie about a goofy guy"}), records.docs.first.attributes | 108 | "description" => "Cool movie about a goofy guy"}), records.docs.first.attributes |
112 | end | 109 | end |
113 | end | 110 | end |
114 | 111 | ||
112 | + def test_dynamic_attributes_are_faceted | ||
113 | + DynamicAttribute.delete_all | ||
114 | + Movie.first.dynamic_attributes.create! :name => 'description', :value => 'A very cool bike' | ||
115 | + Movie.first.solr_save | ||
116 | + | ||
117 | + records = Movie.find_by_solr '', :alternate_query => "description_t:bike", :facets => { :fields => [:description] } | ||
118 | + expected = { "A very cool bike" => 1 } | ||
119 | + assert_equal expected, Hash[records.facets['facet_fields']['description_facet']] | ||
120 | + end | ||
121 | + | ||
122 | + | ||
115 | # Testing basic solr search that returns just the ids instead of the objects: | 123 | # Testing basic solr search that returns just the ids instead of the objects: |
116 | # Model.find_id_by_solr 'term' | 124 | # Model.find_id_by_solr 'term' |
117 | # Note that you're able to mix free-search with fields and boolean operators | 125 | # Note that you're able to mix free-search with fields and boolean operators |
@@ -140,11 +148,10 @@ class ActsAsSolrTest < Test::Unit::TestCase | @@ -140,11 +148,10 @@ class ActsAsSolrTest < Test::Unit::TestCase | ||
140 | # Model.find_id_by_solr 'term' | 148 | # Model.find_id_by_solr 'term' |
141 | # Note that you're able to mix free-search with fields and boolean operators | 149 | # Note that you're able to mix free-search with fields and boolean operators |
142 | def test_find_id_by_solr_ruby_or_splinter | 150 | def test_find_id_by_solr_ruby_or_splinter |
143 | - ['ruby OR splinter', 'ruby OR author:tom', 'name:cell OR author:peter', | ||
144 | - 'dummy OR cell'].each do |term| | 151 | + ['ruby OR splinter', 'ruby OR author:tom', 'name:cell OR author:peter', 'dummy OR cell'].each do |term| |
145 | records = Book.find_id_by_solr term | 152 | records = Book.find_id_by_solr term |
146 | assert_equal 2, records.docs.size | 153 | assert_equal 2, records.docs.size |
147 | - assert_equal ['1','2'], records.docs | 154 | + assert_equivalent ['1','2'], records.docs |
148 | end | 155 | end |
149 | end | 156 | end |
150 | 157 | ||
@@ -152,8 +159,7 @@ class ActsAsSolrTest < Test::Unit::TestCase | @@ -152,8 +159,7 @@ class ActsAsSolrTest < Test::Unit::TestCase | ||
152 | # Model.find_count_by_solr 'term' | 159 | # Model.find_count_by_solr 'term' |
153 | # Note that you're able to mix free-search with fields and boolean operators | 160 | # Note that you're able to mix free-search with fields and boolean operators |
154 | def test_count_by_solr | 161 | def test_count_by_solr |
155 | - ['ruby', 'dummy', 'name:ruby', 'name:dummy', 'name:ruby AND author:peter', | ||
156 | - 'author:peter AND ruby'].each do |term| | 162 | + ['ruby', 'dummy', 'name:ruby', 'name:dummy', 'name:ruby AND author:peter', 'author:peter AND ruby'].each do |term| |
157 | assert_equal 1, Book.count_by_solr(term), "there should only be 1 result for search: #{term}" | 163 | assert_equal 1, Book.count_by_solr(term), "there should only be 1 result for search: #{term}" |
158 | end | 164 | end |
159 | end | 165 | end |
@@ -221,13 +227,13 @@ class ActsAsSolrTest < Test::Unit::TestCase | @@ -221,13 +227,13 @@ class ActsAsSolrTest < Test::Unit::TestCase | ||
221 | assert_equal 'Splinter Cell', records.docs.last.name | 227 | assert_equal 'Splinter Cell', records.docs.last.name |
222 | end | 228 | end |
223 | 229 | ||
224 | - # Testing solr search with optional :order argument | ||
225 | - def _test_with_order_option | ||
226 | - records = Movie.find_by_solr 'office^5 OR goofiness' | 230 | + # Testing solr search with optional :sort argument |
231 | + def test_with_order_option | ||
232 | + records = Movie.find_by_solr 'office^5 OR goofy' | ||
227 | assert_equal 'Hypnotized dude loves fishing but not working', records.docs.first.description | 233 | assert_equal 'Hypnotized dude loves fishing but not working', records.docs.first.description |
228 | assert_equal 'Cool movie about a goofy guy', records.docs.last.description | 234 | assert_equal 'Cool movie about a goofy guy', records.docs.last.description |
229 | 235 | ||
230 | - records = Movie.find_by_solr 'office^5 OR goofiness', :order => 'description asc' | 236 | + records = Movie.find_by_solr 'office^5 OR goofy', :sort => 'description asc' |
231 | assert_equal 'Cool movie about a goofy guy', records.docs.first.description | 237 | assert_equal 'Cool movie about a goofy guy', records.docs.first.description |
232 | assert_equal 'Hypnotized dude loves fishing but not working', records.docs.last.description | 238 | assert_equal 'Hypnotized dude loves fishing but not working', records.docs.last.description |
233 | end | 239 | end |
@@ -235,13 +241,13 @@ class ActsAsSolrTest < Test::Unit::TestCase | @@ -235,13 +241,13 @@ class ActsAsSolrTest < Test::Unit::TestCase | ||
235 | # Testing search with omitted :field_types should | 241 | # Testing search with omitted :field_types should |
236 | # return the same result set as if when we use it | 242 | # return the same result set as if when we use it |
237 | def test_omit_field_types_in_search | 243 | def test_omit_field_types_in_search |
238 | - records = Electronic.find_by_solr "price:[200 TO 599.99]" | ||
239 | - assert_match(/599/, records.docs.first.price) | ||
240 | - assert_match(/319/, records.docs.last.price) | 244 | + records = Electronic.find_by_solr '', :filter_queries => ["price:[200 TO 599.99]"] |
245 | + assert_match /599/, records.docs.last.price | ||
246 | + assert_match /319/, records.docs.first.price | ||
241 | 247 | ||
242 | - records = Electronic.find_by_solr "price:[200 TO 599.99]", :order => 'price asc' | ||
243 | - assert_match(/319/, records.docs.first.price) | ||
244 | - assert_match(/599/, records.docs.last.price) | 248 | + records = Electronic.find_by_solr '', :filter_queries => ["price:[200 TO 599.99]"], :sort => 'price asc' |
249 | + assert_match /319/, records.docs.first.price | ||
250 | + assert_match /599/, records.docs.last.price | ||
245 | 251 | ||
246 | end | 252 | end |
247 | 253 | ||
@@ -289,6 +295,12 @@ class ActsAsSolrTest < Test::Unit::TestCase | @@ -289,6 +295,12 @@ class ActsAsSolrTest < Test::Unit::TestCase | ||
289 | assert_equal 0, Author.count_by_solr('raymond chandler') | 295 | assert_equal 0, Author.count_by_solr('raymond chandler') |
290 | end | 296 | end |
291 | 297 | ||
298 | + def test_basic_search_on_model_with_string_id_field | ||
299 | + records = Posting.find_by_solr 'first' | ||
300 | + assert_equal 1, records.total | ||
301 | + assert_equal 'ABC-123', records.docs.first.guid | ||
302 | + end | ||
303 | + | ||
292 | # Testing models that use a different key as the primary key | 304 | # Testing models that use a different key as the primary key |
293 | def test_search_on_model_with_string_id_field | 305 | def test_search_on_model_with_string_id_field |
294 | records = Posting.find_by_solr 'first^5 OR second' | 306 | records = Posting.find_by_solr 'first^5 OR second' |
@@ -379,13 +391,11 @@ class ActsAsSolrTest < Test::Unit::TestCase | @@ -379,13 +391,11 @@ class ActsAsSolrTest < Test::Unit::TestCase | ||
379 | end | 391 | end |
380 | 392 | ||
381 | def test_operator_search_option | 393 | def test_operator_search_option |
382 | - assert_nothing_raised { | ||
383 | - books = Movie.find_by_solr "office napoleon", :operator => :or | ||
384 | - assert_equal 2, books.total | 394 | + books = Movie.find_by_solr "office napoleon", :operator => :or |
395 | + assert_equal 2, books.total | ||
385 | 396 | ||
386 | - books = Movie.find_by_solr "office napoleon", :operator => :and | ||
387 | - assert_equal 0, books.total | ||
388 | - } | 397 | + books = Movie.find_by_solr "office napoleon", :operator => :and |
398 | + assert_equal 0, books.total | ||
389 | 399 | ||
390 | assert_raise RuntimeError do | 400 | assert_raise RuntimeError do |
391 | Movie.find_by_solr "office napoleon", :operator => :bad | 401 | Movie.find_by_solr "office napoleon", :operator => :bad |
@@ -395,18 +405,17 @@ class ActsAsSolrTest < Test::Unit::TestCase | @@ -395,18 +405,17 @@ class ActsAsSolrTest < Test::Unit::TestCase | ||
395 | # Making sure find_by_solr with scores actually return the scores | 405 | # Making sure find_by_solr with scores actually return the scores |
396 | # for each individual record and orders them accordingly | 406 | # for each individual record and orders them accordingly |
397 | def test_find_by_solr_order_by_score | 407 | def test_find_by_solr_order_by_score |
398 | - books = Book.find_by_solr 'ruby^10 OR splinter', {:scores => true, :order => 'score asc' } | 408 | + books = Book.find_by_solr 'ruby^10 OR splinter', :scores => true, :sort => 'score asc' |
399 | assert (books.docs.collect(&:solr_score).compact.size == books.docs.size), "Each book should have a score" | 409 | assert (books.docs.collect(&:solr_score).compact.size == books.docs.size), "Each book should have a score" |
400 | - assert (books.docs.last.solr_score >= 0.3 && books.docs.last.solr_score <= 0.6) | 410 | + assert (books.docs.first.solr_score < books.docs.last.solr_score) |
401 | 411 | ||
402 | - books = Book.find_by_solr 'ruby^10 OR splinter', {:scores => true, :order => 'score desc' } | ||
403 | - assert (books.docs.first.solr_score >= 0.3 && books.docs.first.solr_score <= 0.6) | 412 | + books = Book.find_by_solr 'ruby^10 OR splinter', :scores => true, :sort => 'score desc' |
404 | assert (books.docs.last.solr_score < books.docs.first.solr_score) | 413 | assert (books.docs.last.solr_score < books.docs.first.solr_score) |
405 | end | 414 | end |
406 | 415 | ||
407 | # Search based on fields with the :date format | 416 | # Search based on fields with the :date format |
408 | def test_indexed_date_field_format | 417 | def test_indexed_date_field_format |
409 | - movies = Movie.find_by_solr 'time_on_xml:[NOW-1DAY TO NOW]' | 418 | + movies = Movie.find_by_solr '', :filter_queries => 'time_on_xml:[NOW-1DAY TO NOW]' |
410 | assert_equal 2, movies.total | 419 | assert_equal 2, movies.total |
411 | end | 420 | end |
412 | 421 | ||
@@ -422,38 +431,26 @@ class ActsAsSolrTest < Test::Unit::TestCase | @@ -422,38 +431,26 @@ class ActsAsSolrTest < Test::Unit::TestCase | ||
422 | assert_equal 0, Gadget.find_id_by_solr('flipvideo').total | 431 | assert_equal 0, Gadget.find_id_by_solr('flipvideo').total |
423 | end | 432 | end |
424 | 433 | ||
425 | - def test_should_find_filtering_a_dynamic_attribute | ||
426 | - records = Advertise.find_by_solr "description:bike" | ||
427 | - assert_equal 1, records.total | ||
428 | - end | ||
429 | - | ||
430 | - def test_dynamic_attributes_are_faceted | ||
431 | - records = Advertise.find_by_solr "Description:bike", :facets => { :fields => [:Description] } | ||
432 | - expected = { "A very cool bike" => 1 } | ||
433 | - assert_equal expected, records.facets['facet_fields']['Description_facet'] | ||
434 | - end | ||
435 | - | ||
436 | def test_search_is_an_alias_for_find_by_solr | 434 | def test_search_is_an_alias_for_find_by_solr |
437 | assert_equal Advertise.find_by_solr("bike").docs, Advertise.search("bike").docs | 435 | assert_equal Advertise.find_by_solr("bike").docs, Advertise.search("bike").docs |
438 | end | 436 | end |
439 | 437 | ||
440 | def test_search_given_a_radius | 438 | def test_search_given_a_radius |
439 | + Local.delete_all | ||
440 | + Local.create! :localizable => Advertise.find(1), :longitude => '-77.4027', :latitude => '39.36' | ||
441 | + Local.create! :localizable => Advertise.find(2), :longitude => '77.4027', :latitude => '-38.36' | ||
442 | + Advertise.find(1).solr_save | ||
443 | + Advertise.find(2).solr_save | ||
444 | + | ||
441 | records = Advertise.search "bike", :latitude => '-39.36', :longitude => '77.4027', :radius => 1 | 445 | records = Advertise.search "bike", :latitude => '-39.36', :longitude => '77.4027', :radius => 1 |
442 | assert_equal 0, records.total | 446 | assert_equal 0, records.total |
443 | - end | ||
444 | - | ||
445 | - def test_records_are_found_in_a_radius | ||
446 | - records = Advertise.search "bike", :latitude => '39.36', :longitude => '-77.4027', :radius => 1 | ||
447 | - assert_equal 1, records.total | ||
448 | - end | ||
449 | 447 | ||
450 | - def test_records_are_found_with_highlight | ||
451 | - records = Book.find_by_solr "ruby", :highlight => { :fields => "name" } | 448 | + records = Advertise.search "car", :latitude => '39.36', :longitude => '-77.4027', :radius => 1 |
452 | assert_equal 1, records.total | 449 | assert_equal 1, records.total |
453 | end | 450 | end |
454 | 451 | ||
455 | - def test_records_wiht_highlights_are_returned_properly | ||
456 | - records = Book.find_by_solr "ruby", :highlight => { :fields => "name" } | 452 | + def test_records_with_highlights_are_returned_properly |
453 | + records = Book.find_by_solr "Ruby", :highlight => { :fields => "name" } | ||
457 | expected = {"name"=>["<em>Ruby</em> for Dummies"]} | 454 | expected = {"name"=>["<em>Ruby</em> for Dummies"]} |
458 | assert_equal expected, records.highlights.values.first | 455 | assert_equal expected, records.highlights.values.first |
459 | end | 456 | end |
@@ -464,23 +461,25 @@ class ActsAsSolrTest < Test::Unit::TestCase | @@ -464,23 +461,25 @@ class ActsAsSolrTest < Test::Unit::TestCase | ||
464 | 461 | ||
465 | def test_mongo_mappers_documents_are_found | 462 | def test_mongo_mappers_documents_are_found |
466 | Document.new(:name => "mapper").save | 463 | Document.new(:name => "mapper").save |
467 | - assert_equal "mapper", Document.search("mapper").docs.first.name | 464 | + records = Document.search("mapper").docs |
465 | + assert_equal 1, records.count | ||
466 | + assert_equal "mapper", records.first.name | ||
468 | end | 467 | end |
469 | 468 | ||
470 | def test_total_pages_is_returned_when_limit_specified | 469 | def test_total_pages_is_returned_when_limit_specified |
471 | - assert_equal 2, Posting.search("test", :limit => 1).total_pages | 470 | + assert_equal 2, Posting.search("testing", :limit => 1).total_pages |
472 | end | 471 | end |
473 | 472 | ||
474 | def test_total_pages_is_returned_when_limit_not_specified | 473 | def test_total_pages_is_returned_when_limit_not_specified |
475 | - assert_equal 1, Posting.search("test").total_pages | 474 | + assert_equal 1, Posting.search("testing").total_pages |
476 | end | 475 | end |
477 | 476 | ||
478 | def test_current_page_is_returned | 477 | def test_current_page_is_returned |
479 | - assert_equal 2, Posting.search("test", :limit => 1, :offset => 1).current_page | 478 | + assert_equal 2, Posting.search("testing", :limit => 1, :offset => 1).current_page |
480 | end | 479 | end |
481 | 480 | ||
482 | def test_current_page_1_is_returned | 481 | def test_current_page_1_is_returned |
483 | - assert_equal 1, Posting.search("test").current_page | 482 | + assert_equal 1, Posting.search("testing").current_page |
484 | end | 483 | end |
485 | 484 | ||
486 | def test_current_page_1_is_returned_when_no_records_found | 485 | def test_current_page_1_is_returned_when_no_records_found |
@@ -488,10 +487,10 @@ class ActsAsSolrTest < Test::Unit::TestCase | @@ -488,10 +487,10 @@ class ActsAsSolrTest < Test::Unit::TestCase | ||
488 | end | 487 | end |
489 | 488 | ||
490 | def test_page_parameter_is_accepted | 489 | def test_page_parameter_is_accepted |
491 | - assert_equal 2, Posting.search("test", :limit => 1, :page => 2).current_page | 490 | + assert_equal 2, Posting.search("testing", :limit => 1, :page => 2).current_page |
492 | end | 491 | end |
493 | 492 | ||
494 | def test_per_page_parameter_is_accepted | 493 | def test_per_page_parameter_is_accepted |
495 | - assert_equal 1, Posting.search("test", :per_page => 1).per_page | 494 | + assert_equal 1, Posting.search("testing", :per_page => 1).per_page |
496 | end | 495 | end |
497 | end | 496 | end |
vendor/plugins/acts_as_solr_reloaded/test/functional/faceted_search_test.rb
@@ -14,11 +14,10 @@ class FacetedSearchTest < Test::Unit::TestCase | @@ -14,11 +14,10 @@ class FacetedSearchTest < Test::Unit::TestCase | ||
14 | # A basic faceted search using just one facet field | 14 | # A basic faceted search using just one facet field |
15 | def test_faceted_search_basic | 15 | def test_faceted_search_basic |
16 | records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]} | 16 | records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]} |
17 | + ipod_video = Electronic.find 1 | ||
17 | assert_equal 4, records.docs.size | 18 | assert_equal 4, records.docs.size |
18 | - assert_match /Apple 60 GB Memory iPod/, records.docs.first.name | ||
19 | - assert_equal({"category_facet" => {"Electronics" => 1, | ||
20 | - "Memory" => 2, | ||
21 | - "Hard Drive" => 1}}, | 19 | + assert records.docs.include?(ipod_video) |
20 | + assert_equal({"category_facet" => [["Electronics", 1], ["Hard Drive", 1], ["Memory", 2]]}, | ||
22 | records.facets['facet_fields']) | 21 | records.facets['facet_fields']) |
23 | end | 22 | end |
24 | 23 | ||
@@ -33,14 +32,12 @@ class FacetedSearchTest < Test::Unit::TestCase | @@ -33,14 +32,12 @@ class FacetedSearchTest < Test::Unit::TestCase | ||
33 | def test_faceted_search_multiple_fields | 32 | def test_faceted_search_multiple_fields |
34 | records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category, :manufacturer]} | 33 | records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category, :manufacturer]} |
35 | assert_equal 4, records.docs.size | 34 | assert_equal 4, records.docs.size |
36 | - assert_equal({"category_facet" => {"Electronics" => 1, | ||
37 | - "Memory" => 2, | ||
38 | - "Hard Drive" => 1}, | ||
39 | - "manufacturer_facet" => {"Dell, Inc" => 0, | ||
40 | - "Samsung Electronics Co. Ltd." => 1, | ||
41 | - "Corsair Microsystems Inc." => 1, | ||
42 | - "A-DATA Technology Inc." => 1, | ||
43 | - "Apple Computer Inc." => 1}}, records.facets['facet_fields']) | 35 | + assert_equal({"category_facet" => [["Electronics", 1], ["Hard Drive", 1], ["Memory", 2]], |
36 | + "manufacturer_facet" => [["A-DATA Technology Inc.", 1], | ||
37 | + ["Apple Computer Inc.", 1], | ||
38 | + ["Corsair Microsystems Inc.", 1], | ||
39 | + ["Dell, Inc", 0], | ||
40 | + ["Samsung Electronics Co. Ltd.", 1]]}, records.facets['facet_fields']) | ||
44 | end | 41 | end |
45 | 42 | ||
46 | # A basic faceted search using facet queries to get counts. | 43 | # A basic faceted search using facet queries to get counts. |
@@ -56,7 +53,7 @@ class FacetedSearchTest < Test::Unit::TestCase | @@ -56,7 +53,7 @@ class FacetedSearchTest < Test::Unit::TestCase | ||
56 | assert_equal({"facet_queries" => {"price_rf:[* TO 200.00]"=>2, | 53 | assert_equal({"facet_queries" => {"price_rf:[* TO 200.00]"=>2, |
57 | "price_rf:[200.00 TO 500.00]"=>1, | 54 | "price_rf:[200.00 TO 500.00]"=>1, |
58 | "price_rf:[500.00 TO *]"=>1}, | 55 | "price_rf:[500.00 TO *]"=>1}, |
59 | - "facet_fields" => {}, "facet_dates" => {}}, records.facets) | 56 | + "facet_ranges" => {}, "facet_fields" => {}, "facet_dates" => {}}, records.facets) |
60 | end | 57 | end |
61 | 58 | ||
62 | # Faceted search specifying the query and fields | 59 | # Faceted search specifying the query and fields |
@@ -72,9 +69,11 @@ class FacetedSearchTest < Test::Unit::TestCase | @@ -72,9 +69,11 @@ class FacetedSearchTest < Test::Unit::TestCase | ||
72 | assert_equal 1, q["price_rf:[200.00 TO 500.00]"] | 69 | assert_equal 1, q["price_rf:[200.00 TO 500.00]"] |
73 | 70 | ||
74 | f = records.facets["facet_fields"] | 71 | f = records.facets["facet_fields"] |
72 | + f["category_facet"] = Hash[f["category_facet"]] | ||
75 | assert_equal 1, f["category_facet"]["Electronics"] | 73 | assert_equal 1, f["category_facet"]["Electronics"] |
76 | assert_equal 2, f["category_facet"]["Memory"] | 74 | assert_equal 2, f["category_facet"]["Memory"] |
77 | assert_equal 1, f["category_facet"]["Hard Drive"] | 75 | assert_equal 1, f["category_facet"]["Hard Drive"] |
76 | + f["manufacturer_facet"] = Hash[f["manufacturer_facet"]] | ||
78 | assert_equal 1, f["manufacturer_facet"]["Samsung Electronics Co. Ltd."] | 77 | assert_equal 1, f["manufacturer_facet"]["Samsung Electronics Co. Ltd."] |
79 | assert_equal 1, f["manufacturer_facet"]["Corsair Microsystems Inc."] | 78 | assert_equal 1, f["manufacturer_facet"]["Corsair Microsystems Inc."] |
80 | assert_equal 1, f["manufacturer_facet"]["A-DATA Technology Inc."] | 79 | assert_equal 1, f["manufacturer_facet"]["A-DATA Technology Inc."] |
@@ -84,23 +83,23 @@ class FacetedSearchTest < Test::Unit::TestCase | @@ -84,23 +83,23 @@ class FacetedSearchTest < Test::Unit::TestCase | ||
84 | # Faceted searches with :sort and :zeros options turned on/off | 83 | # Faceted searches with :sort and :zeros options turned on/off |
85 | def test_faceted_search_using_zero_and_sort | 84 | def test_faceted_search_using_zero_and_sort |
86 | records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]} | 85 | records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]} |
87 | - assert_equal({"category_facet"=>{"Electronics"=>1, "Memory"=>2, "Hard Drive"=>1}}, records.facets['facet_fields']) | 86 | + assert_equal({"category_facet"=>[["Electronics", 1], ["Hard Drive", 1], ["Memory", 2]]}, records.facets['facet_fields']) |
88 | 87 | ||
89 | records = Electronic.find_by_solr "memory", :facets => {:sort => true, :fields =>[:category]} | 88 | records = Electronic.find_by_solr "memory", :facets => {:sort => true, :fields =>[:category]} |
90 | - assert_equal({"category_facet"=>{"Memory"=>2, "Electronics"=>1, "Hard Drive"=>1}}, records.facets['facet_fields']) | 89 | + assert_equal({"category_facet"=>[["Memory", 2], ["Electronics", 1], ["Hard Drive", 1]]}, records.facets['facet_fields']) |
91 | 90 | ||
92 | records = Electronic.find_by_solr "memory", :facets => {:fields =>[:manufacturer]} | 91 | records = Electronic.find_by_solr "memory", :facets => {:fields =>[:manufacturer]} |
93 | - assert_equal({"manufacturer_facet" => {"Dell, Inc" => 0, | ||
94 | - "Samsung Electronics Co. Ltd." => 1, | ||
95 | - "Corsair Microsystems Inc." => 1, | ||
96 | - "A-DATA Technology Inc." => 1, | ||
97 | - "Apple Computer Inc." => 1}}, records.facets['facet_fields']) | 92 | + assert_equal({"manufacturer_facet" => [["A-DATA Technology Inc.", 1], |
93 | + ["Apple Computer Inc.", 1], | ||
94 | + ["Corsair Microsystems Inc.", 1], | ||
95 | + ["Dell, Inc", 0], | ||
96 | + ["Samsung Electronics Co. Ltd.", 1]]}, records.facets['facet_fields']) | ||
98 | 97 | ||
99 | records = Electronic.find_by_solr "memory", :facets => {:zeros => false, :fields =>[:manufacturer]} | 98 | records = Electronic.find_by_solr "memory", :facets => {:zeros => false, :fields =>[:manufacturer]} |
100 | - assert_equal({"manufacturer_facet" => {"Samsung Electronics Co. Ltd." => 1, | ||
101 | - "Corsair Microsystems Inc." => 1, | ||
102 | - "A-DATA Technology Inc." => 1, | ||
103 | - "Apple Computer Inc." => 1}}, records.facets['facet_fields']) | 99 | + assert_equal({"manufacturer_facet" => [["A-DATA Technology Inc.", 1], |
100 | + ["Apple Computer Inc.", 1], | ||
101 | + ["Corsair Microsystems Inc.", 1], | ||
102 | + ["Samsung Electronics Co. Ltd.", 1]]}, records.facets['facet_fields']) | ||
104 | end | 103 | end |
105 | 104 | ||
106 | # Faceted search with 'drill-down' option being passed. | 105 | # Faceted search with 'drill-down' option being passed. |
@@ -110,13 +109,13 @@ class FacetedSearchTest < Test::Unit::TestCase | @@ -110,13 +109,13 @@ class FacetedSearchTest < Test::Unit::TestCase | ||
110 | def test_faceted_search_with_drill_down | 109 | def test_faceted_search_with_drill_down |
111 | records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]} | 110 | records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]} |
112 | assert_equal 4, records.docs.size | 111 | assert_equal 4, records.docs.size |
113 | - assert_equal({"category_facet"=>{"Electronics"=>1, "Memory"=>2, "Hard Drive"=>1}}, records.facets['facet_fields']) | 112 | + assert_equal({"category_facet"=>[["Electronics", 1], ["Hard Drive", 1], ["Memory", 2]]}, records.facets['facet_fields']) |
114 | 113 | ||
115 | records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category], | 114 | records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category], |
116 | :browse => "category:Memory", | 115 | :browse => "category:Memory", |
117 | :zeros => false} | 116 | :zeros => false} |
118 | assert_equal 2, records.docs.size | 117 | assert_equal 2, records.docs.size |
119 | - assert_equal({"category_facet"=>{"Memory"=>2}}, records.facets['facet_fields']) | 118 | + assert_equal({"category_facet"=>[["Memory", 2]]}, records.facets['facet_fields']) |
120 | end | 119 | end |
121 | 120 | ||
122 | def test_faceted_search_with_dates | 121 | def test_faceted_search_with_dates |
vendor/plugins/acts_as_solr_reloaded/test/functional/multi_solr_search_test.rb
@@ -42,11 +42,9 @@ class ActsAsSolrTest < Test::Unit::TestCase | @@ -42,11 +42,9 @@ class ActsAsSolrTest < Test::Unit::TestCase | ||
42 | assert_equal 0, records.total | 42 | assert_equal 0, records.total |
43 | end | 43 | end |
44 | 44 | ||
45 | - def test_search_on_empty_string_does_not_return_nil | 45 | + def test_search_on_empty_string_return_all_results |
46 | records = Book.multi_solr_search('', :models => [Movie, Category]) | 46 | records = Book.multi_solr_search('', :models => [Movie, Category]) |
47 | - assert_not_nil records | ||
48 | - assert_equal [], records.docs | ||
49 | - assert_equal 0, records.total | 47 | + assert_equal Book.count+Movie.count+Category.count, records.total |
50 | end | 48 | end |
51 | 49 | ||
52 | def test_search_with_score_should_set_score | 50 | def test_search_with_score_should_set_score |
vendor/plugins/acts_as_solr_reloaded/test/models/advertise.rb
vendor/plugins/acts_as_solr_reloaded/test/models/movie.rb
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | # - description | 4 | # - description |
5 | 5 | ||
6 | class Movie < ActiveRecord::Base | 6 | class Movie < ActiveRecord::Base |
7 | - acts_as_solr :additional_fields => [:current_time, {:time_on_xml => :date}] | 7 | + acts_as_solr :additional_fields => [:current_time, {:time_on_xml => :date}], :dynamic_attributes => true |
8 | 8 | ||
9 | def current_time | 9 | def current_time |
10 | Time.now.to_s | 10 | Time.now.to_s |
@@ -14,4 +14,4 @@ class Movie < ActiveRecord::Base | @@ -14,4 +14,4 @@ class Movie < ActiveRecord::Base | ||
14 | Time.now | 14 | Time.now |
15 | end | 15 | end |
16 | 16 | ||
17 | -end | ||
18 | \ No newline at end of file | 17 | \ No newline at end of file |
18 | +end |
vendor/plugins/acts_as_solr_reloaded/test/test_helper.rb
@@ -2,6 +2,8 @@ require 'rubygems' | @@ -2,6 +2,8 @@ require 'rubygems' | ||
2 | require 'test/unit' | 2 | require 'test/unit' |
3 | require 'active_record' | 3 | require 'active_record' |
4 | require 'active_record/fixtures' | 4 | require 'active_record/fixtures' |
5 | +require 'shoulda' | ||
6 | +require 'mocha' | ||
5 | 7 | ||
6 | require 'ruby-debug' | 8 | require 'ruby-debug' |
7 | 9 | ||
@@ -12,15 +14,24 @@ end | @@ -12,15 +14,24 @@ end | ||
12 | 14 | ||
13 | require 'mongo_mapper' | 15 | require 'mongo_mapper' |
14 | 16 | ||
17 | +class Rails | ||
18 | + def self.root | ||
19 | + RAILS_ROOT | ||
20 | + end | ||
21 | + | ||
22 | + def self.env | ||
23 | + RAILS_ENV | ||
24 | + end | ||
25 | +end | ||
26 | + | ||
15 | MongoMapper.database = "acts_as_solr_reloaded-test" | 27 | MongoMapper.database = "acts_as_solr_reloaded-test" |
16 | 28 | ||
17 | RAILS_ROOT = File.dirname(__FILE__) unless defined? RAILS_ROOT | 29 | RAILS_ROOT = File.dirname(__FILE__) unless defined? RAILS_ROOT |
18 | RAILS_ENV = 'test' unless defined? RAILS_ENV | 30 | RAILS_ENV = 'test' unless defined? RAILS_ENV |
19 | ENV["RAILS_ENV"] = "test" | 31 | ENV["RAILS_ENV"] = "test" |
20 | -ENV["ACTS_AS_SOLR_TEST"] = "true" | ||
21 | 32 | ||
33 | +require File.expand_path(File.dirname(__FILE__) + '/../config/solr_environment') | ||
22 | require File.expand_path(File.dirname(__FILE__) + '/../lib/acts_as_solr') | 34 | require File.expand_path(File.dirname(__FILE__) + '/../lib/acts_as_solr') |
23 | -require File.expand_path(File.dirname(__FILE__) + '/../config/solr_environment.rb') | ||
24 | 35 | ||
25 | # Load Models | 36 | # Load Models |
26 | models_dir = File.join(File.dirname( __FILE__ ), 'models') | 37 | models_dir = File.join(File.dirname( __FILE__ ), 'models') |
@@ -57,14 +68,17 @@ class Test::Unit::TestCase | @@ -57,14 +68,17 @@ class Test::Unit::TestCase | ||
57 | def self.clear_from_solr(table_name) | 68 | def self.clear_from_solr(table_name) |
58 | ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "type_s:#{table_name.to_s.capitalize.singularize}")) | 69 | ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "type_s:#{table_name.to_s.capitalize.singularize}")) |
59 | end | 70 | end |
60 | -end | ||
61 | 71 | ||
62 | -class Rails | ||
63 | - def self.root | ||
64 | - RAILS_ROOT | 72 | + def assert_equivalent(enum1, enum2) |
73 | + assert( ((enum1 - enum2) == []) && ((enum2 - enum1) == []), "<#{enum1.inspect}> expected to be equivalent to <#{enum2.inspect}>") | ||
65 | end | 74 | end |
66 | 75 | ||
67 | - def self.env | ||
68 | - RAILS_ENV | 76 | + def assert_includes(array, element) |
77 | + assert(array.include?(element), "<#{array.inspect}> expected to include <#{element.inspect}>") | ||
78 | + end | ||
79 | + | ||
80 | + def assert_not_includes(array, element) | ||
81 | + assert(!array.include?(element), "<#{array.inspect}> expected to NOT include <#{element.inspect}>") | ||
69 | end | 82 | end |
83 | + | ||
70 | end | 84 | end |
vendor/plugins/acts_as_solr_reloaded/test/unit/acts_methods_shoulda.rb
1 | -require File.expand_path("#{File.dirname(__FILE__)}/test_helper") | 1 | +require File.expand_path("#{File.dirname(__FILE__)}/../test_helper") |
2 | 2 | ||
3 | class ActsMethodsTest < Test::Unit::TestCase | 3 | class ActsMethodsTest < Test::Unit::TestCase |
4 | class Model | 4 | class Model |
@@ -55,6 +55,21 @@ class ActsMethodsTest < Test::Unit::TestCase | @@ -55,6 +55,21 @@ class ActsMethodsTest < Test::Unit::TestCase | ||
55 | acts_as_solr | 55 | acts_as_solr |
56 | end | 56 | end |
57 | 57 | ||
58 | + should "enable auto_commit in all environments except production" do | ||
59 | + Taggable.stubs(:after_save) | ||
60 | + Taggable.stubs(:after_destroy) | ||
61 | + instance = Taggable.new | ||
62 | + instance.stubs(:attributes).returns({}) | ||
63 | + Taggable.stubs(:new).returns(instance) | ||
64 | + | ||
65 | + Rails.stubs(:env).returns('test') | ||
66 | + Taggable.acts_as_solr | ||
67 | + assert Taggable.configuration[:auto_commit] == true | ||
68 | + Rails.stubs(:env).returns('production') | ||
69 | + Taggable.acts_as_solr | ||
70 | + assert Taggable.configuration[:auto_commit] == false | ||
71 | + end | ||
72 | + | ||
58 | should "define the model as taggable if taggable is true" do | 73 | should "define the model as taggable if taggable is true" do |
59 | assert Taggable.taggable? | 74 | assert Taggable.taggable? |
60 | end | 75 | end |
@@ -63,12 +78,12 @@ class ActsMethodsTest < Test::Unit::TestCase | @@ -63,12 +78,12 @@ class ActsMethodsTest < Test::Unit::TestCase | ||
63 | assert !NotTaggable.taggable? | 78 | assert !NotTaggable.taggable? |
64 | end | 79 | end |
65 | 80 | ||
66 | - should "define the type of a MongoMapper document id as text" do | ||
67 | - assert_equal :text, Mapper.configuration[:solr_fields][:_id][:type] | 81 | + should "define the type of a MongoMapper document id as string" do |
82 | + assert_equal :string, Mapper.configuration[:solr_fields][:_id][:type] | ||
68 | end | 83 | end |
69 | 84 | ||
70 | - should "recognize the type String of a MongoMapper key as text" do | ||
71 | - assert_equal :text, Mapper.configuration[:solr_fields][:value1][:type] | 85 | + should "recognize the type String of a MongoMapper key as string" do |
86 | + assert_equal :string, Mapper.configuration[:solr_fields][:value1][:type] | ||
72 | end | 87 | end |
73 | 88 | ||
74 | context "when getting field values" do | 89 | context "when getting field values" do |
vendor/plugins/acts_as_solr_reloaded/test/unit/class_methods_shoulda.rb
1 | -require File.expand_path("#{File.dirname(__FILE__)}/test_helper") | 1 | +require File.expand_path("#{File.dirname(__FILE__)}/../test_helper") |
2 | 2 | ||
3 | class User | 3 | class User |
4 | attr_accessor :name, :id | 4 | attr_accessor :name, :id |
@@ -31,12 +31,12 @@ class ClassMethodsTest < Test::Unit::TestCase | @@ -31,12 +31,12 @@ class ClassMethodsTest < Test::Unit::TestCase | ||
31 | end | 31 | end |
32 | 32 | ||
33 | should "include the type field in the query" do | 33 | should "include the type field in the query" do |
34 | - expects(:parse_query).with("name:paul", {:results_format => :objects}, "AND (type_t:User)") | 34 | + expects(:parse_query).with("name:paul", {:results_format => :objects}) |
35 | multi_solr_search("name:paul") | 35 | multi_solr_search("name:paul") |
36 | end | 36 | end |
37 | 37 | ||
38 | should "add all models in the query" do | 38 | should "add all models in the query" do |
39 | - expects(:parse_query).with("name:paul", {:results_format => :objects, :models => ["Movie", "DVD"]}, "AND (type_t:User OR type_t:Movie OR type_t:DVD)") | 39 | + expects(:parse_query).with("name:paul", {:results_format => :objects, :models => ["Movie", "DVD"]}) |
40 | multi_solr_search("name:paul", :models => ["Movie", "DVD"]) | 40 | multi_solr_search("name:paul", :models => ["Movie", "DVD"]) |
41 | end | 41 | end |
42 | 42 | ||
@@ -82,4 +82,4 @@ class ClassMethodsTest < Test::Unit::TestCase | @@ -82,4 +82,4 @@ class ClassMethodsTest < Test::Unit::TestCase | ||
82 | end | 82 | end |
83 | end | 83 | end |
84 | end | 84 | end |
85 | -end | ||
86 | \ No newline at end of file | 85 | \ No newline at end of file |
86 | +end |
vendor/plugins/acts_as_solr_reloaded/test/unit/common_methods_shoulda.rb
1 | -require File.expand_path("#{File.dirname(__FILE__)}/test_helper") | 1 | +require File.expand_path("#{File.dirname(__FILE__)}/../test_helper") |
2 | 2 | ||
3 | class CommonMethodsTest < Test::Unit::TestCase | 3 | class CommonMethodsTest < Test::Unit::TestCase |
4 | include ActsAsSolr::CommonMethods | 4 | include ActsAsSolr::CommonMethods |
@@ -35,6 +35,14 @@ class CommonMethodsTest < Test::Unit::TestCase | @@ -35,6 +35,14 @@ class CommonMethodsTest < Test::Unit::TestCase | ||
35 | assert_equal "f", get_solr_field_type(:float) | 35 | assert_equal "f", get_solr_field_type(:float) |
36 | end | 36 | end |
37 | 37 | ||
38 | + should "return f for a decimal" do | ||
39 | + assert_equal "f", get_solr_field_type(:decimal) | ||
40 | + end | ||
41 | + | ||
42 | + should "return do for a double" do | ||
43 | + assert_equal "do", get_solr_field_type(:double) | ||
44 | + end | ||
45 | + | ||
38 | should "return b for a boolean" do | 46 | should "return b for a boolean" do |
39 | assert_equal "b", get_solr_field_type(:boolean) | 47 | assert_equal "b", get_solr_field_type(:boolean) |
40 | end | 48 | end |
vendor/plugins/acts_as_solr_reloaded/test/unit/instance_methods_shoulda.rb
1 | -require File.expand_path("#{File.dirname(__FILE__)}/test_helper") | 1 | +require File.expand_path("#{File.dirname(__FILE__)}/../test_helper") |
2 | module Solr; end | 2 | module Solr; end |
3 | 3 | ||
4 | class InstanceMethodsTest < Test::Unit::TestCase | 4 | class InstanceMethodsTest < Test::Unit::TestCase |
@@ -148,7 +148,8 @@ class InstanceMethodsTest < Test::Unit::TestCase | @@ -148,7 +148,8 @@ class InstanceMethodsTest < Test::Unit::TestCase | ||
148 | 148 | ||
149 | context "when converting an instance to a solr document" do | 149 | context "when converting an instance to a solr document" do |
150 | setup do | 150 | setup do |
151 | - @instance.configuration = {:if => true, :auto_commit => true, :solr_fields => {:name => {:boost => 9.0}}, :boost => 10.0} | 151 | + @instance.configuration = {:if => true, :auto_commit => true, :fields => [:name, :last_name], |
152 | + :solr_fields => {:name => {:boost => 9.0}, :last_name => {:type => :string}}, :boost => 10.0} | ||
152 | @instance.solr_configuration = {:type_field => "type", :primary_key_field => "pk_id", :default_boost => 25.0} | 153 | @instance.solr_configuration = {:type_field => "type", :primary_key_field => "pk_id", :default_boost => 25.0} |
153 | end | 154 | end |
154 | 155 | ||
@@ -183,12 +184,12 @@ class InstanceMethodsTest < Test::Unit::TestCase | @@ -183,12 +184,12 @@ class InstanceMethodsTest < Test::Unit::TestCase | ||
183 | end | 184 | end |
184 | 185 | ||
185 | should "add the longitude" do | 186 | should "add the longitude" do |
186 | - field = @fields.find { |field| field.name.eql? "lng" } | 187 | + field = @fields.find { |field| field.name.eql? "lng_f" } |
187 | assert_equal @local.longitude, field.value | 188 | assert_equal @local.longitude, field.value |
188 | end | 189 | end |
189 | 190 | ||
190 | should "add the latitude" do | 191 | should "add the latitude" do |
191 | - field = @fields.find { |field| field.name.eql? "lat" } | 192 | + field = @fields.find { |field| field.name.eql? "lat_f" } |
192 | assert_equal @local.latitude, field.value | 193 | assert_equal @local.latitude, field.value |
193 | end | 194 | end |
194 | end | 195 | end |
@@ -198,7 +199,7 @@ class InstanceMethodsTest < Test::Unit::TestCase | @@ -198,7 +199,7 @@ class InstanceMethodsTest < Test::Unit::TestCase | ||
198 | @instance.stubs(:local).returns(nil) | 199 | @instance.stubs(:local).returns(nil) |
199 | @instance.configuration[:spatial] = true | 200 | @instance.configuration[:spatial] = true |
200 | fields = @instance.to_solr_doc.fields | 201 | fields = @instance.to_solr_doc.fields |
201 | - assert_equal nil, fields.find { |field| field.name.eql? 'lng' } | 202 | + assert_equal nil, fields.find { |field| field.name.eql? 'lng_f' } |
202 | end | 203 | end |
203 | end | 204 | end |
204 | 205 | ||
@@ -217,6 +218,13 @@ class InstanceMethodsTest < Test::Unit::TestCase | @@ -217,6 +218,13 @@ class InstanceMethodsTest < Test::Unit::TestCase | ||
217 | field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "name_s"} | 218 | field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "name_s"} |
218 | assert_equal 25.0, field.boost | 219 | assert_equal 25.0, field.boost |
219 | end | 220 | end |
221 | + | ||
222 | + should "ignore null fields" do | ||
223 | + @instance.stubs(:name_for_solr).returns(nil) | ||
224 | + @instance.stubs(:last_name_for_solr).returns('Dohn') | ||
225 | + assert ! @instance.to_solr_doc.fields.find {|f| f.name.to_s == "name_s"} | ||
226 | + assert @instance.to_solr_doc.fields.find {|f| f.name.to_s == "last_name_s"} | ||
227 | + end | ||
220 | 228 | ||
221 | should "not overwrite the type or id field" do | 229 | should "not overwrite the type or id field" do |
222 | @instance.configuration[:solr_fields] = {:type => {}, :id => {}} | 230 | @instance.configuration[:solr_fields] = {:type => {}, :id => {}} |
@@ -281,7 +289,7 @@ class InstanceMethodsTest < Test::Unit::TestCase | @@ -281,7 +289,7 @@ class InstanceMethodsTest < Test::Unit::TestCase | ||
281 | @instance.stubs(:people).returns(@people) | 289 | @instance.stubs(:people).returns(@people) |
282 | @reflection = OpenStruct.new(:macro => :has_many) | 290 | @reflection = OpenStruct.new(:macro => :has_many) |
283 | @instance.class.stubs(:reflect_on_association).returns(@reflection) | 291 | @instance.class.stubs(:reflect_on_association).returns(@reflection) |
284 | - @instance.configuration[:solr_includes] = {@assoc => {}} | 292 | + @instance.configuration[:solr_includes] = {@assoc => {:type => :string}} |
285 | @instance.solr_configuration.merge! :default_boost => 35.0 | 293 | @instance.solr_configuration.merge! :default_boost => 35.0 |
286 | end | 294 | end |
287 | 295 | ||
@@ -306,7 +314,6 @@ class InstanceMethodsTest < Test::Unit::TestCase | @@ -306,7 +314,6 @@ class InstanceMethodsTest < Test::Unit::TestCase | ||
306 | end | 314 | end |
307 | 315 | ||
308 | should "set the default boost for the include, if none is configured" do | 316 | should "set the default boost for the include, if none is configured" do |
309 | - # @instance.configuration[:solr_includes] = {@assoc => {}} | ||
310 | field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "person_s"} | 317 | field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "person_s"} |
311 | assert_equal 35.0, field.boost | 318 | assert_equal 35.0, field.boost |
312 | end | 319 | end |
@@ -318,10 +325,9 @@ class InstanceMethodsTest < Test::Unit::TestCase | @@ -318,10 +325,9 @@ class InstanceMethodsTest < Test::Unit::TestCase | ||
318 | end | 325 | end |
319 | 326 | ||
320 | should "default to a field value with all association attributes" do | 327 | should "default to a field value with all association attributes" do |
321 | - # @instance.configuration[:solr_includes] = {@assoc => {}} | ||
322 | field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "person_s"} | 328 | field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "person_s"} |
323 | @people.first.attributes.each do |attr, value| | 329 | @people.first.attributes.each do |attr, value| |
324 | - assert_match /#{attr}=#{value}/, field.value | 330 | + assert_match /#{value}/, field.value |
325 | end | 331 | end |
326 | end | 332 | end |
327 | 333 | ||
@@ -346,7 +352,6 @@ class InstanceMethodsTest < Test::Unit::TestCase | @@ -346,7 +352,6 @@ class InstanceMethodsTest < Test::Unit::TestCase | ||
346 | end | 352 | end |
347 | 353 | ||
348 | should "include multiple values separately if the :multivalued options is specified" do | 354 | should "include multiple values separately if the :multivalued options is specified" do |
349 | - # @instance.configuration[:solr_includes] = {@assoc => {}} | ||
350 | second_person = {:name => 'Dean Venture', :address => 'Venture Compound'} | 355 | second_person = {:name => 'Dean Venture', :address => 'Venture Compound'} |
351 | @people << OpenStruct.new(second_person.merge(:attributes => second_person)) | 356 | @people << OpenStruct.new(second_person.merge(:attributes => second_person)) |
352 | fields = @instance.to_solr_doc.fields.select {|f| f.name.to_s == "person_s"} | 357 | fields = @instance.to_solr_doc.fields.select {|f| f.name.to_s == "person_s"} |
vendor/plugins/acts_as_solr_reloaded/test/unit/parser_methods_shoulda.rb
1 | -require File.expand_path("#{File.dirname(__FILE__)}/test_helper") | 1 | +require File.expand_path("#{File.dirname(__FILE__)}/../test_helper") |
2 | +require File.expand_path("#{File.dirname(__FILE__)}/parser_instance") | ||
2 | 3 | ||
3 | class ParserMethodsTest < Test::Unit::TestCase | 4 | class ParserMethodsTest < Test::Unit::TestCase |
4 | 5 | ||
@@ -16,6 +17,8 @@ class ParserMethodsTest < Test::Unit::TestCase | @@ -16,6 +17,8 @@ class ParserMethodsTest < Test::Unit::TestCase | ||
16 | @results.stubs(:highlighting).returns [] | 17 | @results.stubs(:highlighting).returns [] |
17 | @results.stubs(:data).returns({"responseHeader" => {"QTime" => "10.2"}}) | 18 | @results.stubs(:data).returns({"responseHeader" => {"QTime" => "10.2"}}) |
18 | @results.stubs(:header).returns({}) | 19 | @results.stubs(:header).returns({}) |
20 | + @parser.stubs(:merge_conditions).returns({:id => []}) | ||
21 | + @parser.stubs(:all).returns([]) | ||
19 | end | 22 | end |
20 | 23 | ||
21 | should "return a SearchResults object" do | 24 | should "return a SearchResults object" do |
@@ -36,11 +39,13 @@ class ParserMethodsTest < Test::Unit::TestCase | @@ -36,11 +39,13 @@ class ParserMethodsTest < Test::Unit::TestCase | ||
36 | @parser.configuration = {:format => :objects} | 39 | @parser.configuration = {:format => :objects} |
37 | @parser.solr_configuration = {:primary_key_field => :pk_id} | 40 | @parser.solr_configuration = {:primary_key_field => :pk_id} |
38 | @results.stubs(:hits).returns [{"pk_id" => 1}, {"pk_id" => 2}] | 41 | @results.stubs(:hits).returns [{"pk_id" => 1}, {"pk_id" => 2}] |
42 | + @ids = @results.hits.map{ |h| h.first.last } | ||
39 | @parser.stubs(:reorder) | 43 | @parser.stubs(:reorder) |
44 | + @parser.expects(:merge_conditions).returns({:id => @ids}) | ||
40 | end | 45 | end |
41 | 46 | ||
42 | should "query with the record ids" do | 47 | should "query with the record ids" do |
43 | - @parser.expects(:find).with([1, 2], {}).returns [1, 2] | 48 | + @parser.expects(:all).with(:conditions => {:id => @ids}).returns @ids |
44 | @parser.parse_results(@results) | 49 | @parser.parse_results(@results) |
45 | end | 50 | end |
46 | 51 | ||
@@ -50,8 +55,8 @@ class ParserMethodsTest < Test::Unit::TestCase | @@ -50,8 +55,8 @@ class ParserMethodsTest < Test::Unit::TestCase | ||
50 | end | 55 | end |
51 | 56 | ||
52 | should "add :include if :include was specified" do | 57 | should "add :include if :include was specified" do |
53 | - @parser.expects(:find).with([1, 2], :include => [:author]).returns [1, 2] | ||
54 | - @parser.parse_results(@results, :include => [:author]) | 58 | + @parser.expects(:all).with(:conditions => {:id => @ids}, :include => [:author]).returns @ids |
59 | + @parser.parse_results(@results, :sql_options => {:include => [:author]}) | ||
55 | end | 60 | end |
56 | end | 61 | end |
57 | 62 | ||
@@ -129,8 +134,8 @@ class ParserMethodsTest < Test::Unit::TestCase | @@ -129,8 +134,8 @@ class ParserMethodsTest < Test::Unit::TestCase | ||
129 | end | 134 | end |
130 | 135 | ||
131 | context "when reordering results" do | 136 | context "when reordering results" do |
132 | - should "raise an error if arguments don't have the same number of elements" do | ||
133 | - assert_raise(RuntimeError) {@parser.reorder([], [1])} | 137 | + should "don't raise an error if arguments don't have the same number of elements" do |
138 | + assert_nothing_raised {@parser.reorder([], [1])} | ||
134 | end | 139 | end |
135 | 140 | ||
136 | should "reorder the results to match the order of the documents returned by solr" do | 141 | should "reorder the results to match the order of the documents returned by solr" do |
@@ -151,7 +156,22 @@ class ParserMethodsTest < Test::Unit::TestCase | @@ -151,7 +156,22 @@ class ParserMethodsTest < Test::Unit::TestCase | ||
151 | ActsAsSolr::Post.stubs(:execute) | 156 | ActsAsSolr::Post.stubs(:execute) |
152 | @parser.stubs(:solr_type_condition).returns "(type:ParserMethodsTest)" | 157 | @parser.stubs(:solr_type_condition).returns "(type:ParserMethodsTest)" |
153 | @parser.solr_configuration = {:primary_key_field => "id"} | 158 | @parser.solr_configuration = {:primary_key_field => "id"} |
154 | - @parser.configuration = {:solr_fields => nil} | 159 | + @parser.configuration = {:solr_fields => {:title => {:type => :string}, :tag => {:type => :text}, :description => {:type => :text}}} |
160 | + end | ||
161 | + | ||
162 | + should "not escape fields followed filter and boost chars" do | ||
163 | + ActsAsSolr::Post.expects(:execute).with {|request, core| | ||
164 | + request.to_hash[:q] == 'tag_t:blah nonfield\\:blah' | ||
165 | + } | ||
166 | + @parser.parse_query "tag:blah nonfield:blah" | ||
167 | + end | ||
168 | + | ||
169 | + | ||
170 | + should "always use search as query type" do | ||
171 | + ActsAsSolr::Post.expects(:execute).with {|request, core| | ||
172 | + request.to_hash[:qt] == 'search' | ||
173 | + } | ||
174 | + @parser.parse_query "foo" | ||
155 | end | 175 | end |
156 | 176 | ||
157 | should "set the limit and offset" do | 177 | should "set the limit and offset" do |
@@ -165,23 +185,16 @@ class ParserMethodsTest < Test::Unit::TestCase | @@ -165,23 +185,16 @@ class ParserMethodsTest < Test::Unit::TestCase | ||
165 | should "set the relevancy of the specified fields and non-filtered terms" do | 185 | should "set the relevancy of the specified fields and non-filtered terms" do |
166 | ActsAsSolr::Post.expects(:execute).with {|request, core| | 186 | ActsAsSolr::Post.expects(:execute).with {|request, core| |
167 | q = request.to_hash[:q] | 187 | q = request.to_hash[:q] |
168 | - q.starts_with?("(aeroplane brasil continent_t:south OR tag_t:(aeroplane brasil)^5 OR description_t:(aeroplane brasil)^3)") or q.starts_with?("(aeroplane brasil continent_t:south OR description_t:(aeroplane brasil)^3 OR tag_t:(aeroplane brasil)^5)") | 188 | + q.starts_with?("aeroplane brasil OR tag_t:(aeroplane brasil)^5 OR description_t:(aeroplane brasil)^3") or |
189 | + q.starts_with?("aeroplane brasil OR description_t:(aeroplane brasil)^3 OR tag_t:(aeroplane brasil)^5") | ||
169 | } | 190 | } |
170 | - @parser.parse_query "aeroplane brasil continent:south", :relevance => {:tag => 5, :description => 3} | ||
171 | - end | ||
172 | - | ||
173 | - should "set the relevance unless no query specified" do | ||
174 | - expected = "(continent_t:south)" | ||
175 | - ActsAsSolr::Post.expects(:execute).with {|request, core| | ||
176 | - request.to_hash[:q].starts_with? expected | ||
177 | - } | ||
178 | - @parser.parse_query "continent:south", :relevance => {:tag => 5, :description => 3} | 191 | + @parser.parse_query "aeroplane brasil", :filter_queries => ['continent:south'], :relevance => {:tag => 5, :description => 3} |
179 | end | 192 | end |
180 | 193 | ||
181 | should "set the relevance with simple queries" do | 194 | should "set the relevance with simple queries" do |
182 | ActsAsSolr::Post.expects(:execute).with {|request, core| | 195 | ActsAsSolr::Post.expects(:execute).with {|request, core| |
183 | q = request.to_hash[:q] | 196 | q = request.to_hash[:q] |
184 | - q.starts_with?("(car OR tag_t:(car)^5 OR description_t:(car)^3)") or q.starts_with?("(car OR description_t:(car)^3 OR tag_t:(car)^5)") | 197 | + q.starts_with?("car OR tag_t:(car)^5 OR description_t:(car)^3") or q.starts_with?("car OR description_t:(car)^3 OR tag_t:(car)^5") |
185 | } | 198 | } |
186 | @parser.parse_query "car", :relevance => {:tag => 5, :description => 3} | 199 | @parser.parse_query "car", :relevance => {:tag => 5, :description => 3} |
187 | end | 200 | end |
@@ -202,24 +215,24 @@ class ParserMethodsTest < Test::Unit::TestCase | @@ -202,24 +215,24 @@ class ParserMethodsTest < Test::Unit::TestCase | ||
202 | 215 | ||
203 | should "add the type" do | 216 | should "add the type" do |
204 | ActsAsSolr::Post.expects(:execute).with {|request, core| | 217 | ActsAsSolr::Post.expects(:execute).with {|request, core| |
205 | - request.to_hash[:q].include?("(type:ParserMethodsTest)") | 218 | + request.to_hash[:fq].include?("(type:ParserMethodsTest)") |
206 | } | 219 | } |
207 | @parser.parse_query "foo" | 220 | @parser.parse_query "foo" |
208 | end | 221 | end |
209 | 222 | ||
210 | - should "append the field types for the specified fields" do | 223 | + should "not append field types for not specified fields" do |
211 | ActsAsSolr::Post.expects(:execute).with {|request, core| | 224 | ActsAsSolr::Post.expects(:execute).with {|request, core| |
212 | - request.to_hash[:q].include?("(username_t:Chunky)") | 225 | + request.to_hash[:fq].include?("username:Chunky") |
213 | } | 226 | } |
214 | - @parser.parse_query "username:Chunky" | 227 | + @parser.parse_query '', :filter_queries => ["username:Chunky"] |
215 | end | 228 | end |
216 | 229 | ||
217 | should "replace the field types" do | 230 | should "replace the field types" do |
218 | - @parser.expects(:replace_types).returns(["active_i:1"]) | 231 | + @parser.configuration = {:solr_fields => {:active => {:type => :integer}}} |
219 | ActsAsSolr::Post.expects(:execute).with {|request, core| | 232 | ActsAsSolr::Post.expects(:execute).with {|request, core| |
220 | - request.to_hash[:q].include?("active_i:1") | 233 | + request.to_hash[:fq].include?("active_i:1") |
221 | } | 234 | } |
222 | - @parser.parse_query "active:1" | 235 | + @parser.parse_query "", :filter_queries => ['active:1'] |
223 | end | 236 | end |
224 | 237 | ||
225 | should "add score and primary key to field list" do | 238 | should "add score and primary key to field list" do |
@@ -232,7 +245,7 @@ class ParserMethodsTest < Test::Unit::TestCase | @@ -232,7 +245,7 @@ class ParserMethodsTest < Test::Unit::TestCase | ||
232 | should "add highlight options" do | 245 | should "add highlight options" do |
233 | ActsAsSolr::Post.expects(:execute).with {|request, core| | 246 | ActsAsSolr::Post.expects(:execute).with {|request, core| |
234 | request.to_hash[:hl] == "true" | 247 | request.to_hash[:hl] == "true" |
235 | - request.to_hash["hl.fl"] == "title_t" | 248 | + request.to_hash["hl.fl"] == "title_s" |
236 | } | 249 | } |
237 | @parser.parse_query "car", :highlight => {:fields => "title"} | 250 | @parser.parse_query "car", :highlight => {:fields => "title"} |
238 | end | 251 | end |
@@ -259,30 +272,16 @@ class ParserMethodsTest < Test::Unit::TestCase | @@ -259,30 +272,16 @@ class ParserMethodsTest < Test::Unit::TestCase | ||
259 | end | 272 | end |
260 | 273 | ||
261 | context "with the around option" do | 274 | context "with the around option" do |
262 | - should "set the qt as geo" do | ||
263 | - ActsAsSolr::Post.expects(:execute).with {|request, core| | ||
264 | - request.to_hash[:qt] == ('geo') | ||
265 | - } | ||
266 | - @parser.parse_query "foo" , :latitude => '-39.36', :longitude => '77.4027', :radius => 1 | ||
267 | - end | ||
268 | - | ||
269 | should "set the radius" do | 275 | should "set the radius" do |
270 | ActsAsSolr::Post.expects(:execute).with {|request, core| | 276 | ActsAsSolr::Post.expects(:execute).with {|request, core| |
271 | - request.to_hash[:radius] == 12 | ||
272 | - } | ||
273 | - @parser.parse_query "foo" , :latitude => '-39.36', :longitude => '77.4027', :radius => 12 | ||
274 | - end | ||
275 | - | ||
276 | - should "set the latitude" do | ||
277 | - ActsAsSolr::Post.expects(:execute).with {|request, core| | ||
278 | - request.to_hash[:lat] == '-39.36' | 277 | + request.to_hash[:d] == 12 |
279 | } | 278 | } |
280 | @parser.parse_query "foo" , :latitude => '-39.36', :longitude => '77.4027', :radius => 12 | 279 | @parser.parse_query "foo" , :latitude => '-39.36', :longitude => '77.4027', :radius => 12 |
281 | end | 280 | end |
282 | 281 | ||
283 | - should "set the longitude" do | 282 | + should "set the latitude and the longitude" do |
284 | ActsAsSolr::Post.expects(:execute).with {|request, core| | 283 | ActsAsSolr::Post.expects(:execute).with {|request, core| |
285 | - request.to_hash[:long] == '77.4027' | 284 | + request.to_hash[:pt] == "-39.36, 77.4027" |
286 | } | 285 | } |
287 | @parser.parse_query "foo" , :latitude => '-39.36', :longitude => '77.4027', :radius => 12 | 286 | @parser.parse_query "foo" , :latitude => '-39.36', :longitude => '77.4027', :radius => 12 |
288 | end | 287 | end |
@@ -290,10 +289,11 @@ class ParserMethodsTest < Test::Unit::TestCase | @@ -290,10 +289,11 @@ class ParserMethodsTest < Test::Unit::TestCase | ||
290 | 289 | ||
291 | context "with the order option" do | 290 | context "with the order option" do |
292 | should "add the order criteria to the query" do | 291 | should "add the order criteria to the query" do |
292 | + @parser.configuration = {:solr_fields => {:active => {:type => :text}}} | ||
293 | ActsAsSolr::Post.expects(:execute).with {|request, core| | 293 | ActsAsSolr::Post.expects(:execute).with {|request, core| |
294 | request.to_hash[:sort].include?("active_t desc") | 294 | request.to_hash[:sort].include?("active_t desc") |
295 | } | 295 | } |
296 | - @parser.parse_query "active:1", :order => "active desc" | 296 | + @parser.parse_query "active:1", :sort => "active desc" |
297 | end | 297 | end |
298 | end | 298 | end |
299 | 299 | ||
@@ -308,16 +308,16 @@ context "When setting the field types" do | @@ -308,16 +308,16 @@ context "When setting the field types" do | ||
308 | end | 308 | end |
309 | 309 | ||
310 | should "replace the _t suffix with the real type" do | 310 | should "replace the _t suffix with the real type" do |
311 | - assert_equal ["name_s:Chunky AND age_i:21"], @parser.replace_types(["name_t:Chunky AND age_t:21"]) | 311 | + assert_equal ["name_s:Chunky AND age_i:21"], @parser.replace_types(["name:Chunky AND age:21"]) |
312 | end | 312 | end |
313 | 313 | ||
314 | context "with a suffix" do | 314 | context "with a suffix" do |
315 | should "not include the colon when false" do | 315 | should "not include the colon when false" do |
316 | - assert_equal ["name_s"], @parser.replace_types(["name_t"], false) | 316 | + assert_equal ["name_s"], @parser.replace_types(["name"], '') |
317 | end | 317 | end |
318 | 318 | ||
319 | should "include the colon by default" do | 319 | should "include the colon by default" do |
320 | - assert_equal ["name_s:Chunky"], @parser.replace_types(["name_t:Chunky"]) | 320 | + assert_equal ["name_s:Chunky"], @parser.replace_types(["name:Chunky"]) |
321 | end | 321 | end |
322 | end | 322 | end |
323 | end | 323 | end |
vendor/plugins/acts_as_solr_reloaded/test/unit/solr_add_document_shoulda.rb
0 → 100644
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +require File.expand_path("#{File.dirname(__FILE__)}/../test_helper") | ||
2 | + | ||
3 | +# This tests a solr-ruby modification | ||
4 | + | ||
5 | +class SolrAddDocumentTest < Test::Unit::TestCase | ||
6 | + | ||
7 | + should "return correct handler" do | ||
8 | + assert_equal Solr::Request::AddDocument.new.handler, 'update/json' | ||
9 | + end | ||
10 | + | ||
11 | + should "have xml as response format" do | ||
12 | + assert_equal Solr::Request::AddDocument.new.response_format, :xml | ||
13 | + end | ||
14 | + | ||
15 | +end |