outoftime-sunspot 0.7.3 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +26 -1
- data/LICENSE +18 -0
- data/README.rdoc +31 -25
- data/Rakefile +1 -1
- data/TODO +1 -5
- data/VERSION.yml +2 -2
- data/lib/sunspot/adapters.rb +28 -11
- data/lib/sunspot/data_extractor.rb +37 -0
- data/lib/sunspot/dsl/fields.rb +6 -17
- data/lib/sunspot/dsl/query.rb +22 -120
- data/lib/sunspot/dsl/restriction.rb +25 -0
- data/lib/sunspot/dsl/scope.rb +127 -15
- data/lib/sunspot/dsl.rb +1 -1
- data/lib/sunspot/field.rb +151 -81
- data/lib/sunspot/indexer.rb +1 -1
- data/lib/sunspot/query/dynamic_query.rb +86 -0
- data/lib/sunspot/{facets.rb → query/field_facet.rb} +1 -1
- data/lib/sunspot/query/pagination.rb +39 -0
- data/lib/sunspot/query/restriction.rb +223 -0
- data/lib/sunspot/query/sort.rb +33 -0
- data/lib/sunspot/query.rb +217 -117
- data/lib/sunspot/search.rb +43 -5
- data/lib/sunspot/session.rb +20 -5
- data/lib/sunspot/setup.rb +39 -10
- data/lib/sunspot/type.rb +15 -7
- data/lib/sunspot/util.rb +17 -0
- data/lib/sunspot.rb +83 -2
- data/spec/api/build_search_spec.rb +120 -2
- data/spec/api/indexer_spec.rb +44 -0
- data/spec/api/query_spec.rb +129 -0
- data/spec/api/search_retrieval_spec.rb +6 -0
- data/spec/integration/dynamic_fields_spec.rb +55 -0
- data/spec/mocks/post.rb +27 -1
- data/spec/spec_helper.rb +10 -3
- data/tasks/gemspec.rake +6 -1
- data/tasks/rdoc.rake +14 -1
- metadata +79 -56
- data/lib/sunspot/restriction.rb +0 -216
data/tasks/gemspec.rake
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
begin
|
2
|
-
gem 'technicalpickles-jeweler', '~> 0.
|
2
|
+
gem 'technicalpickles-jeweler', '~> 1.0.1'
|
3
3
|
require 'jeweler'
|
4
4
|
Jeweler::Tasks.new do |s|
|
5
5
|
s.name = 'sunspot'
|
@@ -13,5 +13,10 @@ begin
|
|
13
13
|
s.add_dependency 'solr-ruby', '>= 0.0.6'
|
14
14
|
s.add_development_dependency 'rspec', '~> 1.1'
|
15
15
|
s.add_development_dependency 'ruby-debug', '~> 0.10'
|
16
|
+
s.extra_rdoc_files = ['README.rdoc']
|
17
|
+
s.rdoc_options << '--webcvs=http://github.com/outoftime/sunspot/tree/master/%s' <<
|
18
|
+
'--title' << 'Sunspot - Pure-Ruby Solr Search and Indexing - API Documentation' <<
|
19
|
+
'--main' << 'README.rdoc'
|
20
|
+
|
16
21
|
end
|
17
22
|
end
|
data/tasks/rdoc.rake
CHANGED
@@ -1,7 +1,20 @@
|
|
1
|
-
|
1
|
+
gem 'mislav-hanna'
|
2
|
+
require 'hanna/rdoctask'
|
2
3
|
|
3
4
|
Rake::RDocTask.new(:doc) do |rdoc|
|
5
|
+
rdoc.title = 'Sunspot - Pure-Ruby Solr Search and Indexing - API Documentation'
|
4
6
|
rdoc.main = 'README.rdoc'
|
5
7
|
rdoc.rdoc_files.include('README.rdoc', 'lib/sunspot.rb', 'lib/sunspot/**/*.rb')
|
6
8
|
rdoc.rdoc_dir = 'doc'
|
9
|
+
rdoc.options << '--webcvs=http://github.com/outoftime/sunspot/tree/master/%s' << '--title' << 'Sunspot - Pure-Ruby Solr Search and Indexing - API Documentation'
|
10
|
+
end
|
11
|
+
|
12
|
+
namespace :doc do
|
13
|
+
desc 'Generate rdoc and move into pages directory'
|
14
|
+
task :publish => :doc do
|
15
|
+
doc_dir = File.join(File.dirname(__FILE__), '..', 'doc')
|
16
|
+
publish_dir = File.join(File.dirname(__FILE__), '..', 'pages', 'docs')
|
17
|
+
FileUtils.rm_rf(publish_dir) if File.exist?(publish_dir)
|
18
|
+
FileUtils.cp_r(doc_dir, publish_dir)
|
19
|
+
end
|
7
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: outoftime-sunspot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat Brown
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-22 00:00:00 -07:00
|
13
13
|
default_executable: sunspot-solr
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -48,85 +48,91 @@ executables:
|
|
48
48
|
- sunspot-solr
|
49
49
|
extensions: []
|
50
50
|
|
51
|
-
extra_rdoc_files:
|
52
|
-
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.rdoc
|
53
53
|
files:
|
54
|
-
-
|
54
|
+
- History.txt
|
55
|
+
- LICENSE
|
55
56
|
- README.rdoc
|
57
|
+
- Rakefile
|
56
58
|
- TODO
|
57
|
-
- History.txt
|
58
59
|
- VERSION.yml
|
59
60
|
- bin/sunspot-solr
|
60
|
-
- lib/
|
61
|
-
- lib/sunspot
|
62
|
-
- lib/sunspot/type.rb
|
63
|
-
- lib/sunspot/facets.rb
|
64
|
-
- lib/sunspot/facet.rb
|
61
|
+
- lib/light_config.rb
|
62
|
+
- lib/sunspot.rb
|
65
63
|
- lib/sunspot/adapters.rb
|
66
|
-
- lib/sunspot/restriction.rb
|
67
|
-
- lib/sunspot/facet_row.rb
|
68
64
|
- lib/sunspot/configuration.rb
|
65
|
+
- lib/sunspot/data_extractor.rb
|
69
66
|
- lib/sunspot/dsl.rb
|
70
|
-
- lib/sunspot/
|
71
|
-
- lib/sunspot/
|
67
|
+
- lib/sunspot/dsl/fields.rb
|
68
|
+
- lib/sunspot/dsl/query.rb
|
69
|
+
- lib/sunspot/dsl/restriction.rb
|
70
|
+
- lib/sunspot/dsl/scope.rb
|
71
|
+
- lib/sunspot/facet.rb
|
72
|
+
- lib/sunspot/facet_row.rb
|
72
73
|
- lib/sunspot/field.rb
|
73
74
|
- lib/sunspot/indexer.rb
|
74
75
|
- lib/sunspot/query.rb
|
76
|
+
- lib/sunspot/query/dynamic_query.rb
|
77
|
+
- lib/sunspot/query/field_facet.rb
|
78
|
+
- lib/sunspot/query/pagination.rb
|
79
|
+
- lib/sunspot/query/restriction.rb
|
80
|
+
- lib/sunspot/query/sort.rb
|
81
|
+
- lib/sunspot/search.rb
|
82
|
+
- lib/sunspot/session.rb
|
83
|
+
- lib/sunspot/setup.rb
|
84
|
+
- lib/sunspot/type.rb
|
75
85
|
- lib/sunspot/util.rb
|
76
|
-
- lib/sunspot/dsl
|
77
|
-
- lib/sunspot/dsl/fields.rb
|
78
|
-
- lib/sunspot/dsl/scope.rb
|
79
|
-
- lib/sunspot/dsl/query.rb
|
80
|
-
- lib/sunspot.rb
|
81
|
-
- lib/light_config.rb
|
82
|
-
- spec/spec_helper.rb
|
83
|
-
- spec/integration
|
84
|
-
- spec/integration/spec_helper.rb
|
85
|
-
- spec/integration/faceting_spec.rb
|
86
|
-
- spec/integration/scoped_search_spec.rb
|
87
|
-
- spec/integration/keyword_search_spec.rb
|
88
|
-
- spec/integration/test_pagination.rb
|
89
|
-
- spec/mocks
|
90
|
-
- spec/mocks/base_class.rb
|
91
|
-
- spec/mocks/mock_adapter.rb
|
92
|
-
- spec/mocks/user.rb
|
93
|
-
- spec/mocks/post.rb
|
94
|
-
- spec/mocks/comment.rb
|
95
|
-
- spec/api
|
96
|
-
- spec/api/search_retrieval_spec.rb
|
97
|
-
- spec/api/spec_helper.rb
|
98
|
-
- spec/api/session_spec.rb
|
99
|
-
- spec/api/build_search_spec.rb
|
100
|
-
- spec/api/indexer_spec.rb
|
101
|
-
- tasks/gemspec.rake
|
102
|
-
- tasks/rcov.rake
|
103
|
-
- tasks/todo.rake
|
104
|
-
- tasks/rdoc.rake
|
105
|
-
- tasks/spec.rake
|
106
|
-
- solr/etc/webdefault.xml
|
107
86
|
- solr/etc/jetty.xml
|
108
|
-
- solr/
|
109
|
-
- solr/lib/servlet-api-2.5-6.1.3.jar
|
87
|
+
- solr/etc/webdefault.xml
|
110
88
|
- solr/lib/jetty-6.1.3.jar
|
111
|
-
- solr/lib/
|
112
|
-
- solr/lib/jsp-2.1/jsp-2.1.jar
|
89
|
+
- solr/lib/jetty-util-6.1.3.jar
|
113
90
|
- solr/lib/jsp-2.1/ant-1.6.5.jar
|
114
91
|
- solr/lib/jsp-2.1/core-3.1.1.jar
|
92
|
+
- solr/lib/jsp-2.1/jsp-2.1.jar
|
115
93
|
- solr/lib/jsp-2.1/jsp-api-2.1.jar
|
116
|
-
- solr/
|
94
|
+
- solr/lib/servlet-api-2.5-6.1.3.jar
|
117
95
|
- solr/solr/conf/elevate.xml
|
118
96
|
- solr/solr/conf/protwords.txt
|
119
|
-
- solr/solr/conf/synonyms.txt
|
120
|
-
- solr/solr/conf/solrconfig.xml
|
121
97
|
- solr/solr/conf/schema.xml
|
98
|
+
- solr/solr/conf/solrconfig.xml
|
122
99
|
- solr/solr/conf/stopwords.txt
|
100
|
+
- solr/solr/conf/synonyms.txt
|
123
101
|
- solr/start.jar
|
102
|
+
- solr/webapps/solr.war
|
103
|
+
- spec/api/build_search_spec.rb
|
104
|
+
- spec/api/indexer_spec.rb
|
105
|
+
- spec/api/query_spec.rb
|
106
|
+
- spec/api/search_retrieval_spec.rb
|
107
|
+
- spec/api/session_spec.rb
|
108
|
+
- spec/api/spec_helper.rb
|
109
|
+
- spec/integration/dynamic_fields_spec.rb
|
110
|
+
- spec/integration/faceting_spec.rb
|
111
|
+
- spec/integration/keyword_search_spec.rb
|
112
|
+
- spec/integration/scoped_search_spec.rb
|
113
|
+
- spec/integration/spec_helper.rb
|
114
|
+
- spec/integration/test_pagination.rb
|
115
|
+
- spec/mocks/base_class.rb
|
116
|
+
- spec/mocks/comment.rb
|
117
|
+
- spec/mocks/mock_adapter.rb
|
118
|
+
- spec/mocks/post.rb
|
119
|
+
- spec/mocks/user.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
- tasks/gemspec.rake
|
122
|
+
- tasks/rcov.rake
|
123
|
+
- tasks/rdoc.rake
|
124
|
+
- tasks/spec.rake
|
125
|
+
- tasks/todo.rake
|
124
126
|
has_rdoc: true
|
125
127
|
homepage: http://github.com/outoftime/sunspot
|
126
128
|
post_install_message:
|
127
129
|
rdoc_options:
|
128
|
-
- --inline-source
|
129
130
|
- --charset=UTF-8
|
131
|
+
- --webcvs=http://github.com/outoftime/sunspot/tree/master/%s
|
132
|
+
- --title
|
133
|
+
- Sunspot - Pure-Ruby Solr Search and Indexing - API Documentation
|
134
|
+
- --main
|
135
|
+
- README.rdoc
|
130
136
|
require_paths:
|
131
137
|
- lib
|
132
138
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -148,5 +154,22 @@ rubygems_version: 1.2.0
|
|
148
154
|
signing_key:
|
149
155
|
specification_version: 3
|
150
156
|
summary: Library for expressive, powerful interaction with the Solr search engine
|
151
|
-
test_files:
|
152
|
-
|
157
|
+
test_files:
|
158
|
+
- spec/spec_helper.rb
|
159
|
+
- spec/integration/spec_helper.rb
|
160
|
+
- spec/integration/faceting_spec.rb
|
161
|
+
- spec/integration/scoped_search_spec.rb
|
162
|
+
- spec/integration/keyword_search_spec.rb
|
163
|
+
- spec/integration/dynamic_fields_spec.rb
|
164
|
+
- spec/integration/test_pagination.rb
|
165
|
+
- spec/mocks/base_class.rb
|
166
|
+
- spec/mocks/mock_adapter.rb
|
167
|
+
- spec/mocks/user.rb
|
168
|
+
- spec/mocks/post.rb
|
169
|
+
- spec/mocks/comment.rb
|
170
|
+
- spec/api/search_retrieval_spec.rb
|
171
|
+
- spec/api/spec_helper.rb
|
172
|
+
- spec/api/session_spec.rb
|
173
|
+
- spec/api/build_search_spec.rb
|
174
|
+
- spec/api/indexer_spec.rb
|
175
|
+
- spec/api/query_spec.rb
|
data/lib/sunspot/restriction.rb
DELETED
@@ -1,216 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
module Restriction #:nodoc:
|
3
|
-
class <<self
|
4
|
-
#
|
5
|
-
# Return the names of all of the restriction classes that should be made
|
6
|
-
# available to the DSL.
|
7
|
-
#
|
8
|
-
# ==== Returns
|
9
|
-
#
|
10
|
-
# Array:: Collection of restriction class names
|
11
|
-
#
|
12
|
-
def names
|
13
|
-
constants - %w(Base SameAs) #XXX this seems ugly
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
#
|
18
|
-
# Subclasses of this class represent restrictions that can be applied to
|
19
|
-
# a Sunspot query. The Sunspot::DSL::Restriction class presents a builder
|
20
|
-
# API for instances of this class.
|
21
|
-
#
|
22
|
-
# Implementations of this class must respond to #to_params and
|
23
|
-
# #to_negative_params. Instead of implementing those methods, they may
|
24
|
-
# choose to implement any of:
|
25
|
-
#
|
26
|
-
# * #to_positive_boolean_phrase, and optionally #to_negative_boolean_phrase
|
27
|
-
# * #to_solr_conditional
|
28
|
-
#
|
29
|
-
class Base #:nodoc:
|
30
|
-
def initialize(field, value, negative = false)
|
31
|
-
@field, @value, @negative = field, value, negative
|
32
|
-
end
|
33
|
-
|
34
|
-
#
|
35
|
-
# A hash representing this restriction in solr-ruby's parameter format.
|
36
|
-
# All restriction implementations must respond to this method; however,
|
37
|
-
# the base implementation delegates to the #to_positive_boolean_phrase method, so
|
38
|
-
# subclasses may (and probably should) choose to implement that method
|
39
|
-
# instead.
|
40
|
-
#
|
41
|
-
# ==== Returns
|
42
|
-
#
|
43
|
-
# Hash:: Representation of this restriction as solr-ruby parameters
|
44
|
-
#
|
45
|
-
def to_params
|
46
|
-
{ :filter_queries => [to_boolean_phrase] }
|
47
|
-
end
|
48
|
-
|
49
|
-
#
|
50
|
-
# Return the boolean phrase associated with this restriction object.
|
51
|
-
# Differentiates between positive and negative boolean phrases depending
|
52
|
-
# on whether this restriction is negated.
|
53
|
-
#
|
54
|
-
def to_boolean_phrase
|
55
|
-
unless negative?
|
56
|
-
to_positive_boolean_phrase
|
57
|
-
else
|
58
|
-
to_negative_boolean_phrase
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
#
|
63
|
-
# Boolean phrase representing this restriction in the positive. Subclasses
|
64
|
-
# may choose to implement this method rather than #to_params; however,
|
65
|
-
# this method delegates to the abstract #to_solr_conditional method, which
|
66
|
-
# in most cases will be what subclasses will want to implement.
|
67
|
-
# #to_solr_conditional contains the boolean phrase representing the
|
68
|
-
# condition but leaves out the field name (see built-in implementations
|
69
|
-
# for examples)
|
70
|
-
#
|
71
|
-
# ==== Returns
|
72
|
-
#
|
73
|
-
# String:: Boolean phrase for restriction in the positive
|
74
|
-
#
|
75
|
-
def to_positive_boolean_phrase
|
76
|
-
"#{@field.indexed_name}:#{to_solr_conditional}"
|
77
|
-
end
|
78
|
-
|
79
|
-
#
|
80
|
-
# Boolean phrase representing this restriction in the negative. Subclasses
|
81
|
-
# may choose to implement this method, but it is not necessary, as the
|
82
|
-
# base implementation delegates to #to_positive_boolean_phrase.
|
83
|
-
#
|
84
|
-
# ==== Returns
|
85
|
-
#
|
86
|
-
# String:: Boolean phrase for restriction in the negative
|
87
|
-
#
|
88
|
-
def to_negative_boolean_phrase
|
89
|
-
"-#{to_positive_boolean_phrase}"
|
90
|
-
end
|
91
|
-
|
92
|
-
protected
|
93
|
-
|
94
|
-
#
|
95
|
-
# Whether this restriction should be negated from its original meaning
|
96
|
-
#
|
97
|
-
def negative?
|
98
|
-
!!@negative
|
99
|
-
end
|
100
|
-
|
101
|
-
#
|
102
|
-
# Return escaped Solr API representation of given value
|
103
|
-
#
|
104
|
-
# ==== Parameters
|
105
|
-
#
|
106
|
-
# value<Object>::
|
107
|
-
# value to convert to Solr representation (default: @value)
|
108
|
-
#
|
109
|
-
# ==== Returns
|
110
|
-
#
|
111
|
-
# String:: Solr API representation of given value
|
112
|
-
#
|
113
|
-
def solr_value(value = @value)
|
114
|
-
Solr::Util.query_parser_escape(@field.to_indexed(value))
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
#
|
119
|
-
# Results must have field with value equal to given value. If the value
|
120
|
-
# is nil, results must have no value for the given field.
|
121
|
-
#
|
122
|
-
class EqualTo < Base
|
123
|
-
def to_positive_boolean_phrase
|
124
|
-
unless @value.nil?
|
125
|
-
super
|
126
|
-
else
|
127
|
-
"-#{@field.indexed_name}:[* TO *]"
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def to_negative_boolean_phrase
|
132
|
-
unless @value.nil?
|
133
|
-
super
|
134
|
-
else
|
135
|
-
"#{@field.indexed_name}:[* TO *]"
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
private
|
140
|
-
|
141
|
-
def to_solr_conditional
|
142
|
-
"#{solr_value}"
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
#
|
147
|
-
# Results must have field with value less than given value
|
148
|
-
#
|
149
|
-
class LessThan < Base
|
150
|
-
private
|
151
|
-
|
152
|
-
def to_solr_conditional
|
153
|
-
"[* TO #{solr_value}]"
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
#
|
158
|
-
# Results must have field with value greater than given value
|
159
|
-
#
|
160
|
-
class GreaterThan < Base
|
161
|
-
private
|
162
|
-
|
163
|
-
def to_solr_conditional
|
164
|
-
"[#{solr_value} TO *]"
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
#
|
169
|
-
# Results must have field with value in given range
|
170
|
-
#
|
171
|
-
class Between < Base
|
172
|
-
private
|
173
|
-
|
174
|
-
def to_solr_conditional
|
175
|
-
"[#{solr_value(@value.first)} TO #{solr_value(@value.last)}]"
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
#
|
180
|
-
# Results must have field with value included in given collection
|
181
|
-
#
|
182
|
-
class AnyOf < Base
|
183
|
-
private
|
184
|
-
|
185
|
-
def to_solr_conditional
|
186
|
-
"(#{@value.map { |v| solr_value v } * ' OR '})"
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
#
|
191
|
-
# Results must have field with values matching all values in given
|
192
|
-
# collection (only makes sense for fields with multiple values)
|
193
|
-
#
|
194
|
-
class AllOf < Base
|
195
|
-
private
|
196
|
-
|
197
|
-
def to_solr_conditional
|
198
|
-
"(#{@value.map { |v| solr_value v } * ' AND '})"
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
#
|
203
|
-
# Result must be the exact instance given (only useful when negated).
|
204
|
-
#
|
205
|
-
class SameAs < Base
|
206
|
-
def initialize(object, negative = false)
|
207
|
-
@object, @negative = object, negative
|
208
|
-
end
|
209
|
-
|
210
|
-
def to_positive_boolean_phrase
|
211
|
-
adapter = Adapters::InstanceAdapter.adapt(@object)
|
212
|
-
"id:#{Solr::Util.query_parser_escape(adapter.index_id)}"
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|