sunspot_rails 2.0.0.pre.120924 → 2.0.0.pre.120925
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -10
- data/{sunspot_rails/.rspec → .rspec} +0 -0
- data/{sunspot_rails/History.txt → History.txt} +0 -0
- data/{sunspot/LICENSE → LICENSE} +0 -0
- data/{sunspot_rails/MIT-LICENSE → MIT-LICENSE} +0 -0
- data/{sunspot_rails/README.rdoc → README.rdoc} +0 -0
- data/Rakefile +12 -32
- data/{sunspot_rails/TODO → TODO} +0 -0
- data/{sunspot_rails/dev_tasks → dev_tasks}/rdoc.rake +0 -0
- data/{sunspot_rails/dev_tasks → dev_tasks}/release.rake +0 -0
- data/{sunspot_rails/dev_tasks → dev_tasks}/spec.rake +0 -0
- data/{sunspot/tasks → dev_tasks}/todo.rake +0 -0
- data/{sunspot_rails/gemfiles → gemfiles}/rails-2.3.14 +0 -0
- data/{sunspot_rails/gemfiles → gemfiles}/rails-3.0.15 +0 -0
- data/{sunspot_rails/gemfiles → gemfiles}/rails-3.1.6 +0 -0
- data/{sunspot_rails/gemfiles → gemfiles}/rails-3.2.6 +0 -0
- data/{sunspot_rails/generators → generators}/sunspot/sunspot_generator.rb +0 -0
- data/{sunspot_rails/generators → generators}/sunspot/templates/sunspot.yml +0 -0
- data/{sunspot_rails/install.rb → install.rb} +0 -0
- data/{sunspot_rails/lib → lib}/generators/sunspot_rails.rb +0 -0
- data/{sunspot_rails/lib → lib}/generators/sunspot_rails/install/install_generator.rb +0 -0
- data/{sunspot_rails/lib → lib}/generators/sunspot_rails/install/templates/config/sunspot.yml +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/adapters.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/configuration.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/init.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/log_subscriber.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/railtie.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/railties/controller_runtime.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/request_lifecycle.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/searchable.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/server.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/solr_instrumentation.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/solr_logging.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/spec_helper.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/stub_session_proxy.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/tasks.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot_rails.rb +0 -0
- data/{sunspot_rails/spec → spec}/configuration_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/model_lifecycle_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/model_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/controllers/application_controller.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/controllers/posts_controller.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/author.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/blog.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/location.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/photo_post.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/post.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/post_with_auto.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/post_with_default_scope.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/config/boot.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/config/preinitializer.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/config/routes.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/config/sunspot.yml +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/db/schema.rb +0 -0
- data/{sunspot_rails/spec → spec}/request_lifecycle_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/schema.rb +0 -0
- data/{sunspot_rails/spec → spec}/searchable_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/server_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/session_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/shared_examples/indexed_after_save.rb +0 -0
- data/{sunspot_rails/spec → spec}/shared_examples/not_indexed_after_save.rb +0 -0
- data/{sunspot_rails/spec → spec}/spec_helper.rb +0 -0
- data/{sunspot_rails/spec → spec}/stub_session_proxy_spec.rb +0 -0
- data/{sunspot_rails/sunspot_rails.gemspec → sunspot_rails.gemspec} +0 -0
- metadata +102 -305
- data/.travis.yml +0 -35
- data/README.md +0 -863
- data/ci/travis.sh +0 -67
- data/sunspot/.gitignore +0 -13
- data/sunspot/Gemfile +0 -5
- data/sunspot/History.txt +0 -258
- data/sunspot/Rakefile +0 -13
- data/sunspot/TODO +0 -13
- data/sunspot/lib/light_config.rb +0 -40
- data/sunspot/lib/sunspot.rb +0 -579
- data/sunspot/lib/sunspot/adapters.rb +0 -349
- data/sunspot/lib/sunspot/batcher.rb +0 -62
- data/sunspot/lib/sunspot/class_set.rb +0 -23
- data/sunspot/lib/sunspot/composite_setup.rb +0 -202
- data/sunspot/lib/sunspot/configuration.rb +0 -53
- data/sunspot/lib/sunspot/data_extractor.rb +0 -50
- data/sunspot/lib/sunspot/dsl.rb +0 -5
- data/sunspot/lib/sunspot/dsl/adjustable.rb +0 -47
- data/sunspot/lib/sunspot/dsl/field_group.rb +0 -57
- data/sunspot/lib/sunspot/dsl/field_query.rb +0 -345
- data/sunspot/lib/sunspot/dsl/fields.rb +0 -103
- data/sunspot/lib/sunspot/dsl/fulltext.rb +0 -243
- data/sunspot/lib/sunspot/dsl/function.rb +0 -27
- data/sunspot/lib/sunspot/dsl/functional.rb +0 -44
- data/sunspot/lib/sunspot/dsl/more_like_this_query.rb +0 -56
- data/sunspot/lib/sunspot/dsl/paginatable.rb +0 -32
- data/sunspot/lib/sunspot/dsl/query_facet.rb +0 -36
- data/sunspot/lib/sunspot/dsl/restriction.rb +0 -25
- data/sunspot/lib/sunspot/dsl/restriction_with_near.rb +0 -160
- data/sunspot/lib/sunspot/dsl/scope.rb +0 -214
- data/sunspot/lib/sunspot/dsl/search.rb +0 -30
- data/sunspot/lib/sunspot/dsl/standard_query.rb +0 -122
- data/sunspot/lib/sunspot/field.rb +0 -193
- data/sunspot/lib/sunspot/field_factory.rb +0 -129
- data/sunspot/lib/sunspot/indexer.rb +0 -136
- data/sunspot/lib/sunspot/query.rb +0 -11
- data/sunspot/lib/sunspot/query/abstract_field_facet.rb +0 -55
- data/sunspot/lib/sunspot/query/bbox.rb +0 -15
- data/sunspot/lib/sunspot/query/boost_query.rb +0 -24
- data/sunspot/lib/sunspot/query/common_query.rb +0 -96
- data/sunspot/lib/sunspot/query/composite_fulltext.rb +0 -36
- data/sunspot/lib/sunspot/query/connective.rb +0 -206
- data/sunspot/lib/sunspot/query/date_field_facet.rb +0 -14
- data/sunspot/lib/sunspot/query/dismax.rb +0 -132
- data/sunspot/lib/sunspot/query/field_facet.rb +0 -41
- data/sunspot/lib/sunspot/query/field_group.rb +0 -37
- data/sunspot/lib/sunspot/query/filter.rb +0 -38
- data/sunspot/lib/sunspot/query/function_query.rb +0 -52
- data/sunspot/lib/sunspot/query/geo.rb +0 -53
- data/sunspot/lib/sunspot/query/geofilt.rb +0 -16
- data/sunspot/lib/sunspot/query/highlighting.rb +0 -62
- data/sunspot/lib/sunspot/query/more_like_this.rb +0 -61
- data/sunspot/lib/sunspot/query/more_like_this_query.rb +0 -12
- data/sunspot/lib/sunspot/query/pagination.rb +0 -42
- data/sunspot/lib/sunspot/query/query_facet.rb +0 -53
- data/sunspot/lib/sunspot/query/range_facet.rb +0 -15
- data/sunspot/lib/sunspot/query/restriction.rb +0 -308
- data/sunspot/lib/sunspot/query/scope.rb +0 -9
- data/sunspot/lib/sunspot/query/sort.rb +0 -109
- data/sunspot/lib/sunspot/query/sort_composite.rb +0 -34
- data/sunspot/lib/sunspot/query/standard_query.rb +0 -16
- data/sunspot/lib/sunspot/query/text_field_boost.rb +0 -17
- data/sunspot/lib/sunspot/schema.rb +0 -151
- data/sunspot/lib/sunspot/search.rb +0 -9
- data/sunspot/lib/sunspot/search/abstract_search.rb +0 -286
- data/sunspot/lib/sunspot/search/date_facet.rb +0 -35
- data/sunspot/lib/sunspot/search/facet_row.rb +0 -27
- data/sunspot/lib/sunspot/search/field_facet.rb +0 -88
- data/sunspot/lib/sunspot/search/field_group.rb +0 -70
- data/sunspot/lib/sunspot/search/group.rb +0 -54
- data/sunspot/lib/sunspot/search/highlight.rb +0 -38
- data/sunspot/lib/sunspot/search/hit.rb +0 -150
- data/sunspot/lib/sunspot/search/hit_enumerable.rb +0 -68
- data/sunspot/lib/sunspot/search/more_like_this_search.rb +0 -31
- data/sunspot/lib/sunspot/search/paginated_collection.rb +0 -57
- data/sunspot/lib/sunspot/search/query_facet.rb +0 -67
- data/sunspot/lib/sunspot/search/range_facet.rb +0 -37
- data/sunspot/lib/sunspot/search/standard_search.rb +0 -21
- data/sunspot/lib/sunspot/session.rb +0 -262
- data/sunspot/lib/sunspot/session_proxy.rb +0 -95
- data/sunspot/lib/sunspot/session_proxy/abstract_session_proxy.rb +0 -29
- data/sunspot/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +0 -66
- data/sunspot/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +0 -89
- data/sunspot/lib/sunspot/session_proxy/master_slave_session_proxy.rb +0 -43
- data/sunspot/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb +0 -67
- data/sunspot/lib/sunspot/session_proxy/sharding_session_proxy.rb +0 -222
- data/sunspot/lib/sunspot/session_proxy/silent_fail_session_proxy.rb +0 -42
- data/sunspot/lib/sunspot/session_proxy/thread_local_session_proxy.rb +0 -37
- data/sunspot/lib/sunspot/setup.rb +0 -350
- data/sunspot/lib/sunspot/text_field_setup.rb +0 -29
- data/sunspot/lib/sunspot/type.rb +0 -393
- data/sunspot/lib/sunspot/util.rb +0 -252
- data/sunspot/lib/sunspot/version.rb +0 -3
- data/sunspot/script/console +0 -10
- data/sunspot/spec/api/adapters_spec.rb +0 -68
- data/sunspot/spec/api/batcher_spec.rb +0 -112
- data/sunspot/spec/api/binding_spec.rb +0 -50
- data/sunspot/spec/api/class_set_spec.rb +0 -24
- data/sunspot/spec/api/hit_enumerable_spec.rb +0 -47
- data/sunspot/spec/api/indexer/attributes_spec.rb +0 -149
- data/sunspot/spec/api/indexer/batch_spec.rb +0 -72
- data/sunspot/spec/api/indexer/dynamic_fields_spec.rb +0 -42
- data/sunspot/spec/api/indexer/fixed_fields_spec.rb +0 -57
- data/sunspot/spec/api/indexer/fulltext_spec.rb +0 -43
- data/sunspot/spec/api/indexer/removal_spec.rb +0 -53
- data/sunspot/spec/api/indexer/spec_helper.rb +0 -1
- data/sunspot/spec/api/indexer_spec.rb +0 -14
- data/sunspot/spec/api/query/advanced_manipulation_examples.rb +0 -35
- data/sunspot/spec/api/query/connectives_examples.rb +0 -201
- data/sunspot/spec/api/query/dsl_spec.rb +0 -18
- data/sunspot/spec/api/query/dynamic_fields_examples.rb +0 -165
- data/sunspot/spec/api/query/faceting_examples.rb +0 -497
- data/sunspot/spec/api/query/fulltext_examples.rb +0 -313
- data/sunspot/spec/api/query/function_spec.rb +0 -79
- data/sunspot/spec/api/query/geo_examples.rb +0 -68
- data/sunspot/spec/api/query/group_spec.rb +0 -32
- data/sunspot/spec/api/query/highlighting_examples.rb +0 -245
- data/sunspot/spec/api/query/more_like_this_spec.rb +0 -140
- data/sunspot/spec/api/query/ordering_pagination_examples.rb +0 -116
- data/sunspot/spec/api/query/scope_examples.rb +0 -275
- data/sunspot/spec/api/query/spatial_examples.rb +0 -27
- data/sunspot/spec/api/query/spec_helper.rb +0 -1
- data/sunspot/spec/api/query/standard_spec.rb +0 -29
- data/sunspot/spec/api/query/text_field_scoping_examples.rb +0 -30
- data/sunspot/spec/api/query/types_spec.rb +0 -20
- data/sunspot/spec/api/search/dynamic_fields_spec.rb +0 -33
- data/sunspot/spec/api/search/faceting_spec.rb +0 -360
- data/sunspot/spec/api/search/highlighting_spec.rb +0 -69
- data/sunspot/spec/api/search/hits_spec.rb +0 -147
- data/sunspot/spec/api/search/paginated_collection_spec.rb +0 -36
- data/sunspot/spec/api/search/results_spec.rb +0 -72
- data/sunspot/spec/api/search/search_spec.rb +0 -23
- data/sunspot/spec/api/search/spec_helper.rb +0 -1
- data/sunspot/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +0 -85
- data/sunspot/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +0 -30
- data/sunspot/spec/api/session_proxy/master_slave_session_proxy_spec.rb +0 -41
- data/sunspot/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +0 -78
- data/sunspot/spec/api/session_proxy/sharding_session_proxy_spec.rb +0 -77
- data/sunspot/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +0 -24
- data/sunspot/spec/api/session_proxy/spec_helper.rb +0 -9
- data/sunspot/spec/api/session_proxy/thread_local_session_proxy_spec.rb +0 -39
- data/sunspot/spec/api/session_spec.rb +0 -232
- data/sunspot/spec/api/spec_helper.rb +0 -3
- data/sunspot/spec/api/sunspot_spec.rb +0 -29
- data/sunspot/spec/ext.rb +0 -11
- data/sunspot/spec/helpers/indexer_helper.rb +0 -17
- data/sunspot/spec/helpers/integration_helper.rb +0 -8
- data/sunspot/spec/helpers/mock_session_helper.rb +0 -13
- data/sunspot/spec/helpers/query_helper.rb +0 -26
- data/sunspot/spec/helpers/search_helper.rb +0 -68
- data/sunspot/spec/integration/dynamic_fields_spec.rb +0 -57
- data/sunspot/spec/integration/faceting_spec.rb +0 -330
- data/sunspot/spec/integration/field_grouping_spec.rb +0 -100
- data/sunspot/spec/integration/geospatial_spec.rb +0 -96
- data/sunspot/spec/integration/highlighting_spec.rb +0 -44
- data/sunspot/spec/integration/indexing_spec.rb +0 -55
- data/sunspot/spec/integration/keyword_search_spec.rb +0 -317
- data/sunspot/spec/integration/local_search_spec.rb +0 -64
- data/sunspot/spec/integration/more_like_this_spec.rb +0 -43
- data/sunspot/spec/integration/scoped_search_spec.rb +0 -386
- data/sunspot/spec/integration/stored_fields_spec.rb +0 -12
- data/sunspot/spec/integration/test_pagination.rb +0 -43
- data/sunspot/spec/integration/unicode_spec.rb +0 -15
- data/sunspot/spec/mocks/adapters.rb +0 -33
- data/sunspot/spec/mocks/blog.rb +0 -3
- data/sunspot/spec/mocks/comment.rb +0 -21
- data/sunspot/spec/mocks/connection.rb +0 -126
- data/sunspot/spec/mocks/mock_adapter.rb +0 -30
- data/sunspot/spec/mocks/mock_class_sharding_session_proxy.rb +0 -24
- data/sunspot/spec/mocks/mock_record.rb +0 -52
- data/sunspot/spec/mocks/mock_sharding_session_proxy.rb +0 -15
- data/sunspot/spec/mocks/photo.rb +0 -11
- data/sunspot/spec/mocks/post.rb +0 -86
- data/sunspot/spec/mocks/super_class.rb +0 -2
- data/sunspot/spec/mocks/user.rb +0 -13
- data/sunspot/spec/spec_helper.rb +0 -40
- data/sunspot/sunspot.gemspec +0 -37
- data/sunspot/tasks/rdoc.rake +0 -27
- data/sunspot/tasks/schema.rake +0 -19
- data/sunspot_rails/.gitignore +0 -7
- data/sunspot_rails/LICENSE +0 -18
- data/sunspot_rails/Rakefile +0 -17
- data/sunspot_rails/dev_tasks/todo.rake +0 -4
- data/sunspot_solr/Gemfile +0 -3
- data/sunspot_solr/README.rdoc +0 -24
- data/sunspot_solr/bin/sunspot-installer +0 -20
- data/sunspot_solr/bin/sunspot-solr +0 -80
- data/sunspot_solr/lib/sunspot/solr/installer.rb +0 -25
- data/sunspot_solr/lib/sunspot/solr/installer/config_installer.rb +0 -46
- data/sunspot_solr/lib/sunspot/solr/installer/task_helper.rb +0 -13
- data/sunspot_solr/lib/sunspot/solr/java.rb +0 -10
- data/sunspot_solr/lib/sunspot/solr/railtie.rb +0 -15
- data/sunspot_solr/lib/sunspot/solr/server.rb +0 -223
- data/sunspot_solr/lib/sunspot/solr/tasks.rb +0 -49
- data/sunspot_solr/lib/sunspot_solr.rb +0 -5
- data/sunspot_solr/solr/README.txt +0 -42
- data/sunspot_solr/solr/etc/jetty.xml +0 -219
- data/sunspot_solr/solr/etc/webdefault.xml +0 -379
- data/sunspot_solr/solr/lib/jetty-6.1.26-patched-JETTY-1340.jar +0 -0
- data/sunspot_solr/solr/lib/jetty-util-6.1.26-patched-JETTY-1340.jar +0 -0
- data/sunspot_solr/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
- data/sunspot_solr/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
- data/sunspot_solr/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
- data/sunspot_solr/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
- data/sunspot_solr/solr/lib/servlet-api-2.5-20081211.jar +0 -0
- data/sunspot_solr/solr/solr/.gitignore +0 -1
- data/sunspot_solr/solr/solr/README.txt +0 -54
- data/sunspot_solr/solr/solr/conf/admin-extra.html +0 -31
- data/sunspot_solr/solr/solr/conf/elevate.xml +0 -36
- data/sunspot_solr/solr/solr/conf/mapping-ISOLatin1Accent.txt +0 -246
- data/sunspot_solr/solr/solr/conf/protwords.txt +0 -21
- data/sunspot_solr/solr/solr/conf/schema.xml +0 -250
- data/sunspot_solr/solr/solr/conf/scripts.conf +0 -24
- data/sunspot_solr/solr/solr/conf/solrconfig.xml +0 -934
- data/sunspot_solr/solr/solr/conf/spellings.txt +0 -2
- data/sunspot_solr/solr/solr/conf/stopwords.txt +0 -58
- data/sunspot_solr/solr/solr/conf/synonyms.txt +0 -31
- data/sunspot_solr/solr/solr/conf/xslt/example.xsl +0 -132
- data/sunspot_solr/solr/solr/conf/xslt/example_atom.xsl +0 -67
- data/sunspot_solr/solr/solr/conf/xslt/example_rss.xsl +0 -66
- data/sunspot_solr/solr/solr/conf/xslt/luke.xsl +0 -337
- data/sunspot_solr/solr/start.jar +0 -0
- data/sunspot_solr/solr/webapps/solr.war +0 -0
- data/sunspot_solr/spec/server_spec.rb +0 -98
- data/sunspot_solr/spec/spec_helper.rb +0 -18
- data/sunspot_solr/sunspot_solr.gemspec +0 -37
- data/tools/gem_tasks.rb +0 -69
@@ -1,109 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
module Query
|
3
|
-
#
|
4
|
-
# The classes in this module implement query components that build sort
|
5
|
-
# parameters for Solr. As well as regular sort on fields, there are several
|
6
|
-
# "special" sorts that allow ordering for metrics calculated during the
|
7
|
-
# search.
|
8
|
-
#
|
9
|
-
module Sort #:nodoc: all
|
10
|
-
DIRECTIONS = {
|
11
|
-
:asc => 'asc',
|
12
|
-
:ascending => 'asc',
|
13
|
-
:desc => 'desc',
|
14
|
-
:descending => 'desc'
|
15
|
-
}
|
16
|
-
|
17
|
-
class <<self
|
18
|
-
#
|
19
|
-
# Certain field names are "special", referring to specific non-field
|
20
|
-
# sorts, which are generally by other metrics associated with hits.
|
21
|
-
#
|
22
|
-
# XXX I'm not entirely convinced it's a good idea to prevent anyone from
|
23
|
-
# ever sorting by a field named 'score', etc.
|
24
|
-
#
|
25
|
-
def special(name)
|
26
|
-
special_class_name = "#{Util.camel_case(name.to_s)}Sort"
|
27
|
-
if const_defined?(special_class_name) && special_class_name != 'FieldSort'
|
28
|
-
const_get(special_class_name)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
#
|
34
|
-
# Base class for sorts. All subclasses should implement the #to_param
|
35
|
-
# method, which is a string that is then concatenated with other sort
|
36
|
-
# strings by the SortComposite to form the sort parameter.
|
37
|
-
#
|
38
|
-
class Abstract
|
39
|
-
def initialize(direction)
|
40
|
-
@direction = (direction || :asc).to_sym
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
#
|
46
|
-
# Translate fairly forgiving direction argument into solr direction
|
47
|
-
#
|
48
|
-
def direction_for_solr
|
49
|
-
DIRECTIONS[@direction] ||
|
50
|
-
raise(
|
51
|
-
ArgumentError,
|
52
|
-
"Unknown sort direction #{@direction}. Acceptable input is: #{DIRECTIONS.keys.map { |input| input.inspect } * ', '}"
|
53
|
-
)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
#
|
58
|
-
# A FieldSort is the usual kind of sort, by the value of a particular
|
59
|
-
# field, ascending or descending
|
60
|
-
#
|
61
|
-
class FieldSort < Abstract
|
62
|
-
def initialize(field, direction = nil)
|
63
|
-
if field.multiple?
|
64
|
-
raise(ArgumentError, "#{field.name} cannot be used for ordering because it is a multiple-value field")
|
65
|
-
end
|
66
|
-
@field, @direction = field, (direction || :asc).to_sym
|
67
|
-
end
|
68
|
-
|
69
|
-
def to_param
|
70
|
-
"#{@field.indexed_name.to_sym} #{direction_for_solr}"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
#
|
75
|
-
# A RandomSort uses Solr's random field functionality to sort results
|
76
|
-
# (usually) randomly.
|
77
|
-
#
|
78
|
-
class RandomSort < Abstract
|
79
|
-
def to_param
|
80
|
-
"random_#{rand(1<<16)} #{direction_for_solr}"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
#
|
85
|
-
# A ScoreSort sorts by keyword relevance score. This is only useful when
|
86
|
-
# performing fulltext search.
|
87
|
-
#
|
88
|
-
class ScoreSort < Abstract
|
89
|
-
def to_param
|
90
|
-
"score #{direction_for_solr}"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
#
|
95
|
-
# A GeodistSort sorts by distance from a given point.
|
96
|
-
#
|
97
|
-
class GeodistSort < FieldSort
|
98
|
-
def initialize(field, lat, lon, direction)
|
99
|
-
@lat, @lon = lat, lon
|
100
|
-
super(field, direction)
|
101
|
-
end
|
102
|
-
|
103
|
-
def to_param
|
104
|
-
"geodist(#{@field.indexed_name.to_sym},#{@lat},#{@lon}) #{direction_for_solr}"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
module Query
|
3
|
-
#
|
4
|
-
# The SortComposite class encapsulates an ordered collection of Sort
|
5
|
-
# objects. It's necessary to keep this as a separate class as Solr takes
|
6
|
-
# the sort as a single parameter, so adding sorts as regular components
|
7
|
-
# would not merge correctly in the #to_params method.
|
8
|
-
#
|
9
|
-
class SortComposite #:nodoc:
|
10
|
-
def initialize
|
11
|
-
@sorts = []
|
12
|
-
end
|
13
|
-
|
14
|
-
#
|
15
|
-
# Add a sort to the composite
|
16
|
-
#
|
17
|
-
def <<(sort)
|
18
|
-
@sorts << sort
|
19
|
-
end
|
20
|
-
|
21
|
-
#
|
22
|
-
# Combine the sorts into a single param by joining them
|
23
|
-
#
|
24
|
-
def to_params(prefix = "")
|
25
|
-
unless @sorts.empty?
|
26
|
-
key = "#{prefix}sort".to_sym
|
27
|
-
{ key => @sorts.map { |sort| sort.to_param } * ', ' }
|
28
|
-
else
|
29
|
-
{}
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
module Query
|
3
|
-
class StandardQuery < CommonQuery
|
4
|
-
attr_accessor :scope, :fulltext
|
5
|
-
|
6
|
-
def initialize(types)
|
7
|
-
super
|
8
|
-
@components << @fulltext = CompositeFulltext.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def add_fulltext(keywords)
|
12
|
-
@fulltext.add(keywords)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
module Query
|
3
|
-
class TextFieldBoost #:nodoc:
|
4
|
-
attr_reader :boost
|
5
|
-
|
6
|
-
def initialize(field, boost = nil)
|
7
|
-
@field, @boost = field, boost
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_boosted_field
|
11
|
-
boosted_field = @field.indexed_name
|
12
|
-
boosted_field.concat("^#{@boost}") if @boost
|
13
|
-
boosted_field
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,151 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
|
-
module Sunspot
|
4
|
-
#
|
5
|
-
# Object that encapsulates schema information for building a Solr schema.xml
|
6
|
-
# file. This class is used by the schema:compile task as well as the
|
7
|
-
# sunspot-configure-solr executable.
|
8
|
-
#
|
9
|
-
class Schema #:nodoc:all
|
10
|
-
FieldType = Struct.new(:name, :class_name, :suffix)
|
11
|
-
FieldVariant = Struct.new(:attribute, :suffix)
|
12
|
-
|
13
|
-
DEFAULT_TOKENIZER = 'solr.StandardTokenizerFactory'
|
14
|
-
DEFAULT_FILTERS = %w(solr.StandardFilterFactory solr.LowerCaseFilterFactory)
|
15
|
-
|
16
|
-
FIELD_TYPES = [
|
17
|
-
FieldType.new('boolean', 'Bool', 'b'),
|
18
|
-
FieldType.new('sfloat', 'SortableFloat', 'f'),
|
19
|
-
FieldType.new('date', 'Date', 'd'),
|
20
|
-
FieldType.new('sint', 'SortableInt', 'i'),
|
21
|
-
FieldType.new('string', 'Str', 's'),
|
22
|
-
FieldType.new('sdouble', 'SortableDouble', 'e'),
|
23
|
-
FieldType.new('slong', 'SortableLong', 'l'),
|
24
|
-
FieldType.new('tint', 'TrieInteger', 'it'),
|
25
|
-
FieldType.new('tfloat', 'TrieFloat', 'ft'),
|
26
|
-
FieldType.new('tdate', 'TrieInt', 'dt')
|
27
|
-
|
28
|
-
]
|
29
|
-
|
30
|
-
FIELD_VARIANTS = [
|
31
|
-
FieldVariant.new('multiValued', 'm'),
|
32
|
-
FieldVariant.new('stored', 's')
|
33
|
-
]
|
34
|
-
|
35
|
-
attr_reader :tokenizer, :filters
|
36
|
-
|
37
|
-
def initialize
|
38
|
-
@tokenizer = DEFAULT_TOKENIZER
|
39
|
-
@filters = DEFAULT_FILTERS.dup
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
# Attribute field types defined in the schema
|
44
|
-
#
|
45
|
-
def types
|
46
|
-
FIELD_TYPES
|
47
|
-
end
|
48
|
-
|
49
|
-
#
|
50
|
-
# DynamicField instances representing all the available types and variants
|
51
|
-
#
|
52
|
-
def dynamic_fields
|
53
|
-
fields = []
|
54
|
-
variant_combinations.each do |field_variants|
|
55
|
-
FIELD_TYPES.each do |type|
|
56
|
-
fields << DynamicField.new(type, field_variants)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
fields
|
60
|
-
end
|
61
|
-
|
62
|
-
#
|
63
|
-
# Which tokenizer to use for text fields
|
64
|
-
#
|
65
|
-
def tokenizer=(tokenizer)
|
66
|
-
@tokenizer =
|
67
|
-
if tokenizer =~ /\./
|
68
|
-
tokenizer
|
69
|
-
else
|
70
|
-
"solr.#{tokenizer}TokenizerFactory"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
#
|
75
|
-
# Add a filter for text field tokenization
|
76
|
-
#
|
77
|
-
def add_filter(filter)
|
78
|
-
@filters <<
|
79
|
-
if filter =~ /\./
|
80
|
-
filter
|
81
|
-
else
|
82
|
-
"solr.#{filter}FilterFactory"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
#
|
87
|
-
# Return an XML representation of this schema using the ERB template
|
88
|
-
#
|
89
|
-
def to_xml
|
90
|
-
template = File.join(File.dirname(__FILE__), '..', '..', 'templates', 'schema.xml.erb')
|
91
|
-
ERB.new(File.read(template), nil, '-').result(binding)
|
92
|
-
end
|
93
|
-
|
94
|
-
private
|
95
|
-
|
96
|
-
#
|
97
|
-
# All of the possible combinations of variants
|
98
|
-
#
|
99
|
-
def variant_combinations
|
100
|
-
combinations = []
|
101
|
-
0.upto(2 ** FIELD_VARIANTS.length - 1) do |b|
|
102
|
-
combinations << combination = []
|
103
|
-
FIELD_VARIANTS.each_with_index do |variant, i|
|
104
|
-
combination << variant if b & 1<<i > 0
|
105
|
-
end
|
106
|
-
end
|
107
|
-
combinations
|
108
|
-
end
|
109
|
-
|
110
|
-
#
|
111
|
-
# Represents a dynamic field (in the Solr schema sense, not the Sunspot
|
112
|
-
# sense).
|
113
|
-
#
|
114
|
-
class DynamicField
|
115
|
-
def initialize(type, field_variants)
|
116
|
-
@type, @field_variants = type, field_variants
|
117
|
-
end
|
118
|
-
|
119
|
-
#
|
120
|
-
# Name of the field in the schema
|
121
|
-
#
|
122
|
-
def name
|
123
|
-
variant_suffixes = @field_variants.map { |variant| variant.suffix }.join
|
124
|
-
"*_#{@type.suffix}#{variant_suffixes}"
|
125
|
-
end
|
126
|
-
|
127
|
-
#
|
128
|
-
# Name of the type as defined in the schema
|
129
|
-
#
|
130
|
-
def type
|
131
|
-
@type.name
|
132
|
-
end
|
133
|
-
|
134
|
-
#
|
135
|
-
# Implement magic methods to ask if a field is of a particular variant.
|
136
|
-
# Returns "true" if the field is of that variant and "false" otherwise.
|
137
|
-
#
|
138
|
-
def method_missing(name, *args, &block)
|
139
|
-
if name.to_s =~ /\?$/ && args.empty?
|
140
|
-
if @field_variants.any? { |variant| "#{variant.attribute}?" == name.to_s }
|
141
|
-
'true'
|
142
|
-
else
|
143
|
-
'false'
|
144
|
-
end
|
145
|
-
else
|
146
|
-
super(name.to_sym, *args, &block)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
%w(abstract_search standard_search more_like_this_search query_facet field_facet
|
2
|
-
date_facet range_facet facet_row hit highlight field_group group hit_enumerable).each do |file|
|
3
|
-
require File.join(File.dirname(__FILE__), 'search', file)
|
4
|
-
end
|
5
|
-
|
6
|
-
module Sunspot
|
7
|
-
module Search
|
8
|
-
end
|
9
|
-
end
|
@@ -1,286 +0,0 @@
|
|
1
|
-
require 'sunspot/search/paginated_collection'
|
2
|
-
require 'sunspot/search/hit_enumerable'
|
3
|
-
|
4
|
-
module Sunspot
|
5
|
-
module Search #:nodoc:
|
6
|
-
|
7
|
-
#
|
8
|
-
# This class encapsulates the results of a Solr search. It provides access
|
9
|
-
# to search results, total result count, facets, and pagination information.
|
10
|
-
# Instances of Search are returned by the Sunspot.search and
|
11
|
-
# Sunspot.new_search methods.
|
12
|
-
#
|
13
|
-
class AbstractSearch
|
14
|
-
#
|
15
|
-
# Retrieve all facet objects defined for this search, in order they were
|
16
|
-
# defined. To retrieve an individual facet by name, use #facet()
|
17
|
-
#
|
18
|
-
attr_reader :facets, :groups
|
19
|
-
attr_reader :query #:nodoc:
|
20
|
-
attr_accessor :request_handler
|
21
|
-
|
22
|
-
include HitEnumerable
|
23
|
-
|
24
|
-
def initialize(connection, setup, query, configuration) #:nodoc:
|
25
|
-
@connection, @setup, @query = connection, setup, query
|
26
|
-
@query.paginate(1, configuration.pagination.default_per_page)
|
27
|
-
|
28
|
-
@facets = []
|
29
|
-
@facets_by_name = {}
|
30
|
-
|
31
|
-
@groups_by_name = {}
|
32
|
-
@groups = []
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
# Execute the search on the Solr instance and store the results. If you
|
37
|
-
# use Sunspot#search() to construct your searches, there is no need to call
|
38
|
-
# this method as it has already been called. If you use
|
39
|
-
# Sunspot#new_search(), you will need to call this method after building the
|
40
|
-
# query.
|
41
|
-
#
|
42
|
-
def execute
|
43
|
-
reset
|
44
|
-
params = @query.to_params
|
45
|
-
@solr_result = @connection.post "#{request_handler}", :data => params
|
46
|
-
self
|
47
|
-
end
|
48
|
-
|
49
|
-
def execute! #:nodoc: deprecated
|
50
|
-
execute
|
51
|
-
end
|
52
|
-
|
53
|
-
#
|
54
|
-
# Get the collection of results as instantiated objects. If WillPaginate is
|
55
|
-
# available, the results will be a WillPaginate::Collection instance; if
|
56
|
-
# not, it will be a vanilla Array.
|
57
|
-
#
|
58
|
-
# If not all of the results referenced by the Solr hits actually exist in
|
59
|
-
# the data store, Sunspot will only return the results that do exist.
|
60
|
-
#
|
61
|
-
# ==== Returns
|
62
|
-
#
|
63
|
-
# WillPaginate::Collection or Array:: Instantiated result objects
|
64
|
-
#
|
65
|
-
def results
|
66
|
-
@results ||= paginate_collection(verified_hits.map { |hit| hit.instance })
|
67
|
-
end
|
68
|
-
|
69
|
-
#
|
70
|
-
# Access raw Solr result information. Returns a collection of Hit objects
|
71
|
-
# that contain the class name, primary key, keyword relevance score (if
|
72
|
-
# applicable), and any stored fields.
|
73
|
-
#
|
74
|
-
# ==== Options (options)
|
75
|
-
#
|
76
|
-
# :verify::
|
77
|
-
# Only return hits that reference objects that actually exist in the data
|
78
|
-
# store. This causes results to be eager-loaded from the data store,
|
79
|
-
# unlike the normal behavior of this method, which only loads the
|
80
|
-
# referenced results when Hit#result is first called.
|
81
|
-
#
|
82
|
-
# ==== Returns
|
83
|
-
#
|
84
|
-
# Array:: Ordered collection of Hit objects
|
85
|
-
#
|
86
|
-
def hits(options = {})
|
87
|
-
if options[:verify]
|
88
|
-
super
|
89
|
-
else
|
90
|
-
@hits ||= paginate_collection(super)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
alias_method :raw_results, :hits
|
94
|
-
|
95
|
-
#
|
96
|
-
# The total number of documents matching the query parameters
|
97
|
-
#
|
98
|
-
# ==== Returns
|
99
|
-
#
|
100
|
-
# Integer:: Total matching documents
|
101
|
-
#
|
102
|
-
def total
|
103
|
-
@total ||= solr_response['numFound'] || 0
|
104
|
-
end
|
105
|
-
|
106
|
-
#
|
107
|
-
# The time elapsed to generate the Solr response
|
108
|
-
#
|
109
|
-
# ==== Returns
|
110
|
-
#
|
111
|
-
# Integer:: Query runtime in milliseconds
|
112
|
-
#
|
113
|
-
def query_time
|
114
|
-
@query_time ||= solr_response_header['QTime']
|
115
|
-
end
|
116
|
-
|
117
|
-
#
|
118
|
-
# Get the facet object for the given name. `name` can either be the name
|
119
|
-
# given to a query facet, or the field name of a field facet. Returns a
|
120
|
-
# Sunspot::Facet object.
|
121
|
-
#
|
122
|
-
# ==== Parameters
|
123
|
-
#
|
124
|
-
# name<Symbol>::
|
125
|
-
# Name of the field to return the facet for, or the name given to the
|
126
|
-
# query facet when the search was constructed.
|
127
|
-
# dynamic_name<Symbol>::
|
128
|
-
# If faceting on a dynamic field, this is the dynamic portion of the field
|
129
|
-
# name.
|
130
|
-
#
|
131
|
-
# ==== Example:
|
132
|
-
#
|
133
|
-
# search = Sunspot.search(Post) do
|
134
|
-
# facet :category_ids
|
135
|
-
# dynamic :custom do
|
136
|
-
# facet :cuisine
|
137
|
-
# end
|
138
|
-
# facet :age do
|
139
|
-
# row 'Less than a month' do
|
140
|
-
# with(:published_at).greater_than(1.month.ago)
|
141
|
-
# end
|
142
|
-
# row 'Less than a year' do
|
143
|
-
# with(:published_at, 1.year.ago..1.month.ago)
|
144
|
-
# end
|
145
|
-
# row 'More than a year' do
|
146
|
-
# with(:published_at).less_than(1.year.ago)
|
147
|
-
# end
|
148
|
-
# end
|
149
|
-
# end
|
150
|
-
# search.facet(:category_ids)
|
151
|
-
# #=> Facet for :category_ids field
|
152
|
-
# search.facet(:custom, :cuisine)
|
153
|
-
# #=> Facet for the dynamic field :cuisine in the :custom field definition
|
154
|
-
# search.facet(:age)
|
155
|
-
# #=> Facet for the query facet named :age
|
156
|
-
#
|
157
|
-
def facet(name, dynamic_name = nil)
|
158
|
-
if name
|
159
|
-
if dynamic_name
|
160
|
-
@facets_by_name[:"#{name}:#{dynamic_name}"]
|
161
|
-
else
|
162
|
-
@facets_by_name[name.to_sym]
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def group(name)
|
168
|
-
if name
|
169
|
-
@groups_by_name[name.to_sym]
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
#
|
174
|
-
# Deprecated in favor of optional second argument to #facet
|
175
|
-
#
|
176
|
-
def dynamic_facet(base_name, dynamic_name) #:nodoc:
|
177
|
-
facet(base_name, dynamic_name)
|
178
|
-
end
|
179
|
-
|
180
|
-
def facet_response #:nodoc:
|
181
|
-
@solr_result['facet_counts']
|
182
|
-
end
|
183
|
-
|
184
|
-
def group_response #:nodoc:
|
185
|
-
@solr_result['grouped']
|
186
|
-
end
|
187
|
-
|
188
|
-
#
|
189
|
-
# Build this search using a DSL block. This method can be called more than
|
190
|
-
# once on an unexecuted search (e.g., Sunspot.new_search) in order to build
|
191
|
-
# a search incrementally.
|
192
|
-
#
|
193
|
-
# === Example
|
194
|
-
#
|
195
|
-
# search = Sunspot.new_search(Post)
|
196
|
-
# search.build do
|
197
|
-
# with(:published_at).less_than Time.now
|
198
|
-
# end
|
199
|
-
# search.execute
|
200
|
-
#
|
201
|
-
def build(&block)
|
202
|
-
Util.instance_eval_or_call(dsl, &block)
|
203
|
-
self
|
204
|
-
end
|
205
|
-
|
206
|
-
|
207
|
-
def inspect #:nodoc:
|
208
|
-
"<Sunspot::Search:#{query.to_params.inspect}>"
|
209
|
-
end
|
210
|
-
|
211
|
-
def add_field_group(field) #:nodoc:
|
212
|
-
add_group(field.name, FieldGroup.new(field, self))
|
213
|
-
end
|
214
|
-
|
215
|
-
def add_field_facet(field, options = {}) #:nodoc:
|
216
|
-
name = (options[:name] || field.name)
|
217
|
-
add_facet(name, FieldFacet.new(field, self, options))
|
218
|
-
end
|
219
|
-
|
220
|
-
def add_query_facet(name, options) #:nodoc:
|
221
|
-
add_facet(name, QueryFacet.new(name, self, options))
|
222
|
-
end
|
223
|
-
|
224
|
-
def add_date_facet(field, options) #:nodoc:
|
225
|
-
name = (options[:name] || field.name)
|
226
|
-
add_facet(name, DateFacet.new(field, self, options))
|
227
|
-
end
|
228
|
-
|
229
|
-
def add_range_facet(field, options) #:nodoc:
|
230
|
-
name = (options[:name] || field.name)
|
231
|
-
add_facet(name, RangeFacet.new(field, self, options))
|
232
|
-
end
|
233
|
-
|
234
|
-
def highlights_for(doc) #:nodoc:
|
235
|
-
if @solr_result['highlighting']
|
236
|
-
@solr_result['highlighting'][doc['id']]
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
private
|
241
|
-
|
242
|
-
def dsl
|
243
|
-
raise NotImplementedError
|
244
|
-
end
|
245
|
-
|
246
|
-
def execute_request(params)
|
247
|
-
raise NotImplementedError
|
248
|
-
end
|
249
|
-
|
250
|
-
def solr_response
|
251
|
-
@solr_response ||= @solr_result['response'] || {}
|
252
|
-
end
|
253
|
-
|
254
|
-
def solr_response_header
|
255
|
-
@solr_response_header ||= @solr_result['responseHeader'] || {}
|
256
|
-
end
|
257
|
-
|
258
|
-
def solr_docs
|
259
|
-
solr_response['docs']
|
260
|
-
end
|
261
|
-
|
262
|
-
def verified_hits
|
263
|
-
@verified_hits ||= paginate_collection(super)
|
264
|
-
end
|
265
|
-
|
266
|
-
def paginate_collection(collection)
|
267
|
-
PaginatedCollection.new(collection, @query.page, @query.per_page, total)
|
268
|
-
end
|
269
|
-
|
270
|
-
def add_facet(name, facet)
|
271
|
-
@facets << facet
|
272
|
-
@facets_by_name[name.to_sym] = facet
|
273
|
-
end
|
274
|
-
|
275
|
-
def add_group(name, group)
|
276
|
-
@groups << group
|
277
|
-
@groups_by_name[name.to_sym] = group
|
278
|
-
end
|
279
|
-
|
280
|
-
# Clear out all the cached ivars so the search can be called again.
|
281
|
-
def reset
|
282
|
-
@results = @hits = @verified_hits = @total = @solr_response = @doc_ids = nil
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|