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.
@@ -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
@@ -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