UnderpantsGnome-sunspot 0.9.1.1 → 0.9.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +44 -0
- data/TODO +7 -2
- data/VERSION.yml +2 -2
- data/lib/sunspot.rb +1 -2
- data/lib/sunspot/facet.rb +6 -41
- data/lib/sunspot/facet_data.rb +120 -0
- data/lib/sunspot/facet_row.rb +3 -27
- data/lib/sunspot/instantiated_facet.rb +5 -1
- data/lib/sunspot/instantiated_facet_row.rb +10 -0
- data/lib/sunspot/query.rb +6 -5
- data/lib/sunspot/query/base_query.rb +3 -3
- data/lib/sunspot/query/connective.rb +52 -3
- data/lib/sunspot/query/field_facet.rb +3 -2
- data/lib/sunspot/query/field_query.rb +8 -2
- data/lib/sunspot/query/query_facet.rb +2 -1
- data/lib/sunspot/query/query_field_facet.rb +13 -0
- data/lib/sunspot/query/restriction.rb +29 -21
- data/lib/sunspot/search.rb +20 -23
- data/lib/sunspot/search/hit.rb +4 -0
- data/lib/sunspot/session.rb +9 -8
- data/spec/api/build_search_spec.rb +123 -24
- data/spec/api/search_retrieval_spec.rb +55 -18
- data/spec/api/session_spec.rb +5 -5
- data/spec/integration/scoped_search_spec.rb +101 -0
- data/spec/integration/spec_helper.rb +6 -0
- data/spec/mocks/connection.rb +8 -0
- data/spec/mocks/mock_record.rb +7 -0
- data/spec/mocks/post.rb +3 -0
- data/tasks/gemspec.rake +2 -3
- data/tasks/rdoc.rake +1 -0
- metadata +28 -28
- data/lib/sunspot/date_facet.rb +0 -36
- data/lib/sunspot/date_facet_row.rb +0 -17
- data/lib/sunspot/query_facet.rb +0 -33
- data/lib/sunspot/query_facet_row.rb +0 -21
data/lib/sunspot/date_facet.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
#
|
3
|
-
# Date facets are retrieved by passing a :time_range key into the
|
4
|
-
# DSL::FieldQuery#facet options. They are only available for Date and Time
|
5
|
-
# type fields. The #value for date facet rows is a Range object encapsulating
|
6
|
-
# the time range covered by the row.
|
7
|
-
#
|
8
|
-
class DateFacet < Facet
|
9
|
-
def initialize(facet_values, field) #:nodoc:
|
10
|
-
@gap = facet_values.delete('gap')[/\+(\d+)SECONDS/,1].to_i
|
11
|
-
%w(start end).each { |key| facet_values.delete(key) }
|
12
|
-
super(facet_values.to_a.flatten, field)
|
13
|
-
end
|
14
|
-
|
15
|
-
#
|
16
|
-
# Get the rows of this date facet, which are instances of DateFacetRow.
|
17
|
-
# The rows will always be sorted in chronological order.
|
18
|
-
#
|
19
|
-
#--
|
20
|
-
#
|
21
|
-
# The date facet info comes back from Solr as a hash, so we need to sort
|
22
|
-
# it manually. FIXME this currently assumes we want to do a "lexical"
|
23
|
-
# sort, but we should support count sort as well, even if it's not a
|
24
|
-
# common use case.
|
25
|
-
#
|
26
|
-
def rows
|
27
|
-
super.sort { |a, b| a.value.first <=> b.value.first }
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def new_row(pair)
|
33
|
-
DateFacetRow.new(pair, @gap, self)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
#TODO document
|
3
|
-
class DateFacetRow < FacetRow
|
4
|
-
def initialize(pair, gap, facet)
|
5
|
-
@gap = gap
|
6
|
-
super(pair, facet)
|
7
|
-
end
|
8
|
-
|
9
|
-
def value
|
10
|
-
@value ||=
|
11
|
-
begin
|
12
|
-
start_date = @facet.field.cast(@pair[0])
|
13
|
-
Range.new(start_date, start_date + @gap)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/sunspot/query_facet.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
#
|
3
|
-
# QueryFacet instances encapsulate a set of query facet results. Each facet
|
4
|
-
# corresponds to a group of rows defined inside a DSL::FieldQuery#facet block.
|
5
|
-
#
|
6
|
-
class QueryFacet
|
7
|
-
def initialize(outgoing_query_facet, row_data) #:nodoc:
|
8
|
-
@outgoing_query_facet, @row_data = outgoing_query_facet, row_data
|
9
|
-
end
|
10
|
-
|
11
|
-
#
|
12
|
-
# Get the rows associated with this query facet. Returned rows are always
|
13
|
-
# ordered by count.
|
14
|
-
#
|
15
|
-
# ==== Returns
|
16
|
-
#
|
17
|
-
# Array:: Collection of QueryFacetRow objects, ordered by count
|
18
|
-
#
|
19
|
-
def rows
|
20
|
-
@rows ||=
|
21
|
-
begin
|
22
|
-
rows = []
|
23
|
-
for row in @outgoing_query_facet.rows
|
24
|
-
row_query = row.to_boolean_phrase
|
25
|
-
if @row_data.has_key?(row_query)
|
26
|
-
rows << QueryFacetRow.new(row.label, @row_data[row_query])
|
27
|
-
end
|
28
|
-
end
|
29
|
-
rows.sort! { |x, y| y.count <=> x.count }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
#
|
3
|
-
# Objects of this class encapsulate a single query facet row returned for a
|
4
|
-
# query facet.
|
5
|
-
#
|
6
|
-
class QueryFacetRow
|
7
|
-
#
|
8
|
-
# This is the "label" passed into the query facet row when it is defined in
|
9
|
-
# the search.
|
10
|
-
#
|
11
|
-
attr_reader :value
|
12
|
-
#
|
13
|
-
# Number of documents in the result set that match this facet's scope.
|
14
|
-
#
|
15
|
-
attr_reader :count
|
16
|
-
|
17
|
-
def initialize(value, count) #:nodoc:
|
18
|
-
@value, @count = value, count
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|