sunspot_solr 2.0.0.pre.120720 → 2.0.0.pre.120924
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/.travis.yml +35 -0
- data/README.md +863 -0
- data/Rakefile +37 -0
- data/ci/travis.sh +67 -0
- data/sunspot/.gitignore +13 -0
- data/sunspot/Gemfile +5 -0
- data/sunspot/History.txt +258 -0
- data/sunspot/LICENSE +18 -0
- data/sunspot/Rakefile +13 -0
- data/sunspot/TODO +13 -0
- data/sunspot/lib/light_config.rb +40 -0
- data/sunspot/lib/sunspot.rb +579 -0
- data/sunspot/lib/sunspot/adapters.rb +349 -0
- data/sunspot/lib/sunspot/batcher.rb +62 -0
- data/sunspot/lib/sunspot/class_set.rb +23 -0
- data/sunspot/lib/sunspot/composite_setup.rb +202 -0
- data/sunspot/lib/sunspot/configuration.rb +53 -0
- data/sunspot/lib/sunspot/data_extractor.rb +50 -0
- data/sunspot/lib/sunspot/dsl.rb +5 -0
- data/sunspot/lib/sunspot/dsl/adjustable.rb +47 -0
- data/sunspot/lib/sunspot/dsl/field_group.rb +57 -0
- data/sunspot/lib/sunspot/dsl/field_query.rb +345 -0
- data/sunspot/lib/sunspot/dsl/fields.rb +103 -0
- data/sunspot/lib/sunspot/dsl/fulltext.rb +243 -0
- data/sunspot/lib/sunspot/dsl/function.rb +27 -0
- data/sunspot/lib/sunspot/dsl/functional.rb +44 -0
- data/sunspot/lib/sunspot/dsl/more_like_this_query.rb +56 -0
- data/sunspot/lib/sunspot/dsl/paginatable.rb +32 -0
- data/sunspot/lib/sunspot/dsl/query_facet.rb +36 -0
- data/sunspot/lib/sunspot/dsl/restriction.rb +25 -0
- data/sunspot/lib/sunspot/dsl/restriction_with_near.rb +160 -0
- data/sunspot/lib/sunspot/dsl/scope.rb +214 -0
- data/sunspot/lib/sunspot/dsl/search.rb +30 -0
- data/sunspot/lib/sunspot/dsl/standard_query.rb +122 -0
- data/sunspot/lib/sunspot/field.rb +193 -0
- data/sunspot/lib/sunspot/field_factory.rb +129 -0
- data/sunspot/lib/sunspot/indexer.rb +136 -0
- data/sunspot/lib/sunspot/query.rb +11 -0
- data/sunspot/lib/sunspot/query/abstract_field_facet.rb +55 -0
- data/sunspot/lib/sunspot/query/bbox.rb +15 -0
- data/sunspot/lib/sunspot/query/boost_query.rb +24 -0
- data/sunspot/lib/sunspot/query/common_query.rb +96 -0
- data/sunspot/lib/sunspot/query/composite_fulltext.rb +36 -0
- data/sunspot/lib/sunspot/query/connective.rb +206 -0
- data/sunspot/lib/sunspot/query/date_field_facet.rb +14 -0
- data/sunspot/lib/sunspot/query/dismax.rb +132 -0
- data/sunspot/lib/sunspot/query/field_facet.rb +41 -0
- data/sunspot/lib/sunspot/query/field_group.rb +37 -0
- data/sunspot/lib/sunspot/query/filter.rb +38 -0
- data/sunspot/lib/sunspot/query/function_query.rb +52 -0
- data/sunspot/lib/sunspot/query/geo.rb +53 -0
- data/sunspot/lib/sunspot/query/geofilt.rb +16 -0
- data/sunspot/lib/sunspot/query/highlighting.rb +62 -0
- data/sunspot/lib/sunspot/query/more_like_this.rb +61 -0
- data/sunspot/lib/sunspot/query/more_like_this_query.rb +12 -0
- data/sunspot/lib/sunspot/query/pagination.rb +42 -0
- data/sunspot/lib/sunspot/query/query_facet.rb +53 -0
- data/sunspot/lib/sunspot/query/range_facet.rb +15 -0
- data/sunspot/lib/sunspot/query/restriction.rb +308 -0
- data/sunspot/lib/sunspot/query/scope.rb +9 -0
- data/sunspot/lib/sunspot/query/sort.rb +109 -0
- data/sunspot/lib/sunspot/query/sort_composite.rb +34 -0
- data/sunspot/lib/sunspot/query/standard_query.rb +16 -0
- data/sunspot/lib/sunspot/query/text_field_boost.rb +17 -0
- data/sunspot/lib/sunspot/schema.rb +151 -0
- data/sunspot/lib/sunspot/search.rb +9 -0
- data/sunspot/lib/sunspot/search/abstract_search.rb +286 -0
- data/sunspot/lib/sunspot/search/date_facet.rb +35 -0
- data/sunspot/lib/sunspot/search/facet_row.rb +27 -0
- data/sunspot/lib/sunspot/search/field_facet.rb +88 -0
- data/sunspot/lib/sunspot/search/field_group.rb +70 -0
- data/sunspot/lib/sunspot/search/group.rb +54 -0
- data/sunspot/lib/sunspot/search/highlight.rb +38 -0
- data/sunspot/lib/sunspot/search/hit.rb +150 -0
- data/sunspot/lib/sunspot/search/hit_enumerable.rb +68 -0
- data/sunspot/lib/sunspot/search/more_like_this_search.rb +31 -0
- data/sunspot/lib/sunspot/search/paginated_collection.rb +57 -0
- data/sunspot/lib/sunspot/search/query_facet.rb +67 -0
- data/sunspot/lib/sunspot/search/range_facet.rb +37 -0
- data/sunspot/lib/sunspot/search/standard_search.rb +21 -0
- data/sunspot/lib/sunspot/session.rb +262 -0
- data/sunspot/lib/sunspot/session_proxy.rb +95 -0
- data/sunspot/lib/sunspot/session_proxy/abstract_session_proxy.rb +29 -0
- data/sunspot/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +66 -0
- data/sunspot/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +89 -0
- data/sunspot/lib/sunspot/session_proxy/master_slave_session_proxy.rb +43 -0
- data/sunspot/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb +67 -0
- data/sunspot/lib/sunspot/session_proxy/sharding_session_proxy.rb +222 -0
- data/sunspot/lib/sunspot/session_proxy/silent_fail_session_proxy.rb +42 -0
- data/sunspot/lib/sunspot/session_proxy/thread_local_session_proxy.rb +37 -0
- data/sunspot/lib/sunspot/setup.rb +350 -0
- data/sunspot/lib/sunspot/text_field_setup.rb +29 -0
- data/sunspot/lib/sunspot/type.rb +393 -0
- data/sunspot/lib/sunspot/util.rb +252 -0
- data/sunspot/lib/sunspot/version.rb +3 -0
- data/sunspot/script/console +10 -0
- data/sunspot/spec/api/adapters_spec.rb +68 -0
- data/sunspot/spec/api/batcher_spec.rb +112 -0
- data/sunspot/spec/api/binding_spec.rb +50 -0
- data/sunspot/spec/api/class_set_spec.rb +24 -0
- data/sunspot/spec/api/hit_enumerable_spec.rb +47 -0
- data/sunspot/spec/api/indexer/attributes_spec.rb +149 -0
- data/sunspot/spec/api/indexer/batch_spec.rb +72 -0
- data/sunspot/spec/api/indexer/dynamic_fields_spec.rb +42 -0
- data/sunspot/spec/api/indexer/fixed_fields_spec.rb +57 -0
- data/sunspot/spec/api/indexer/fulltext_spec.rb +43 -0
- data/sunspot/spec/api/indexer/removal_spec.rb +53 -0
- data/sunspot/spec/api/indexer/spec_helper.rb +1 -0
- data/sunspot/spec/api/indexer_spec.rb +14 -0
- data/sunspot/spec/api/query/advanced_manipulation_examples.rb +35 -0
- data/sunspot/spec/api/query/connectives_examples.rb +201 -0
- data/sunspot/spec/api/query/dsl_spec.rb +18 -0
- data/sunspot/spec/api/query/dynamic_fields_examples.rb +165 -0
- data/sunspot/spec/api/query/faceting_examples.rb +497 -0
- data/sunspot/spec/api/query/fulltext_examples.rb +313 -0
- data/sunspot/spec/api/query/function_spec.rb +79 -0
- data/sunspot/spec/api/query/geo_examples.rb +68 -0
- data/sunspot/spec/api/query/group_spec.rb +32 -0
- data/sunspot/spec/api/query/highlighting_examples.rb +245 -0
- data/sunspot/spec/api/query/more_like_this_spec.rb +140 -0
- data/sunspot/spec/api/query/ordering_pagination_examples.rb +116 -0
- data/sunspot/spec/api/query/scope_examples.rb +275 -0
- data/sunspot/spec/api/query/spatial_examples.rb +27 -0
- data/sunspot/spec/api/query/spec_helper.rb +1 -0
- data/sunspot/spec/api/query/standard_spec.rb +29 -0
- data/sunspot/spec/api/query/text_field_scoping_examples.rb +30 -0
- data/sunspot/spec/api/query/types_spec.rb +20 -0
- data/sunspot/spec/api/search/dynamic_fields_spec.rb +33 -0
- data/sunspot/spec/api/search/faceting_spec.rb +360 -0
- data/sunspot/spec/api/search/highlighting_spec.rb +69 -0
- data/sunspot/spec/api/search/hits_spec.rb +147 -0
- data/sunspot/spec/api/search/paginated_collection_spec.rb +36 -0
- data/sunspot/spec/api/search/results_spec.rb +72 -0
- data/sunspot/spec/api/search/search_spec.rb +23 -0
- data/sunspot/spec/api/search/spec_helper.rb +1 -0
- data/sunspot/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +85 -0
- data/sunspot/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +30 -0
- data/sunspot/spec/api/session_proxy/master_slave_session_proxy_spec.rb +41 -0
- data/sunspot/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +78 -0
- data/sunspot/spec/api/session_proxy/sharding_session_proxy_spec.rb +77 -0
- data/sunspot/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +24 -0
- data/sunspot/spec/api/session_proxy/spec_helper.rb +9 -0
- data/sunspot/spec/api/session_proxy/thread_local_session_proxy_spec.rb +39 -0
- data/sunspot/spec/api/session_spec.rb +232 -0
- data/sunspot/spec/api/spec_helper.rb +3 -0
- data/sunspot/spec/api/sunspot_spec.rb +29 -0
- data/sunspot/spec/ext.rb +11 -0
- data/sunspot/spec/helpers/indexer_helper.rb +17 -0
- data/sunspot/spec/helpers/integration_helper.rb +8 -0
- data/sunspot/spec/helpers/mock_session_helper.rb +13 -0
- data/sunspot/spec/helpers/query_helper.rb +26 -0
- data/sunspot/spec/helpers/search_helper.rb +68 -0
- data/sunspot/spec/integration/dynamic_fields_spec.rb +57 -0
- data/sunspot/spec/integration/faceting_spec.rb +330 -0
- data/sunspot/spec/integration/field_grouping_spec.rb +100 -0
- data/sunspot/spec/integration/geospatial_spec.rb +96 -0
- data/sunspot/spec/integration/highlighting_spec.rb +44 -0
- data/sunspot/spec/integration/indexing_spec.rb +55 -0
- data/sunspot/spec/integration/keyword_search_spec.rb +317 -0
- data/sunspot/spec/integration/local_search_spec.rb +64 -0
- data/sunspot/spec/integration/more_like_this_spec.rb +43 -0
- data/sunspot/spec/integration/scoped_search_spec.rb +386 -0
- data/sunspot/spec/integration/stored_fields_spec.rb +12 -0
- data/sunspot/spec/integration/test_pagination.rb +43 -0
- data/sunspot/spec/integration/unicode_spec.rb +15 -0
- data/sunspot/spec/mocks/adapters.rb +33 -0
- data/sunspot/spec/mocks/blog.rb +3 -0
- data/sunspot/spec/mocks/comment.rb +21 -0
- data/sunspot/spec/mocks/connection.rb +126 -0
- data/sunspot/spec/mocks/mock_adapter.rb +30 -0
- data/sunspot/spec/mocks/mock_class_sharding_session_proxy.rb +24 -0
- data/sunspot/spec/mocks/mock_record.rb +52 -0
- data/sunspot/spec/mocks/mock_sharding_session_proxy.rb +15 -0
- data/sunspot/spec/mocks/photo.rb +11 -0
- data/sunspot/spec/mocks/post.rb +86 -0
- data/sunspot/spec/mocks/super_class.rb +2 -0
- data/sunspot/spec/mocks/user.rb +13 -0
- data/sunspot/spec/spec_helper.rb +40 -0
- data/sunspot/sunspot.gemspec +37 -0
- data/sunspot/tasks/rdoc.rake +27 -0
- data/sunspot/tasks/schema.rake +19 -0
- data/sunspot/tasks/todo.rake +4 -0
- data/sunspot_rails/.gitignore +7 -0
- data/sunspot_rails/.rspec +1 -0
- data/sunspot_rails/History.txt +74 -0
- data/sunspot_rails/LICENSE +18 -0
- data/sunspot_rails/MIT-LICENSE +20 -0
- data/sunspot_rails/README.rdoc +265 -0
- data/sunspot_rails/Rakefile +17 -0
- data/sunspot_rails/TODO +8 -0
- data/sunspot_rails/dev_tasks/rdoc.rake +24 -0
- data/sunspot_rails/dev_tasks/release.rake +4 -0
- data/sunspot_rails/dev_tasks/spec.rake +107 -0
- data/sunspot_rails/dev_tasks/todo.rake +4 -0
- data/sunspot_rails/gemfiles/rails-2.3.14 +12 -0
- data/sunspot_rails/gemfiles/rails-3.0.15 +12 -0
- data/sunspot_rails/gemfiles/rails-3.1.6 +12 -0
- data/sunspot_rails/gemfiles/rails-3.2.6 +12 -0
- data/sunspot_rails/generators/sunspot/sunspot_generator.rb +9 -0
- data/sunspot_rails/generators/sunspot/templates/sunspot.yml +20 -0
- data/sunspot_rails/install.rb +1 -0
- data/sunspot_rails/lib/generators/sunspot_rails.rb +9 -0
- data/sunspot_rails/lib/generators/sunspot_rails/install/install_generator.rb +13 -0
- data/sunspot_rails/lib/generators/sunspot_rails/install/templates/config/sunspot.yml +19 -0
- data/sunspot_rails/lib/sunspot/rails.rb +69 -0
- data/sunspot_rails/lib/sunspot/rails/adapters.rb +88 -0
- data/sunspot_rails/lib/sunspot/rails/configuration.rb +352 -0
- data/sunspot_rails/lib/sunspot/rails/init.rb +5 -0
- data/sunspot_rails/lib/sunspot/rails/log_subscriber.rb +45 -0
- data/sunspot_rails/lib/sunspot/rails/railtie.rb +41 -0
- data/sunspot_rails/lib/sunspot/rails/railties/controller_runtime.rb +36 -0
- data/sunspot_rails/lib/sunspot/rails/request_lifecycle.rb +36 -0
- data/sunspot_rails/lib/sunspot/rails/searchable.rb +495 -0
- data/sunspot_rails/lib/sunspot/rails/server.rb +106 -0
- data/sunspot_rails/lib/sunspot/rails/solr_instrumentation.rb +19 -0
- data/sunspot_rails/lib/sunspot/rails/solr_logging.rb +62 -0
- data/sunspot_rails/lib/sunspot/rails/spec_helper.rb +26 -0
- data/sunspot_rails/lib/sunspot/rails/stub_session_proxy.rb +146 -0
- data/sunspot_rails/lib/sunspot/rails/tasks.rb +94 -0
- data/sunspot_rails/lib/sunspot_rails.rb +12 -0
- data/sunspot_rails/spec/configuration_spec.rb +209 -0
- data/sunspot_rails/spec/model_lifecycle_spec.rb +63 -0
- data/sunspot_rails/spec/model_spec.rb +601 -0
- data/sunspot_rails/spec/rails_template/app/controllers/application_controller.rb +10 -0
- data/sunspot_rails/spec/rails_template/app/controllers/posts_controller.rb +6 -0
- data/sunspot_rails/spec/rails_template/app/models/author.rb +10 -0
- data/sunspot_rails/spec/rails_template/app/models/blog.rb +14 -0
- data/sunspot_rails/spec/rails_template/app/models/location.rb +3 -0
- data/sunspot_rails/spec/rails_template/app/models/photo_post.rb +2 -0
- data/sunspot_rails/spec/rails_template/app/models/post.rb +13 -0
- data/sunspot_rails/spec/rails_template/app/models/post_with_auto.rb +12 -0
- data/sunspot_rails/spec/rails_template/app/models/post_with_default_scope.rb +13 -0
- data/sunspot_rails/spec/rails_template/config/boot.rb +127 -0
- data/sunspot_rails/spec/rails_template/config/preinitializer.rb +22 -0
- data/sunspot_rails/spec/rails_template/config/routes.rb +9 -0
- data/sunspot_rails/spec/rails_template/config/sunspot.yml +24 -0
- data/sunspot_rails/spec/rails_template/db/schema.rb +27 -0
- data/sunspot_rails/spec/request_lifecycle_spec.rb +61 -0
- data/sunspot_rails/spec/schema.rb +27 -0
- data/sunspot_rails/spec/searchable_spec.rb +12 -0
- data/sunspot_rails/spec/server_spec.rb +33 -0
- data/sunspot_rails/spec/session_spec.rb +57 -0
- data/sunspot_rails/spec/shared_examples/indexed_after_save.rb +8 -0
- data/sunspot_rails/spec/shared_examples/not_indexed_after_save.rb +8 -0
- data/sunspot_rails/spec/spec_helper.rb +48 -0
- data/sunspot_rails/spec/stub_session_proxy_spec.rb +122 -0
- data/sunspot_rails/sunspot_rails.gemspec +43 -0
- data/{Gemfile → sunspot_solr/Gemfile} +0 -0
- data/{README.rdoc → sunspot_solr/README.rdoc} +0 -0
- data/{bin → sunspot_solr/bin}/sunspot-installer +0 -0
- data/{bin → sunspot_solr/bin}/sunspot-solr +0 -0
- data/{lib → sunspot_solr/lib}/sunspot/solr/installer.rb +0 -0
- data/{lib → sunspot_solr/lib}/sunspot/solr/installer/config_installer.rb +0 -0
- data/{lib → sunspot_solr/lib}/sunspot/solr/installer/task_helper.rb +0 -0
- data/{lib → sunspot_solr/lib}/sunspot/solr/java.rb +0 -0
- data/{lib → sunspot_solr/lib}/sunspot/solr/railtie.rb +0 -0
- data/{lib → sunspot_solr/lib}/sunspot/solr/server.rb +1 -2
- data/{lib → sunspot_solr/lib}/sunspot/solr/tasks.rb +0 -0
- data/{lib → sunspot_solr/lib}/sunspot_solr.rb +0 -0
- data/{solr → sunspot_solr/solr}/README.txt +0 -0
- data/{solr → sunspot_solr/solr}/etc/jetty.xml +0 -0
- data/{solr → sunspot_solr/solr}/etc/webdefault.xml +0 -0
- data/{solr → sunspot_solr/solr}/lib/jetty-6.1.26-patched-JETTY-1340.jar +0 -0
- data/{solr → sunspot_solr/solr}/lib/jetty-util-6.1.26-patched-JETTY-1340.jar +0 -0
- data/{solr → sunspot_solr/solr}/lib/jsp-2.1/ant-1.6.5.jar +0 -0
- data/{solr → sunspot_solr/solr}/lib/jsp-2.1/core-3.1.1.jar +0 -0
- data/{solr → sunspot_solr/solr}/lib/jsp-2.1/jsp-2.1.jar +0 -0
- data/{solr → sunspot_solr/solr}/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
- data/{solr → sunspot_solr/solr}/lib/servlet-api-2.5-20081211.jar +0 -0
- data/{solr → sunspot_solr/solr}/solr/.gitignore +0 -0
- data/{solr → sunspot_solr/solr}/solr/README.txt +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/admin-extra.html +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/elevate.xml +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/mapping-ISOLatin1Accent.txt +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/protwords.txt +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/schema.xml +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/scripts.conf +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/solrconfig.xml +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/spellings.txt +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/stopwords.txt +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/synonyms.txt +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/xslt/example.xsl +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/xslt/example_atom.xsl +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/xslt/example_rss.xsl +0 -0
- data/{solr → sunspot_solr/solr}/solr/conf/xslt/luke.xsl +0 -0
- data/{solr → sunspot_solr/solr}/start.jar +0 -0
- data/{solr → sunspot_solr/solr}/webapps/solr.war +0 -0
- data/{spec → sunspot_solr/spec}/server_spec.rb +0 -0
- data/{spec → sunspot_solr/spec}/spec_helper.rb +0 -0
- data/{sunspot_solr.gemspec → sunspot_solr/sunspot_solr.gemspec} +0 -0
- data/tools/gem_tasks.rb +69 -0
- metadata +340 -110
@@ -0,0 +1,12 @@
|
|
1
|
+
# This needs to be loaded before sunspot/search/paginated_collection
|
2
|
+
# or #to_json gets defined in Object breaking delegation to Array via
|
3
|
+
# method_missing
|
4
|
+
require 'active_support/core_ext/object/to_json' if Rails::VERSION::MAJOR == 3
|
5
|
+
|
6
|
+
require 'sunspot/rails'
|
7
|
+
|
8
|
+
if Rails::VERSION::MAJOR == 3
|
9
|
+
require 'sunspot/rails/railtie'
|
10
|
+
else
|
11
|
+
require 'sunspot/rails/init'
|
12
|
+
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Sunspot::Rails::Configuration, "default values without a sunspot.yml" do
|
4
|
+
before(:each) do
|
5
|
+
File.stub!(:exist?).and_return(false) # simulate sunspot.yml not existing
|
6
|
+
@config = Sunspot::Rails::Configuration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should handle the 'hostname' property when not set" do
|
10
|
+
@config.hostname.should == 'localhost'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should handle the 'path' property when not set" do
|
14
|
+
@config.path.should == '/solr'
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "port" do
|
18
|
+
it "should default to port 8981 in test" do
|
19
|
+
::Rails.stub!(:env => 'test')
|
20
|
+
@config = Sunspot::Rails::Configuration.new
|
21
|
+
@config.port.should == 8981
|
22
|
+
end
|
23
|
+
it "should default to port 8982 in development" do
|
24
|
+
::Rails.stub!(:env => 'development')
|
25
|
+
@config = Sunspot::Rails::Configuration.new
|
26
|
+
@config.port.should == 8982
|
27
|
+
end
|
28
|
+
it "should default to 8983 in production" do
|
29
|
+
::Rails.stub!(:env => 'production')
|
30
|
+
@config = Sunspot::Rails::Configuration.new
|
31
|
+
@config.port.should == 8983
|
32
|
+
end
|
33
|
+
it "should generally default to 8983" do
|
34
|
+
::Rails.stub!(:env => 'staging')
|
35
|
+
@config = Sunspot::Rails::Configuration.new
|
36
|
+
@config.port.should == 8983
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should set the read timeout to nil when not set" do
|
41
|
+
@config.read_timeout == nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should set the open timeout to nil when not set" do
|
45
|
+
@config.open_timeout == nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should handle the 'log_level' property when not set" do
|
49
|
+
@config.log_level.should == 'INFO'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should handle the 'log_file' property" do
|
53
|
+
@config.log_file.should =~ /log\/solr_test.log/
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should handle the 'solr_home' property when not set" do
|
57
|
+
Rails.should_receive(:root).at_least(1).and_return('/some/path')
|
58
|
+
@config.solr_home.should == '/some/path/solr'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should handle the 'data_path' property when not set" do
|
62
|
+
Rails.should_receive(:root).at_least(1).and_return('/some/path')
|
63
|
+
@config.data_path.should == '/some/path/solr/data/test'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should handle the 'pid_dir' property when not set" do
|
67
|
+
Rails.should_receive(:root).at_least(1).and_return('/some/path')
|
68
|
+
@config.pid_dir.should == '/some/path/solr/pids/test'
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should handle the 'auto_commit_after_request' propery when not set" do
|
72
|
+
@config.auto_commit_after_request?.should == true
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should handle the 'auto_commit_after_delete_request' propery when not set" do
|
76
|
+
@config.auto_commit_after_delete_request?.should == false
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should handle the 'bind_address' property when not set" do
|
80
|
+
@config.bind_address.should be_nil
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should handle the 'disabled' property when not set" do
|
84
|
+
@config.disabled?.should be_false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe Sunspot::Rails::Configuration, "user provided sunspot.yml" do
|
89
|
+
before(:each) do
|
90
|
+
::Rails.stub!(:env => 'config_test')
|
91
|
+
@config = Sunspot::Rails::Configuration.new
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should handle the 'hostname' property when set" do
|
95
|
+
@config.hostname.should == 'some.host'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should handle the 'port' property when set" do
|
99
|
+
@config.port.should == 1234
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should handle the 'path' property when set" do
|
103
|
+
@config.path.should == '/solr/idx'
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should handle the 'log_level' propery when set" do
|
107
|
+
@config.log_level.should == 'WARNING'
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should handle the 'solr_home' propery when set" do
|
111
|
+
@config.solr_home.should == '/my_superior_path'
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should handle the 'data_path' property when set" do
|
115
|
+
@config.data_path.should == '/my_superior_path/data'
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should handle the 'pid_dir' property when set" do
|
119
|
+
@config.pid_dir.should == '/my_superior_path/pids'
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should handle the 'solr_home' property when set" do
|
123
|
+
@config.solr_home.should == '/my_superior_path'
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should handle the 'auto_commit_after_request' propery when set" do
|
127
|
+
@config.auto_commit_after_request?.should == false
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should handle the 'auto_commit_after_delete_request' propery when set" do
|
131
|
+
@config.auto_commit_after_delete_request?.should == true
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should handle the 'bind_address' property when set" do
|
135
|
+
@config.bind_address.should == "127.0.0.1"
|
136
|
+
end
|
137
|
+
it "should handle the 'read_timeout' property when set" do
|
138
|
+
@config.read_timeout.should == 2
|
139
|
+
end
|
140
|
+
it "should handle the 'open_timeout' property when set" do
|
141
|
+
@config.open_timeout.should == 0.5
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe Sunspot::Rails::Configuration, "with disabled: true in sunspot.yml" do
|
146
|
+
before(:each) do
|
147
|
+
::Rails.stub!(:env => 'config_disabled_test')
|
148
|
+
@config = Sunspot::Rails::Configuration.new
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should handle the 'disabled' property when set" do
|
152
|
+
@config.disabled?.should be_true
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe Sunspot::Rails::Configuration, "with ENV['SOLR_URL'] overriding sunspot.yml" do
|
157
|
+
before(:all) do
|
158
|
+
ENV['SOLR_URL'] = 'http://environment.host:5432/solr/env'
|
159
|
+
end
|
160
|
+
|
161
|
+
before(:each) do
|
162
|
+
::Rails.stub!(:env => 'config_test')
|
163
|
+
@config = Sunspot::Rails::Configuration.new
|
164
|
+
end
|
165
|
+
|
166
|
+
after(:all) do
|
167
|
+
ENV.delete('SOLR_URL')
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should handle the 'hostname' property when set" do
|
171
|
+
@config.hostname.should == 'environment.host'
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should handle the 'port' property when set" do
|
175
|
+
@config.port.should == 5432
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should handle the 'path' property when set" do
|
179
|
+
@config.path.should == '/solr/env'
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe Sunspot::Rails::Configuration, "with ENV['WEBSOLR_URL'] overriding sunspot.yml" do
|
184
|
+
before(:all) do
|
185
|
+
ENV['WEBSOLR_URL'] = 'http://index.websolr.test/solr/a1b2c3d4e5f'
|
186
|
+
end
|
187
|
+
|
188
|
+
before(:each) do
|
189
|
+
::Rails.stub!(:env => 'config_test')
|
190
|
+
@config = Sunspot::Rails::Configuration.new
|
191
|
+
end
|
192
|
+
|
193
|
+
after(:all) do
|
194
|
+
ENV.delete('WEBSOLR_URL')
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should handle the 'hostname' property when set" do
|
198
|
+
@config.hostname.should == 'index.websolr.test'
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should handle the 'port' property when set" do
|
202
|
+
@config.port.should == 80
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should handle the 'path' property when set" do
|
206
|
+
@config.path.should == '/solr/a1b2c3d4e5f'
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe 'searchable with lifecycle' do
|
4
|
+
describe 'on create' do
|
5
|
+
before :each do
|
6
|
+
@post = PostWithAuto.create
|
7
|
+
Sunspot.commit
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should automatically index' do
|
11
|
+
PostWithAuto.search.results.should == [@post]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'on update' do
|
16
|
+
before :each do
|
17
|
+
@post = PostWithAuto.create
|
18
|
+
@post.update_attributes(:title => 'Test 1')
|
19
|
+
Sunspot.commit
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should automatically update index' do
|
23
|
+
PostWithAuto.search { with :title, 'Test 1' }.results.should == [@post]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should index model if relevant attribute changed" do
|
27
|
+
@post = PostWithAuto.create!
|
28
|
+
@post.title = 'new title'
|
29
|
+
@post.should_receive :solr_index
|
30
|
+
@post.save!
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should not index model if relevant attribute not changed" do
|
34
|
+
@post = PostWithAuto.create!
|
35
|
+
@post.updated_at = Date.tomorrow
|
36
|
+
@post.should_not_receive :solr_index
|
37
|
+
@post.save!
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'on destroy' do
|
42
|
+
before :each do
|
43
|
+
@post = PostWithAuto.create
|
44
|
+
@post.destroy
|
45
|
+
Sunspot.commit
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should automatically remove it from the index' do
|
49
|
+
PostWithAuto.search_ids.should be_empty
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'searchable with lifecycle - ignoring specific attributes' do
|
55
|
+
before(:each) do
|
56
|
+
@post = PostWithAuto.create
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should not reindex the object on an update_at change, because it is marked as to-ignore" do
|
60
|
+
Sunspot.should_not_receive(:index).with(@post)
|
61
|
+
@post.update_attribute :updated_at, 123.seconds.from_now
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,601 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe 'ActiveRecord mixin' do
|
4
|
+
describe 'index()' do
|
5
|
+
before :each do
|
6
|
+
@post = Post.create!
|
7
|
+
@post.index
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should not commit the model' do
|
11
|
+
Post.search.results.should be_empty
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should index the model' do
|
15
|
+
Sunspot.commit
|
16
|
+
Post.search.results.should == [@post]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not blow up if there's a default scope specifying order" do
|
20
|
+
posts = Array.new(2) { |j| PostWithDefaultScope.create! :title => (10-j).to_s }
|
21
|
+
lambda { PostWithDefaultScope.index(:batch_size => 1) }.should_not raise_error
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'single table inheritence' do
|
26
|
+
before :each do
|
27
|
+
@post = PhotoPost.create!
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should not break auto-indexing' do
|
31
|
+
@post.title = 'Title'
|
32
|
+
lambda { @post.save! }.should_not raise_error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'index!()' do
|
37
|
+
before :each do
|
38
|
+
@post = Post.create!
|
39
|
+
@post.index!
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should immediately index and commit' do
|
43
|
+
Post.search.results.should == [@post]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'remove_from_index()' do
|
48
|
+
before :each do
|
49
|
+
@post = Post.create!
|
50
|
+
@post.index!
|
51
|
+
@post.remove_from_index
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should not commit immediately' do
|
55
|
+
Post.search.results.should == [@post]
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should remove the model from the index' do
|
59
|
+
Sunspot.commit
|
60
|
+
Post.search.results.should be_empty
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'remove_from_index!()' do
|
65
|
+
before :each do
|
66
|
+
@post = Post.create!
|
67
|
+
@post.index!
|
68
|
+
@post.remove_from_index!
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should immediately remove the model and commit' do
|
72
|
+
Post.search.results.should be_empty
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'remove_all_from_index' do
|
77
|
+
before :each do
|
78
|
+
@posts = Array.new(2) { Post.create! }.each { |post| Sunspot.index(post) }
|
79
|
+
Sunspot.commit
|
80
|
+
Post.remove_all_from_index
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should not commit immediately' do
|
84
|
+
Post.search.results.to_set.should == @posts.to_set
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should remove all instances from the index' do
|
88
|
+
Sunspot.commit
|
89
|
+
Post.search.results.should be_empty
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'remove_all_from_index!' do
|
94
|
+
before :each do
|
95
|
+
Array.new(2) { Post.create! }.each { |post| Sunspot.index(post) }
|
96
|
+
Sunspot.commit
|
97
|
+
Post.remove_all_from_index!
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should remove all instances from the index and commit immediately' do
|
101
|
+
Post.search.results.should be_empty
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'search()' do
|
106
|
+
before :each do
|
107
|
+
@post = Post.create!(:title => 'Test Post')
|
108
|
+
@post.index!
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should return results specified by search' do
|
112
|
+
Post.search do
|
113
|
+
with :title, 'Test Post'
|
114
|
+
end.results.should == [@post]
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should not return results excluded by search' do
|
118
|
+
Post.search do
|
119
|
+
with :title, 'Bogus Post'
|
120
|
+
end.results.should be_empty
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should use the include option on the data accessor when specified' do
|
124
|
+
Post.should_receive(:all).with(hash_including(:include => [:blog])).and_return([@post])
|
125
|
+
Post.search do
|
126
|
+
with :title, 'Test Post'
|
127
|
+
data_accessor_for(Post).include = [:blog]
|
128
|
+
end.results.should == [@post]
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should pass :include option from search call to data accessor' do
|
132
|
+
Post.should_receive(:all).with(hash_including(:include => [:blog])).and_return([@post])
|
133
|
+
Post.search(:include => [:blog]) do
|
134
|
+
with :title, 'Test Post'
|
135
|
+
end.results.should == [@post]
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should use the select option from search call to data accessor' do
|
139
|
+
Post.should_receive(:all).with(hash_including(:select => 'title, published_at')).and_return([@post])
|
140
|
+
Post.search(:select => 'title, published_at') do
|
141
|
+
with :title, 'Test Post'
|
142
|
+
end.results.should == [@post]
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should not allow bogus options to search' do
|
146
|
+
lambda { Post.search(:bogus => :option) }.should raise_error(ArgumentError)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should use the select option on the data accessor when specified' do
|
150
|
+
Post.should_receive(:all).with(hash_including(:select => 'title, published_at')).and_return([@post])
|
151
|
+
Post.search do
|
152
|
+
with :title, 'Test Post'
|
153
|
+
data_accessor_for(Post).select = [:title, :published_at]
|
154
|
+
end.results.should == [@post]
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should not use the select option on the data accessor when not specified' do
|
158
|
+
Post.should_receive(:all).with(hash_not_including(:select)).and_return([@post])
|
159
|
+
Post.search do
|
160
|
+
with :title, 'Test Post'
|
161
|
+
end.results.should == [@post]
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should gracefully handle nonexistent records' do
|
165
|
+
post2 = Post.create!(:title => 'Test Post')
|
166
|
+
post2.index!
|
167
|
+
post2.destroy
|
168
|
+
Post.search do
|
169
|
+
with :title, 'Test Post'
|
170
|
+
end.results.should == [@post]
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'should use an ActiveRecord object for coordinates' do
|
174
|
+
post = Post.new(:title => 'Test Post')
|
175
|
+
post.location = Location.create!(:lat => 40.0, :lng => -70.0)
|
176
|
+
post.save
|
177
|
+
post.index!
|
178
|
+
Post.search { with(:location).near(40.0, -70.0) }.results.should == [post]
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
describe 'search_ids()' do
|
184
|
+
before :each do
|
185
|
+
@posts = Array.new(2) { Post.create! }.each { |post| post.index }
|
186
|
+
Sunspot.commit
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'should return IDs' do
|
190
|
+
Post.search_ids.to_set.should == @posts.map { |post| post.id }.to_set
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe 'searchable?()' do
|
195
|
+
it 'should not be true for models that have not been configured for search' do
|
196
|
+
Location.should_not be_searchable
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should be true for models that have been configured for search' do
|
200
|
+
Post.should be_searchable
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe 'index_orphans()' do
|
205
|
+
before :each do
|
206
|
+
@posts = Array.new(2) { Post.create }.each { |post| post.index }
|
207
|
+
Sunspot.commit
|
208
|
+
@posts.first.destroy
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'should return IDs of objects that are in the index but not the database' do
|
212
|
+
Post.index_orphans.should == [@posts.first.id]
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should find the orphans in batches to improve performance' do
|
216
|
+
Post.should_receive(:find_each).with(hash_including(:batch_size => 10)).and_return([])
|
217
|
+
Post.index_orphans(:batch_size => 10)
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
describe 'clean_index_orphans()' do
|
223
|
+
before :each do
|
224
|
+
@posts = Array.new(2) { Post.create }.each { |post| post.index }
|
225
|
+
Sunspot.commit
|
226
|
+
@posts.first.destroy
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should remove orphans from the index' do
|
230
|
+
Post.clean_index_orphans
|
231
|
+
Sunspot.commit
|
232
|
+
Post.search.results.should == [@posts.last]
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe 'reindex()' do
|
237
|
+
before :each do
|
238
|
+
@posts = Array.new(2) { Post.create }
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'should index all instances' do
|
242
|
+
Post.reindex(:batch_size => nil)
|
243
|
+
Sunspot.commit
|
244
|
+
Post.search.results.to_set.should == @posts.to_set
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'should remove all currently indexed instances' do
|
248
|
+
old_post = Post.create!
|
249
|
+
old_post.index!
|
250
|
+
old_post.destroy
|
251
|
+
Post.reindex
|
252
|
+
Sunspot.commit
|
253
|
+
Post.search.results.to_set.should == @posts.to_set
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
describe 'reindex() with real data' do
|
259
|
+
before :each do
|
260
|
+
@posts = Array.new(2) { Post.create }
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'should index all instances' do
|
264
|
+
Post.reindex(:batch_size => nil)
|
265
|
+
Sunspot.commit
|
266
|
+
Post.search.results.to_set.should == @posts.to_set
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'should remove all currently indexed instances' do
|
270
|
+
old_post = Post.create!
|
271
|
+
old_post.index!
|
272
|
+
old_post.destroy
|
273
|
+
Post.reindex
|
274
|
+
Sunspot.commit
|
275
|
+
Post.search.results.to_set.should == @posts.to_set
|
276
|
+
end
|
277
|
+
|
278
|
+
describe "using batch sizes" do
|
279
|
+
it 'should index with a specified batch size' do
|
280
|
+
Post.reindex(:batch_size => 1)
|
281
|
+
Sunspot.commit
|
282
|
+
Post.search.results.to_set.should == @posts.to_set
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
describe "reindex()" do
|
290
|
+
|
291
|
+
before(:each) do
|
292
|
+
@posts = Array.new(2) { Post.create }
|
293
|
+
end
|
294
|
+
|
295
|
+
describe "when not using batches" do
|
296
|
+
|
297
|
+
it "should select all if the batch_size is nil" do
|
298
|
+
Post.should_receive(:all).with(:include => []).and_return([])
|
299
|
+
Post.reindex(:batch_size => nil)
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should search for models with includes" do
|
303
|
+
Post.should_receive(:all).with(:include => :author).and_return([])
|
304
|
+
Post.reindex(:batch_size => nil, :include => :author)
|
305
|
+
end
|
306
|
+
|
307
|
+
describe ':if constraints' do
|
308
|
+
before do
|
309
|
+
Post.sunspot_options[:if] = proc { |model| model.id != @posts.first.id }
|
310
|
+
end
|
311
|
+
|
312
|
+
after do
|
313
|
+
Post.sunspot_options[:if] = nil
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'should only index those models where :if constraints pass' do
|
317
|
+
Post.reindex(:batch_size => nil)
|
318
|
+
|
319
|
+
Post.search.results.should_not include(@posts.first)
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
end
|
324
|
+
|
325
|
+
describe "when using batches" do
|
326
|
+
it "should commit after indexing each batch" do
|
327
|
+
Sunspot.should_receive(:commit).twice
|
328
|
+
Post.reindex(:batch_size => 1)
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should commit after indexing everything" do
|
332
|
+
Sunspot.should_receive(:commit).once
|
333
|
+
Post.reindex(:batch_commit => false)
|
334
|
+
end
|
335
|
+
|
336
|
+
describe ':if constraints' do
|
337
|
+
before do
|
338
|
+
Post.sunspot_options[:if] = proc { |model| model.id != @posts.first.id }
|
339
|
+
end
|
340
|
+
|
341
|
+
after do
|
342
|
+
Post.sunspot_options[:if] = nil
|
343
|
+
end
|
344
|
+
|
345
|
+
it 'should only index those models where :if constraints pass' do
|
346
|
+
Post.reindex(:batch_size => 50)
|
347
|
+
|
348
|
+
Post.search.results.should_not include(@posts.first)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
describe "more_like_this()" do
|
355
|
+
before(:each) do
|
356
|
+
@posts = [
|
357
|
+
Post.create!(:title => 'Post123', :body => "one two three"),
|
358
|
+
Post.create!(:title => 'Post345', :body => "three four five"),
|
359
|
+
Post.create!(:title => 'Post456', :body => "four five six"),
|
360
|
+
Post.create!(:title => 'Post234', :body => "two three four"),
|
361
|
+
]
|
362
|
+
@posts_with_auto = [
|
363
|
+
PostWithAuto.create!(:body => "one two three"),
|
364
|
+
PostWithAuto.create!(:body => "four five six")
|
365
|
+
]
|
366
|
+
@posts.each { |p| p.index! }
|
367
|
+
end
|
368
|
+
|
369
|
+
it "should return results" do
|
370
|
+
@posts.first.more_like_this.results.should == [@posts[3], @posts[1]]
|
371
|
+
end
|
372
|
+
|
373
|
+
it "should return results for specified classes" do
|
374
|
+
@posts.first.more_like_this(Post, PostWithAuto).results.to_set.should ==
|
375
|
+
Set[@posts_with_auto[0], @posts[1], @posts[3]]
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
describe 'more_like_this_ids()' do
|
380
|
+
before :each do
|
381
|
+
@posts = [
|
382
|
+
Post.create!(:title => 'Post123', :body => "one two three"),
|
383
|
+
Post.create!(:title => 'Post345', :body => "three four five"),
|
384
|
+
Post.create!(:title => 'Post456', :body => "four five six"),
|
385
|
+
Post.create!(:title => 'Post234', :body => "two three four"),
|
386
|
+
]
|
387
|
+
@posts.each { |p| p.index! }
|
388
|
+
end
|
389
|
+
|
390
|
+
it 'should return IDs' do
|
391
|
+
@posts.first.more_like_this_ids.to_set.should == [@posts[3], @posts[1]].map { |post| post.id }.to_set
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
describe ':if constraint' do
|
396
|
+
subject do
|
397
|
+
PostWithAuto.new(:title => 'Post123')
|
398
|
+
end
|
399
|
+
|
400
|
+
after do
|
401
|
+
subject.class.sunspot_options[:if] = nil
|
402
|
+
end
|
403
|
+
|
404
|
+
context 'Symbol' do
|
405
|
+
context 'constraint returns true' do
|
406
|
+
# searchable :if => :returns_true
|
407
|
+
before do
|
408
|
+
subject.should_receive(:returns_true).and_return(true)
|
409
|
+
subject.class.sunspot_options[:if] = :returns_true
|
410
|
+
end
|
411
|
+
|
412
|
+
it_should_behave_like 'indexed after save'
|
413
|
+
end
|
414
|
+
|
415
|
+
context 'constraint returns false' do
|
416
|
+
# searchable :if => :returns_false
|
417
|
+
before do
|
418
|
+
subject.should_receive(:returns_false).and_return(false)
|
419
|
+
subject.class.sunspot_options[:if] = :returns_false
|
420
|
+
end
|
421
|
+
|
422
|
+
it_should_behave_like 'not indexed after save'
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
context 'String' do
|
427
|
+
context 'constraint returns true' do
|
428
|
+
# searchable :if => 'returns_true'
|
429
|
+
before do
|
430
|
+
subject.should_receive(:returns_true).and_return(true)
|
431
|
+
subject.class.sunspot_options[:if] = 'returns_true'
|
432
|
+
end
|
433
|
+
|
434
|
+
it_should_behave_like 'indexed after save'
|
435
|
+
end
|
436
|
+
|
437
|
+
context 'constraint returns false' do
|
438
|
+
# searchable :if => 'returns_false'
|
439
|
+
before do
|
440
|
+
subject.should_receive(:returns_false).and_return(false)
|
441
|
+
subject.class.sunspot_options[:if] = 'returns_false'
|
442
|
+
end
|
443
|
+
|
444
|
+
it_should_behave_like 'not indexed after save'
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
context 'Proc' do
|
449
|
+
context 'constraint returns true' do
|
450
|
+
# searchable :if => proc { true }
|
451
|
+
before do
|
452
|
+
subject.class.sunspot_options[:if] = proc { true }
|
453
|
+
end
|
454
|
+
|
455
|
+
it_should_behave_like 'indexed after save'
|
456
|
+
end
|
457
|
+
|
458
|
+
context 'constraint returns false' do
|
459
|
+
# searchable :if => proc { false }
|
460
|
+
before do
|
461
|
+
subject.class.sunspot_options[:if] = proc { false }
|
462
|
+
end
|
463
|
+
|
464
|
+
it_should_behave_like 'not indexed after save'
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
context 'Array' do
|
469
|
+
context 'all constraints returns true' do
|
470
|
+
# searchable :if => [:returns_true_1, :returns_true_2]
|
471
|
+
before do
|
472
|
+
subject.should_receive(:returns_true_1).and_return(true)
|
473
|
+
subject.should_receive(:returns_true_2).and_return(true)
|
474
|
+
subject.class.sunspot_options[:if] = [:returns_true_1, 'returns_true_2']
|
475
|
+
end
|
476
|
+
|
477
|
+
it_should_behave_like 'indexed after save'
|
478
|
+
end
|
479
|
+
|
480
|
+
context 'one constraint returns false' do
|
481
|
+
# searchable :if => [:returns_true, :returns_false]
|
482
|
+
before do
|
483
|
+
subject.should_receive(:returns_true).and_return(true)
|
484
|
+
subject.should_receive(:returns_false).and_return(false)
|
485
|
+
subject.class.sunspot_options[:if] = [:returns_true, 'returns_false']
|
486
|
+
end
|
487
|
+
|
488
|
+
it_should_behave_like 'not indexed after save'
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
it 'removes the model from the index if the constraint does not match' do
|
493
|
+
subject.save!
|
494
|
+
Sunspot.commit
|
495
|
+
subject.class.search.results.should include(subject)
|
496
|
+
|
497
|
+
subject.class.sunspot_options[:if] = proc { false }
|
498
|
+
subject.save!
|
499
|
+
Sunspot.commit
|
500
|
+
subject.class.search.results.should_not include(subject)
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
describe ':unless constraint' do
|
505
|
+
subject do
|
506
|
+
PostWithAuto.new(:title => 'Post123')
|
507
|
+
end
|
508
|
+
|
509
|
+
after do
|
510
|
+
subject.class.sunspot_options[:unless] = nil
|
511
|
+
end
|
512
|
+
|
513
|
+
context 'Symbol' do
|
514
|
+
context 'constraint returns true' do
|
515
|
+
# searchable :unless => :returns_true
|
516
|
+
before do
|
517
|
+
subject.should_receive(:returns_true).and_return(true)
|
518
|
+
subject.class.sunspot_options[:unless] = :returns_true
|
519
|
+
end
|
520
|
+
|
521
|
+
it_should_behave_like 'not indexed after save'
|
522
|
+
end
|
523
|
+
|
524
|
+
context 'constraint returns false' do
|
525
|
+
# searchable :unless => :returns_false
|
526
|
+
before do
|
527
|
+
subject.should_receive(:returns_false).and_return(false)
|
528
|
+
subject.class.sunspot_options[:unless] = :returns_false
|
529
|
+
end
|
530
|
+
|
531
|
+
it_should_behave_like 'indexed after save'
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
535
|
+
context 'String' do
|
536
|
+
context 'constraint returns true' do
|
537
|
+
# searchable :unless => 'returns_true'
|
538
|
+
before do
|
539
|
+
subject.should_receive(:returns_true).and_return(true)
|
540
|
+
subject.class.sunspot_options[:unless] = 'returns_true'
|
541
|
+
end
|
542
|
+
|
543
|
+
it_should_behave_like 'not indexed after save'
|
544
|
+
end
|
545
|
+
|
546
|
+
context 'constraint returns false' do
|
547
|
+
# searchable :unless => 'returns_false'
|
548
|
+
before do
|
549
|
+
subject.should_receive(:returns_false).and_return(false)
|
550
|
+
subject.class.sunspot_options[:unless] = 'returns_false'
|
551
|
+
end
|
552
|
+
|
553
|
+
it_should_behave_like 'indexed after save'
|
554
|
+
end
|
555
|
+
end
|
556
|
+
|
557
|
+
context 'Proc' do
|
558
|
+
context 'constraint returns true' do
|
559
|
+
# searchable :unless => proc { true }
|
560
|
+
before do
|
561
|
+
subject.class.sunspot_options[:unless] = proc { |model| model == subject } # true
|
562
|
+
end
|
563
|
+
|
564
|
+
it_should_behave_like 'not indexed after save'
|
565
|
+
end
|
566
|
+
|
567
|
+
context 'constraint returns false' do
|
568
|
+
# searchable :unless => proc { false }
|
569
|
+
before do
|
570
|
+
subject.class.sunspot_options[:unless] = proc { false }
|
571
|
+
end
|
572
|
+
|
573
|
+
it_should_behave_like 'indexed after save'
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
577
|
+
context 'Array' do
|
578
|
+
context 'all constraints returns true' do
|
579
|
+
# searchable :unless => [:returns_true_1, :returns_true_2]
|
580
|
+
before do
|
581
|
+
subject.should_receive(:returns_true_1).and_return(true)
|
582
|
+
subject.should_receive(:returns_true_2).and_return(true)
|
583
|
+
subject.class.sunspot_options[:unless] = [:returns_true_1, 'returns_true_2']
|
584
|
+
end
|
585
|
+
|
586
|
+
it_should_behave_like 'not indexed after save'
|
587
|
+
end
|
588
|
+
|
589
|
+
context 'one constraint returns false' do
|
590
|
+
# searchable :unless => [:returns_true, :returns_false]
|
591
|
+
before do
|
592
|
+
subject.should_receive(:returns_true).and_return(true)
|
593
|
+
subject.should_receive(:returns_false).and_return(false)
|
594
|
+
subject.class.sunspot_options[:unless] = [:returns_true, 'returns_false']
|
595
|
+
end
|
596
|
+
|
597
|
+
it_should_behave_like 'indexed after save'
|
598
|
+
end
|
599
|
+
end
|
600
|
+
end
|
601
|
+
end
|