Commit ce943de2cce501077ef9eda802167df1a255afb1

Authored by Braulio Bhavamitra
1 parent 0ffb2519

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
... ... @@ -11,6 +11,10 @@ solr/start.jar
11 11 solr/webapps/
12 12 solr/solr/data/*
13 13  
  14 +Gemfile.lock
  15 +test/solr
  16 +test/tmp
  17 +
14 18 acts_as_solr_reloaded-*.gem
15 19 *.log
16 20 *.log
... ...
vendor/plugins/acts_as_solr_reloaded/.travis.yml 0 → 100644
... ... @@ -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/Gemfile 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +source :rubygems
  2 +
  3 +gem 'ruby-debug'
  4 +
  5 +gem 'rails', '2.3.5'
  6 +
  7 +gem 'sqlite3'
  8 +
  9 +gem 'mongo_mapper', '0.7.6'
  10 +gem 'bson_ext', '1.0'
  11 +
  12 +gem 'mocha'
  13 +gem 'thoughtbot-shoulda'
... ...
vendor/plugins/acts_as_solr_reloaded/README.markdown
  1 +[![Build status](https://secure.travis-ci.org/coletivoEITA/acts_as_solr_reloaded.png?branch=master)](http://travis-ci.org/coletivoEITA/acts_as_solr_reloaded)
  2 +
1 3 Description
2 4 ======
3 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 8 This plugin is intended for use in old versions of Rails. For newer versions, I strongly advice using Sunspot!
7 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 13 Installation
10 14 ======
11 15  
... ...
vendor/plugins/acts_as_solr_reloaded/Rakefile
... ... @@ -3,6 +3,9 @@ require 'rake'
3 3 require 'rake/testtask'
4 4 require 'rake/rdoctask'
5 5  
  6 +ENV['RAILS_ENV'] = "test"
  7 +require File.expand_path("#{File.dirname(__FILE__)}/config/solr_environment")
  8 +
6 9 Dir["#{File.dirname(__FILE__)}/lib/tasks/*.rake"].sort.each { |ext| load ext }
7 10  
8 11 desc "Default Task"
... ... @@ -13,10 +16,7 @@ task :test => "test:unit"
13 16  
14 17 namespace :test do
15 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 20 puts "Using " + DB
21 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 34 end
35 35  
36 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 38 t.pattern = "test/functional/*_test.rb"
39 39 t.verbose = true
40 40 end
41 41  
42 42 desc "Unit tests"
43   - Rake::TestTask.new(:unit) do |t|
  43 + Rake::TestTask.new(:unit => :setup) do |t|
44 44 t.libs << 'test/unit'
45 45 t.pattern = "test/unit/*_shoulda.rb"
46 46 t.verbose = true
... ...
vendor/plugins/acts_as_solr_reloaded/TESTING_THE_PLUGIN
1 1 acts_as_solr comes with a quick and fast unit test suite, and with a longer-running
2 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 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 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 2 require "uri"
3 3 require "fileutils"
4 4 require "yaml"
  5 +require 'net/http'
  6 +
5 7 dir = File.dirname(__FILE__)
6 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 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 16 end
12 17 unless defined? SOLR_LOGS_PATH
13 18 SOLR_LOGS_PATH = ENV["SOLR_LOGS_PATH"] || "#{RAILS_ROOT}/log"
... ... @@ -35,9 +40,10 @@ end
35 40  
36 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 45 DB = (ENV['DB'] ? ENV['DB'] : 'sqlite') unless defined?(DB)
41 46 MYSQL_USER = (ENV['MYSQL_USER'].nil? ? 'root' : ENV['MYSQL_USER']) unless defined? MYSQL_USER
42 47 require File.join(File.dirname(File.expand_path(__FILE__)), '..', 'test', 'db', 'connections', DB, 'connection.rb')
43 48 end
  49 +
... ...
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb
... ... @@ -262,6 +262,7 @@ module ActsAsSolr #:nodoc:
262 262 def process_solr_options(options={}, solr_options={})
263 263 self.configuration = {
264 264 :fields => nil,
  265 + :format => :objects,
265 266 :additional_fields => nil,
266 267 :dynamic_attributes => false,
267 268 :exclude_fields => [],
... ... @@ -279,6 +280,7 @@ module ActsAsSolr #:nodoc:
279 280 :default_boost => 1.0,
280 281 }
281 282  
  283 + solr_options ||= {}
282 284 raise "Invalid options: #{(options.keys-configuration.keys).join(',')}" unless (options.keys-configuration.keys).empty?
283 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 368 column_type = format_column_type(column.type)
367 369  
368 370 case column_type
369   - when :string then :text
  371 + when :string then :string
370 372 when :datetime then :date
371 373 when :time then :date
372 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 24 #
25 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 31 # field_types:: This option is deprecated and will be obsolete by version 1.0.
32 32 # There's no need to specify the :field_types anymore when doing a
... ... @@ -156,9 +156,8 @@ module ActsAsSolr #:nodoc:
156 156 # => 0.12321548
157 157 #
158 158 def multi_solr_search(query, options = {})
159   - models = multi_model_suffix(options)
160 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 162 if data.nil? or data.total_hits == 0
164 163 return SearchResults.new(:docs => [], :total => 0)
... ... @@ -184,12 +183,6 @@ module ActsAsSolr #:nodoc:
184 183 result
185 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 186 # returns the total number of documents found in the query specified:
194 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 29 "The field types are automatically traced back when you specify a field type in your model."
30 30 end
31 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 33 options[:sort] ||= options[:sort_by]
34 34 end
35 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 51 field_type = get_solr_field_type(options[:type])
52 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 55 next if value.nil?
56 56  
57 57 suffix = get_solr_field_type(field_type)
... ... @@ -60,7 +60,7 @@ module ActsAsSolr #:nodoc:
60 60  
61 61 field = Solr::Field.new(:name => "#{solr_name}_#{suffix}", :value => value)
62 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 64 doc << field
65 65 end
66 66  
... ... @@ -81,8 +81,8 @@ module ActsAsSolr #:nodoc:
81 81  
82 82 def add_space(doc)
83 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 86 end
87 87 end
88 88  
... ... @@ -96,8 +96,8 @@ module ActsAsSolr #:nodoc:
96 96 def add_dynamic_attributes(doc)
97 97 dynamic_attributes.each do |attribute|
98 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 101 end if configuration[:dynamic_attributes]
102 102 end
103 103  
... ... @@ -117,7 +117,7 @@ module ActsAsSolr #:nodoc:
117 117 Array(data).each do |value|
118 118 field = Solr::Field.new(:name => "#{field_name}_#{suffix}", :value => value)
119 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 121 doc << field
122 122 end
123 123 end
... ...
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/mongo_mapper.rb
... ... @@ -13,14 +13,11 @@ module ActsAsSolr
13 13 def primary_key
14 14 'id'
15 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 21 end
25 22 end
26 23 end
... ...
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb
... ... @@ -3,38 +3,43 @@ module ActsAsSolr #:nodoc:
3 3 protected
4 4  
5 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 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 15 raise "Invalid parameters: #{(options.keys - valid_options).join(',')}" unless (options.keys - valid_options).empty?
27 16 begin
28 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 33 per_page = options[:per_page] || options[:limit] || 30
30 34 offset = options[:offset] || (((options[:page] || 1).to_i - 1) * per_page)
31 35 query_options[:rows] = per_page
32 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 41 query_options[:filter_queries] += replace_types([*options[:filter_queries]], '') if options[:filter_queries]
  42 +
38 43 query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions]
39 44  
40 45 # first steps on the facet parameter processing
... ... @@ -46,9 +51,9 @@ module ActsAsSolr #:nodoc:
46 51 query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false
47 52 # override the :zeros (it's deprecated anyway) if :mincount exists
48 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 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 58 if options[:facets][:dates]
54 59 query_options[:date_facets] = {}
... ... @@ -75,7 +80,7 @@ module ActsAsSolr #:nodoc:
75 80  
76 81 if options[:facets][:dates][:other]
77 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 84 end
80 85  
81 86 end
... ... @@ -83,30 +88,36 @@ module ActsAsSolr #:nodoc:
83 88  
84 89 if options[:highlight]
85 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 92 query_options[:highlighting][:require_field_match] = options[:highlight][:require_field_match] if options[:highlight][:require_field_match]
89 93 query_options[:highlighting][:max_snippets] = options[:highlight][:max_snippets] if options[:highlight][:max_snippets]
90 94 query_options[:highlighting][:prefix] = options[:highlight][:prefix] if options[:highlight][:prefix]
91 95 query_options[:highlighting][:suffix] = options[:highlight][:suffix] if options[:highlight][:suffix]
92 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 104 query_options[:latitude] = options[:latitude]
98 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 110 rescue
102 111 raise "#{$query} There was a problem executing your search\n#{query_options.inspect}\n: #{$!} in #{$!.backtrace.first}"
103 112 end
104 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 121 end
111 122  
112 123 # Parses the data returned from Solr
... ... @@ -155,8 +166,8 @@ module ActsAsSolr #:nodoc:
155 166 ids.collect {|id| ActsAsSolr::LazyDocument.new(id, self)}
156 167 elsif configuration[:format] == :objects
157 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 171 result = reorder(result, ids) unless find_options[:order]
161 172 result
162 173 else
... ... @@ -170,8 +181,8 @@ module ActsAsSolr #:nodoc:
170 181 def reorder(things, ids)
171 182 ordered_things = []
172 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 186 end
176 187 ordered_things
177 188 end
... ... @@ -229,25 +240,22 @@ module ActsAsSolr #:nodoc:
229 240 end
230 241  
231 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 246 end
234 247  
235 248 private
236 249  
237 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 255 end
250   - query
  256 + query = query.join(' OR ')
  257 +
  258 + replace_types([query], '').first
251 259 end
252 260  
253 261 end
... ...
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/search_results.rb
... ... @@ -72,7 +72,7 @@ module ActsAsSolr #:nodoc:
72 72  
73 73 # Returns a suggested query
74 74 def suggest
75   - @solr_data[:spellcheck]['suggestions']['collation'].match(/\((.+)\) /)[1]
  75 + Hash[@solr_data[:spellcheck]['suggestions']]['collation']
76 76 end
77 77  
78 78 # Returns the number of documents per page
... ... @@ -82,12 +82,12 @@ module ActsAsSolr #:nodoc:
82 82  
83 83 # Returns the number of pages found
84 84 def total_pages
85   - (total / per_page.to_f).ceil
  85 + per_page.zero? ? 0 : (total / per_page.to_f).ceil
86 86 end
87 87  
88 88 # Returns the current page
89 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 91 end
92 92  
93 93 def blank?
... ...
vendor/plugins/acts_as_solr_reloaded/lib/solr.rb
... ... @@ -23,4 +23,5 @@ require File.expand_path(&quot;#{File.dirname(__FILE__)}/solr/xml&quot;)
23 23 require File.expand_path("#{File.dirname(__FILE__)}/solr/field")
24 24 require File.expand_path("#{File.dirname(__FILE__)}/solr/request/base")
25 25 require File.expand_path("#{File.dirname(__FILE__)}/solr/document")
  26 +require File.expand_path("#{File.dirname(__FILE__)}/solr/request/json_update")
26 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 18  
19 19 # Accepts an optional <tt>:boost</tt> parameter, used to boost the relevance of a particular field.
20 20 def initialize(params)
21   - @boost = params[:boost] == 1.0 ? nil : params[:boost]
  21 + boost = params[:boost]
22 22 @name = params[:name].to_s
23 23 @value = params[:value]
24 24 # Convert any Time values into UTC/XML schema format (which Solr requires).
... ... @@ -29,6 +29,10 @@ class Solr::Field
29 29 @boost.nil? ? @value : {'boost' => @boost, 'value' => @value}
30 30 end
31 31  
  32 + def boost=(value)
  33 + @boost = value == 1.0 ? nil : value
  34 + end
  35 +
32 36 def to_xml
33 37 e = Solr::XML::Element.new 'field'
34 38 e.attributes['name'] = @name
... ...
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/add_document.rb
... ... @@ -10,6 +10,8 @@
10 10 # See the License for the specific language governing permissions and
11 11 # limitations under the License.
12 12  
  13 +require File.expand_path(File.dirname(__FILE__) + '/json_update')
  14 +
13 15 class Solr::Request::AddDocument < Solr::Request::JsonUpdate
14 16  
15 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 &lt; Solr::Request::Select
64 64  
65 65 hash[:sfield] = 'latlng'
66 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 69 # facet parameter processing
70 70 if @params[:facets]
... ...
vendor/plugins/acts_as_solr_reloaded/lib/solr/util.rb
... ... @@ -26,11 +26,21 @@ class Solr::Util
26 26 end
27 27  
28 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 42 ESCAPES.each { |e| string.gsub! e, "\\#{e}" }
34 43 string
35 44 end
  45 +
36 46 end
... ...
vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake
... ... @@ -6,9 +6,12 @@ namespace :solr do
6 6 SOLR_DIR = "apache-solr-#{SOLR_VERSION}"
7 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 12 desc "Download and install Solr+Jetty #{SOLR_VERSION}."
10 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 15 puts 'Solr already downloaded.'
13 16 else
14 17 Dir.chdir '/tmp' do
... ... @@ -17,16 +20,16 @@ namespace :solr do
17 20 sh "tar xzf apache-solr-#{SOLR_VERSION}.tgz"
18 21 end
19 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 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 26 end
24 27 end
25 28 end
26 29  
27 30 desc 'Remove Solr instalation from the tree.'
28 31 task :remove do
29   - solr_root = Rails.root + 'vendor/plugins/acts_as_solr_reloaded/solr/'
  32 + solr_root = "#{PLUGIN_ROOT}/solr/"
30 33 rm_r ['README.txt', 'bin', 'solr.xml'].map{ |i| File.join(solr_root, 'solr', i) }, :verbose => true, :force => true
31 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 35 end
... ... @@ -36,8 +39,9 @@ namespace :solr do
36 39 end
37 40  
38 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 45 FileUtils.mkdir_p(SOLR_LOGS_PATH)
42 46 FileUtils.mkdir_p(SOLR_DATA_PATH)
43 47 FileUtils.mkdir_p(SOLR_PIDS_PATH)
... ... @@ -73,8 +77,9 @@ namespace :solr do
73 77 end
74 78  
75 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 81 require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment")
  82 +
78 83 if File.exists?(SOLR_PID_FILE)
79 84 killed = false
80 85 File.open(SOLR_PID_FILE, "r") do |f|
... ... @@ -95,7 +100,7 @@ namespace :solr do
95 100 end
96 101  
97 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 104 Rake::Task["solr:stop"].invoke
100 105 Rake::Task["solr:start"].invoke
101 106 end
... ... @@ -129,7 +134,7 @@ namespace :solr do
129 134  
130 135 logger = ActiveRecord::Base.logger = Logger.new(STDOUT)
131 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 139 if start_server
135 140 puts "Starting Solr server..."
... ... @@ -148,7 +153,7 @@ namespace :solr do
148 153 models.each do |model|
149 154 if clear_first
150 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 157 ActsAsSolr::Post.execute(Solr::Request::Commit.new)
153 158 end
154 159  
... ...
vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml
... ... @@ -31,24 +31,22 @@
31 31  
32 32 <schema name="acts_as_solr" version="0.9">
33 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 50 <analyzer type="index">
53 51 <tokenizer class="solr.StandardTokenizerFactory"/>
54 52 <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
... ... @@ -62,6 +60,7 @@
62 60 -->
63 61 <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.pt.txt" />
64 62 <filter class="solr.PortugueseStemFilterFactory" />
  63 + <filter class="solr.PorterStemFilterFactory" />
65 64 <!-- too slow
66 65 <filter class="solr.HunspellStemFilterFactory" dictionary="en_US.dic" affix="en_US.aff" ignoreCase="true" />
67 66 <filter class="solr.HunspellStemFilterFactory" dictionary="pt_PT.dic" affix="pt_PT.aff" ignoreCase="true" />
... ... @@ -84,6 +83,7 @@
84 83 -->
85 84 <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.pt.txt" />
86 85 <filter class="solr.PortugueseStemFilterFactory" />
  86 + <filter class="solr.PorterStemFilterFactory" />
87 87 <!-- too slow
88 88 <filter class="solr.HunspellStemFilterFactory" dictionary="en_US.dic" affix="en_US.aff" ignoreCase="true" />
89 89 <filter class="solr.HunspellStemFilterFactory" dictionary="pt_PT.dic" affix="pt_PT.aff" ignoreCase="true" />
... ... @@ -94,19 +94,6 @@
94 94 -->
95 95 </analyzer>
96 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 98 <fieldType name="textSpell" class="solr.TextField" positionIncrementGap="100" >
112 99 <analyzer>
... ... @@ -117,54 +104,74 @@
117 104 </analyzer>
118 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 112 </types>
123 113  
124 114  
125 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 155 </fields>
155 156  
156 157 <uniqueKey>id</uniqueKey>
  158 +
157 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 172 <copyField source="lat_f" dest="latlng_0_coordinate"/>
160 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 175 <solrQueryParser defaultOperator="AND"/>
169 176  
170 177 </schema>
... ...
vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/solrconfig.xml
... ... @@ -776,7 +776,11 @@
776 776 <str>nameOfCustomComponent2</str>
777 777 </arr>
778 778 -->
779   - </requestHandler>
  779 + <arr name="last-components">
  780 + <str>spellcheck</str>
  781 + </arr>
  782 +
  783 + </requestHandler>
780 784  
781 785 <!-- DisMaxRequestHandler allows easy searching across multiple fields
782 786 for simple user-entered phrases. It's implementation is now
... ... @@ -1099,24 +1103,22 @@
1099 1103 -->
1100 1104 <lst name="spellchecker">
1101 1105 <str name="name">default</str>
1102   - <str name="field">name</str>
  1106 + <str name="field">spell</str>
1103 1107 <str name="spellcheckIndexDir">spellchecker</str>
  1108 + <str name="buildOnCommit">true</str>
  1109 + <str name="buildOnOptimize">true</str>
1104 1110 <!-- uncomment this to require terms to occur in 1% of the documents in order to be included in the dictionary
1105 1111 <float name="thresholdTokenFrequency">.01</float>
1106 1112 -->
1107 1113 </lst>
1108 1114  
1109 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 1123 <!-- a spellchecker that use an alternate comparator
1122 1124  
... ... @@ -1135,15 +1137,13 @@
1135 1137 -->
1136 1138  
1137 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 1147 </searchComponent>
1148 1148  
1149 1149 <!-- A request handler for demonstrating the spellcheck component.
... ... @@ -1444,6 +1444,7 @@
1444 1444 <str name="hl.bs.country">US</str>
1445 1445 </lst>
1446 1446 </boundaryScanner>
  1447 +
1447 1448 </highlighting>
1448 1449 </searchComponent>
1449 1450  
... ...
vendor/plugins/acts_as_solr_reloaded/test/config/solr.yml
1 1 test:
2   - url: http://localhost:8981/solr
3 2 \ No newline at end of file
  3 + url: http://0.0.0.0:8981/solr
... ...
vendor/plugins/acts_as_solr_reloaded/test/functional/acts_as_solr_test.rb
... ... @@ -5,16 +5,10 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
5 5  
6 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 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 12 # Inserting new data into Solr and making sure it's getting indexed
19 13 def test_insert_new_data
20 14 assert_equal 2, Book.count_by_solr('ruby OR splinter OR bob')
... ... @@ -102,16 +96,30 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
102 96 # The method current_time above gets indexed as being part of the
103 97 # Movie model and it's available for search as well
104 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 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 106 assert_equal 1, records.total
110 107 assert_equal ({"id" => 1, "name" => "Napoleon Dynamite",
111 108 "description" => "Cool movie about a goofy guy"}), records.docs.first.attributes
112 109 end
113 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 123 # Testing basic solr search that returns just the ids instead of the objects:
116 124 # Model.find_id_by_solr 'term'
117 125 # Note that you're able to mix free-search with fields and boolean operators
... ... @@ -140,11 +148,10 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
140 148 # Model.find_id_by_solr 'term'
141 149 # Note that you're able to mix free-search with fields and boolean operators
142 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 152 records = Book.find_id_by_solr term
146 153 assert_equal 2, records.docs.size
147   - assert_equal ['1','2'], records.docs
  154 + assert_equivalent ['1','2'], records.docs
148 155 end
149 156 end
150 157  
... ... @@ -152,8 +159,7 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
152 159 # Model.find_count_by_solr 'term'
153 160 # Note that you're able to mix free-search with fields and boolean operators
154 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 163 assert_equal 1, Book.count_by_solr(term), "there should only be 1 result for search: #{term}"
158 164 end
159 165 end
... ... @@ -221,13 +227,13 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
221 227 assert_equal 'Splinter Cell', records.docs.last.name
222 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 233 assert_equal 'Hypnotized dude loves fishing but not working', records.docs.first.description
228 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 237 assert_equal 'Cool movie about a goofy guy', records.docs.first.description
232 238 assert_equal 'Hypnotized dude loves fishing but not working', records.docs.last.description
233 239 end
... ... @@ -235,13 +241,13 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
235 241 # Testing search with omitted :field_types should
236 242 # return the same result set as if when we use it
237 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 252 end
247 253  
... ... @@ -289,6 +295,12 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
289 295 assert_equal 0, Author.count_by_solr('raymond chandler')
290 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 304 # Testing models that use a different key as the primary key
293 305 def test_search_on_model_with_string_id_field
294 306 records = Posting.find_by_solr 'first^5 OR second'
... ... @@ -379,13 +391,11 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
379 391 end
380 392  
381 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 400 assert_raise RuntimeError do
391 401 Movie.find_by_solr "office napoleon", :operator => :bad
... ... @@ -395,18 +405,17 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
395 405 # Making sure find_by_solr with scores actually return the scores
396 406 # for each individual record and orders them accordingly
397 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 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 413 assert (books.docs.last.solr_score < books.docs.first.solr_score)
405 414 end
406 415  
407 416 # Search based on fields with the :date format
408 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 419 assert_equal 2, movies.total
411 420 end
412 421  
... ... @@ -422,38 +431,26 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
422 431 assert_equal 0, Gadget.find_id_by_solr('flipvideo').total
423 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 434 def test_search_is_an_alias_for_find_by_solr
437 435 assert_equal Advertise.find_by_solr("bike").docs, Advertise.search("bike").docs
438 436 end
439 437  
440 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 445 records = Advertise.search "bike", :latitude => '-39.36', :longitude => '77.4027', :radius => 1
442 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 449 assert_equal 1, records.total
453 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 454 expected = {"name"=>["<em>Ruby</em> for Dummies"]}
458 455 assert_equal expected, records.highlights.values.first
459 456 end
... ... @@ -464,23 +461,25 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
464 461  
465 462 def test_mongo_mappers_documents_are_found
466 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 467 end
469 468  
470 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 471 end
473 472  
474 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 475 end
477 476  
478 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 479 end
481 480  
482 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 483 end
485 484  
486 485 def test_current_page_1_is_returned_when_no_records_found
... ... @@ -488,10 +487,10 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
488 487 end
489 488  
490 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 491 end
493 492  
494 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 495 end
497 496 end
... ...
vendor/plugins/acts_as_solr_reloaded/test/functional/faceted_search_test.rb
... ... @@ -14,11 +14,10 @@ class FacetedSearchTest &lt; Test::Unit::TestCase
14 14 # A basic faceted search using just one facet field
15 15 def test_faceted_search_basic
16 16 records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]}
  17 + ipod_video = Electronic.find 1
17 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 21 records.facets['facet_fields'])
23 22 end
24 23  
... ... @@ -33,14 +32,12 @@ class FacetedSearchTest &lt; Test::Unit::TestCase
33 32 def test_faceted_search_multiple_fields
34 33 records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category, :manufacturer]}
35 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 41 end
45 42  
46 43 # A basic faceted search using facet queries to get counts.
... ... @@ -56,7 +53,7 @@ class FacetedSearchTest &lt; Test::Unit::TestCase
56 53 assert_equal({"facet_queries" => {"price_rf:[* TO 200.00]"=>2,
57 54 "price_rf:[200.00 TO 500.00]"=>1,
58 55 "price_rf:[500.00 TO *]"=>1},
59   - "facet_fields" => {}, "facet_dates" => {}}, records.facets)
  56 + "facet_ranges" => {}, "facet_fields" => {}, "facet_dates" => {}}, records.facets)
60 57 end
61 58  
62 59 # Faceted search specifying the query and fields
... ... @@ -72,9 +69,11 @@ class FacetedSearchTest &lt; Test::Unit::TestCase
72 69 assert_equal 1, q["price_rf:[200.00 TO 500.00]"]
73 70  
74 71 f = records.facets["facet_fields"]
  72 + f["category_facet"] = Hash[f["category_facet"]]
75 73 assert_equal 1, f["category_facet"]["Electronics"]
76 74 assert_equal 2, f["category_facet"]["Memory"]
77 75 assert_equal 1, f["category_facet"]["Hard Drive"]
  76 + f["manufacturer_facet"] = Hash[f["manufacturer_facet"]]
78 77 assert_equal 1, f["manufacturer_facet"]["Samsung Electronics Co. Ltd."]
79 78 assert_equal 1, f["manufacturer_facet"]["Corsair Microsystems Inc."]
80 79 assert_equal 1, f["manufacturer_facet"]["A-DATA Technology Inc."]
... ... @@ -84,23 +83,23 @@ class FacetedSearchTest &lt; Test::Unit::TestCase
84 83 # Faceted searches with :sort and :zeros options turned on/off
85 84 def test_faceted_search_using_zero_and_sort
86 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 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 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 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 103 end
105 104  
106 105 # Faceted search with 'drill-down' option being passed.
... ... @@ -110,13 +109,13 @@ class FacetedSearchTest &lt; Test::Unit::TestCase
110 109 def test_faceted_search_with_drill_down
111 110 records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]}
112 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 114 records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category],
116 115 :browse => "category:Memory",
117 116 :zeros => false}
118 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 119 end
121 120  
122 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 &lt; Test::Unit::TestCase
42 42 assert_equal 0, records.total
43 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 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 48 end
51 49  
52 50 def test_search_with_score_should_set_score
... ...
vendor/plugins/acts_as_solr_reloaded/test/models/advertise.rb
... ... @@ -2,5 +2,5 @@
2 2 # - id
3 3  
4 4 class Advertise < ActiveRecord::Base
5   - acts_as_solr :dynamic_attributes => true, :spatial => true
  5 + acts_as_solr :spatial => true
6 6 end
... ...
vendor/plugins/acts_as_solr_reloaded/test/models/movie.rb
... ... @@ -4,7 +4,7 @@
4 4 # - description
5 5  
6 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 9 def current_time
10 10 Time.now.to_s
... ... @@ -14,4 +14,4 @@ class Movie &lt; ActiveRecord::Base
14 14 Time.now
15 15 end
16 16  
17   -end
18 17 \ No newline at end of file
  18 +end
... ...
vendor/plugins/acts_as_solr_reloaded/test/test_helper.rb
... ... @@ -2,6 +2,8 @@ require &#39;rubygems&#39;
2 2 require 'test/unit'
3 3 require 'active_record'
4 4 require 'active_record/fixtures'
  5 +require 'shoulda'
  6 +require 'mocha'
5 7  
6 8 require 'ruby-debug'
7 9  
... ... @@ -12,15 +14,24 @@ end
12 14  
13 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 27 MongoMapper.database = "acts_as_solr_reloaded-test"
16 28  
17 29 RAILS_ROOT = File.dirname(__FILE__) unless defined? RAILS_ROOT
18 30 RAILS_ENV = 'test' unless defined? RAILS_ENV
19 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 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 36 # Load Models
26 37 models_dir = File.join(File.dirname( __FILE__ ), 'models')
... ... @@ -57,14 +68,17 @@ class Test::Unit::TestCase
57 68 def self.clear_from_solr(table_name)
58 69 ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "type_s:#{table_name.to_s.capitalize.singularize}"))
59 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 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 82 end
  83 +
70 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 3 class ActsMethodsTest < Test::Unit::TestCase
4 4 class Model
... ... @@ -55,6 +55,21 @@ class ActsMethodsTest &lt; Test::Unit::TestCase
55 55 acts_as_solr
56 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 73 should "define the model as taggable if taggable is true" do
59 74 assert Taggable.taggable?
60 75 end
... ... @@ -63,12 +78,12 @@ class ActsMethodsTest &lt; Test::Unit::TestCase
63 78 assert !NotTaggable.taggable?
64 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 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 87 end
73 88  
74 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 3 class User
4 4 attr_accessor :name, :id
... ... @@ -31,12 +31,12 @@ class ClassMethodsTest &lt; Test::Unit::TestCase
31 31 end
32 32  
33 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 35 multi_solr_search("name:paul")
36 36 end
37 37  
38 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 40 multi_solr_search("name:paul", :models => ["Movie", "DVD"])
41 41 end
42 42  
... ... @@ -82,4 +82,4 @@ class ClassMethodsTest &lt; Test::Unit::TestCase
82 82 end
83 83 end
84 84 end
85   -end
86 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 3 class CommonMethodsTest < Test::Unit::TestCase
4 4 include ActsAsSolr::CommonMethods
... ... @@ -35,6 +35,14 @@ class CommonMethodsTest &lt; Test::Unit::TestCase
35 35 assert_equal "f", get_solr_field_type(:float)
36 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 46 should "return b for a boolean" do
39 47 assert_equal "b", get_solr_field_type(:boolean)
40 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 2 module Solr; end
3 3  
4 4 class InstanceMethodsTest < Test::Unit::TestCase
... ... @@ -148,7 +148,8 @@ class InstanceMethodsTest &lt; Test::Unit::TestCase
148 148  
149 149 context "when converting an instance to a solr document" do
150 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 153 @instance.solr_configuration = {:type_field => "type", :primary_key_field => "pk_id", :default_boost => 25.0}
153 154 end
154 155  
... ... @@ -183,12 +184,12 @@ class InstanceMethodsTest &lt; Test::Unit::TestCase
183 184 end
184 185  
185 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 188 assert_equal @local.longitude, field.value
188 189 end
189 190  
190 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 193 assert_equal @local.latitude, field.value
193 194 end
194 195 end
... ... @@ -198,7 +199,7 @@ class InstanceMethodsTest &lt; Test::Unit::TestCase
198 199 @instance.stubs(:local).returns(nil)
199 200 @instance.configuration[:spatial] = true
200 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 203 end
203 204 end
204 205  
... ... @@ -217,6 +218,13 @@ class InstanceMethodsTest &lt; Test::Unit::TestCase
217 218 field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "name_s"}
218 219 assert_equal 25.0, field.boost
219 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 229 should "not overwrite the type or id field" do
222 230 @instance.configuration[:solr_fields] = {:type => {}, :id => {}}
... ... @@ -281,7 +289,7 @@ class InstanceMethodsTest &lt; Test::Unit::TestCase
281 289 @instance.stubs(:people).returns(@people)
282 290 @reflection = OpenStruct.new(:macro => :has_many)
283 291 @instance.class.stubs(:reflect_on_association).returns(@reflection)
284   - @instance.configuration[:solr_includes] = {@assoc => {}}
  292 + @instance.configuration[:solr_includes] = {@assoc => {:type => :string}}
285 293 @instance.solr_configuration.merge! :default_boost => 35.0
286 294 end
287 295  
... ... @@ -306,7 +314,6 @@ class InstanceMethodsTest &lt; Test::Unit::TestCase
306 314 end
307 315  
308 316 should "set the default boost for the include, if none is configured" do
309   - # @instance.configuration[:solr_includes] = {@assoc => {}}
310 317 field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "person_s"}
311 318 assert_equal 35.0, field.boost
312 319 end
... ... @@ -318,10 +325,9 @@ class InstanceMethodsTest &lt; Test::Unit::TestCase
318 325 end
319 326  
320 327 should "default to a field value with all association attributes" do
321   - # @instance.configuration[:solr_includes] = {@assoc => {}}
322 328 field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "person_s"}
323 329 @people.first.attributes.each do |attr, value|
324   - assert_match /#{attr}=#{value}/, field.value
  330 + assert_match /#{value}/, field.value
325 331 end
326 332 end
327 333  
... ... @@ -346,7 +352,6 @@ class InstanceMethodsTest &lt; Test::Unit::TestCase
346 352 end
347 353  
348 354 should "include multiple values separately if the :multivalued options is specified" do
349   - # @instance.configuration[:solr_includes] = {@assoc => {}}
350 355 second_person = {:name => 'Dean Venture', :address => 'Venture Compound'}
351 356 @people << OpenStruct.new(second_person.merge(:attributes => second_person))
352 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 4 class ParserMethodsTest < Test::Unit::TestCase
4 5  
... ... @@ -16,6 +17,8 @@ class ParserMethodsTest &lt; Test::Unit::TestCase
16 17 @results.stubs(:highlighting).returns []
17 18 @results.stubs(:data).returns({"responseHeader" => {"QTime" => "10.2"}})
18 19 @results.stubs(:header).returns({})
  20 + @parser.stubs(:merge_conditions).returns({:id => []})
  21 + @parser.stubs(:all).returns([])
19 22 end
20 23  
21 24 should "return a SearchResults object" do
... ... @@ -36,11 +39,13 @@ class ParserMethodsTest &lt; Test::Unit::TestCase
36 39 @parser.configuration = {:format => :objects}
37 40 @parser.solr_configuration = {:primary_key_field => :pk_id}
38 41 @results.stubs(:hits).returns [{"pk_id" => 1}, {"pk_id" => 2}]
  42 + @ids = @results.hits.map{ |h| h.first.last }
39 43 @parser.stubs(:reorder)
  44 + @parser.expects(:merge_conditions).returns({:id => @ids})
40 45 end
41 46  
42 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 49 @parser.parse_results(@results)
45 50 end
46 51  
... ... @@ -50,8 +55,8 @@ class ParserMethodsTest &lt; Test::Unit::TestCase
50 55 end
51 56  
52 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 60 end
56 61 end
57 62  
... ... @@ -129,8 +134,8 @@ class ParserMethodsTest &lt; Test::Unit::TestCase
129 134 end
130 135  
131 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 139 end
135 140  
136 141 should "reorder the results to match the order of the documents returned by solr" do
... ... @@ -151,7 +156,22 @@ class ParserMethodsTest &lt; Test::Unit::TestCase
151 156 ActsAsSolr::Post.stubs(:execute)
152 157 @parser.stubs(:solr_type_condition).returns "(type:ParserMethodsTest)"
153 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 175 end
156 176  
157 177 should "set the limit and offset" do
... ... @@ -165,23 +185,16 @@ class ParserMethodsTest &lt; Test::Unit::TestCase
165 185 should "set the relevancy of the specified fields and non-filtered terms" do
166 186 ActsAsSolr::Post.expects(:execute).with {|request, core|
167 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 192 end
180 193  
181 194 should "set the relevance with simple queries" do
182 195 ActsAsSolr::Post.expects(:execute).with {|request, core|
183 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 199 @parser.parse_query "car", :relevance => {:tag => 5, :description => 3}
187 200 end
... ... @@ -202,24 +215,24 @@ class ParserMethodsTest &lt; Test::Unit::TestCase
202 215  
203 216 should "add the type" do
204 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 220 @parser.parse_query "foo"
208 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 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 228 end
216 229  
217 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 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 236 end
224 237  
225 238 should "add score and primary key to field list" do
... ... @@ -232,7 +245,7 @@ class ParserMethodsTest &lt; Test::Unit::TestCase
232 245 should "add highlight options" do
233 246 ActsAsSolr::Post.expects(:execute).with {|request, core|
234 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 250 @parser.parse_query "car", :highlight => {:fields => "title"}
238 251 end
... ... @@ -259,30 +272,16 @@ class ParserMethodsTest &lt; Test::Unit::TestCase
259 272 end
260 273  
261 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 275 should "set the radius" do
270 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 279 @parser.parse_query "foo" , :latitude => '-39.36', :longitude => '77.4027', :radius => 12
281 280 end
282 281  
283   - should "set the longitude" do
  282 + should "set the latitude and the longitude" do
284 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 286 @parser.parse_query "foo" , :latitude => '-39.36', :longitude => '77.4027', :radius => 12
288 287 end
... ... @@ -290,10 +289,11 @@ class ParserMethodsTest &lt; Test::Unit::TestCase
290 289  
291 290 context "with the order option" do
292 291 should "add the order criteria to the query" do
  292 + @parser.configuration = {:solr_fields => {:active => {:type => :text}}}
293 293 ActsAsSolr::Post.expects(:execute).with {|request, core|
294 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 297 end
298 298 end
299 299  
... ... @@ -308,16 +308,16 @@ context &quot;When setting the field types&quot; do
308 308 end
309 309  
310 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 312 end
313 313  
314 314 context "with a suffix" do
315 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 317 end
318 318  
319 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 321 end
322 322 end
323 323 end
... ...
vendor/plugins/acts_as_solr_reloaded/test/unit/solr_add_document_shoulda.rb 0 → 100644
... ... @@ -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
... ...