warp-thinking-sphinx 1.3.10 → 1.3.11

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.10
1
+ 1.3.11
@@ -1,48 +1,48 @@
1
1
  module ThinkingSphinx
2
2
  class FacetSearch < Hash
3
3
  attr_accessor :args, :options
4
-
4
+
5
5
  def initialize(*args)
6
6
  ThinkingSphinx.context.define_indexes
7
-
7
+
8
8
  @options = args.extract_options!
9
9
  @args = args
10
-
10
+
11
11
  set_default_options
12
-
12
+
13
13
  populate
14
14
  end
15
-
15
+
16
16
  def for(hash = {})
17
17
  for_options = {:with => {}}.merge(options)
18
-
18
+
19
19
  hash.each do |key, value|
20
20
  attrib = ThinkingSphinx::Facet.attribute_name_from_value(key, value)
21
21
  for_options[:with][attrib] = underlying_value key, value
22
22
  end
23
-
23
+
24
24
  ThinkingSphinx.search *(args + [for_options])
25
25
  end
26
-
26
+
27
27
  def facet_names
28
28
  @facet_names ||= begin
29
29
  names = options[:all_facets] ?
30
30
  facet_names_for_all_classes : facet_names_common_to_all_classes
31
-
31
+
32
32
  names.delete "class_crc" unless options[:class_facet]
33
33
  names
34
34
  end
35
35
  end
36
-
36
+
37
37
  private
38
-
38
+
39
39
  def set_default_options
40
40
  options[:all_facets] ||= false
41
41
  if options[:class_facet].nil?
42
42
  options[:class_facet] = ((options[:classes] || []).length != 1)
43
43
  end
44
44
  end
45
-
45
+
46
46
  def populate
47
47
  facet_names.each do |name|
48
48
  search_options = facet_search_options.merge(:group_by => name)
@@ -51,11 +51,11 @@ module ThinkingSphinx
51
51
  )
52
52
  end
53
53
  end
54
-
54
+
55
55
  def facet_search_options
56
56
  config = ThinkingSphinx::Configuration.instance
57
57
  max = config.configuration.searchd.max_matches || 1000
58
-
58
+
59
59
  options.merge(
60
60
  :group_function => :attr,
61
61
  :limit => max,
@@ -63,7 +63,7 @@ module ThinkingSphinx
63
63
  :page => 1
64
64
  )
65
65
  end
66
-
66
+
67
67
  def facet_classes
68
68
  (
69
69
  options[:classes] || ThinkingSphinx.context.indexed_models.collect { |model|
@@ -71,7 +71,7 @@ module ThinkingSphinx
71
71
  }
72
72
  ).select { |klass| klass.sphinx_facets.any? }
73
73
  end
74
-
74
+
75
75
  def all_facets
76
76
  facet_classes.collect { |klass|
77
77
  klass.sphinx_facets
@@ -79,7 +79,7 @@ module ThinkingSphinx
79
79
  options[:facets].blank? || Array(options[:facets]).include?(facet.name)
80
80
  }
81
81
  end
82
-
82
+
83
83
  def facet_names_for_all_classes
84
84
  all_facets.group_by { |facet|
85
85
  facet.name
@@ -90,7 +90,7 @@ module ThinkingSphinx
90
90
  facets.first.attribute_name
91
91
  }
92
92
  end
93
-
93
+
94
94
  def facet_names_common_to_all_classes
95
95
  facet_names_for_all_classes.select { |name|
96
96
  facet_classes.all? { |klass|
@@ -100,24 +100,24 @@ module ThinkingSphinx
100
100
  }
101
101
  }
102
102
  end
103
-
103
+
104
104
  def add_from_results(facet, results)
105
105
  name = ThinkingSphinx::Facet.name_for(facet)
106
-
106
+
107
107
  self[name] ||= {}
108
-
108
+
109
109
  return if results.empty?
110
-
110
+
111
111
  facet = facet_from_object(results.first, facet) if facet.is_a?(String)
112
-
112
+
113
113
  results.each_with_groupby_and_count { |result, group, count|
114
114
  facet_value = facet.value(result, group)
115
-
115
+
116
116
  self[name][facet_value] ||= 0
117
117
  self[name][facet_value] += count
118
118
  }
119
119
  end
120
-
120
+
121
121
  def underlying_value(key, value)
122
122
  case value
123
123
  when Array
@@ -128,9 +128,9 @@ module ThinkingSphinx
128
128
  value
129
129
  end
130
130
  end
131
-
131
+
132
132
  def facet_from_object(object, name)
133
- object.sphinx_facets.detect { |facet| facet.attribute_name == name }
133
+ object.class.source_of_sphinx_index.sphinx_facets.detect { |facet| facet.attribute_name == name }
134
134
  end
135
135
  end
136
136
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warp-thinking-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.10
4
+ version: 1.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-11 00:00:00 +08:00
12
+ date: 2009-12-12 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency