thinking-sphinx 1.4.5 → 1.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +1 -0
- data/VERSION +1 -1
- data/features/searching_by_model.feature +13 -0
- data/features/thinking_sphinx/db/fixtures/posts.rb +5 -1
- data/features/thinking_sphinx/db/migrations/create_posts.rb +1 -0
- data/features/thinking_sphinx/models/developer.rb +1 -0
- data/features/thinking_sphinx/models/music.rb +3 -1
- data/features/thinking_sphinx/models/post.rb +1 -0
- data/lib/thinking_sphinx.rb +2 -2
- data/lib/thinking_sphinx/active_record.rb +27 -0
- data/lib/thinking_sphinx/active_record/delta.rb +0 -27
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +4 -0
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +4 -0
- data/lib/thinking_sphinx/association.rb +23 -3
- data/lib/thinking_sphinx/attribute.rb +17 -10
- data/lib/thinking_sphinx/auto_version.rb +1 -1
- data/lib/thinking_sphinx/class_facet.rb +7 -3
- data/lib/thinking_sphinx/configuration.rb +6 -6
- data/lib/thinking_sphinx/facet.rb +1 -0
- data/lib/thinking_sphinx/facet_search.rb +5 -1
- data/lib/thinking_sphinx/field.rb +16 -0
- data/lib/thinking_sphinx/search.rb +21 -5
- data/lib/thinking_sphinx/source.rb +10 -0
- data/lib/thinking_sphinx/source/internal_properties.rb +8 -3
- data/lib/thinking_sphinx/source/sql.rb +10 -1
- data/spec/thinking_sphinx/attribute_spec.rb +86 -94
- data/spec/thinking_sphinx/auto_version_spec.rb +8 -0
- data/spec/thinking_sphinx/facet_search_spec.rb +12 -6
- data/spec/thinking_sphinx/index/builder_spec.rb +32 -29
- data/spec/thinking_sphinx/search_spec.rb +14 -11
- metadata +4 -4
data/README.textile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.4.
|
1
|
+
1.4.6
|
@@ -66,6 +66,12 @@ Feature: Searching on a single model
|
|
66
66
|
When I filter by 2001-01-01 on comments_created_at
|
67
67
|
Then I should get 1 result
|
68
68
|
|
69
|
+
Scenario: Filtering on a wordcount attribute
|
70
|
+
Given Sphinx is running
|
71
|
+
And I am searching on developers
|
72
|
+
When I filter between 0 and 1 on state_wordcount
|
73
|
+
Then I should get 5 results
|
74
|
+
|
69
75
|
Scenario: Searching by NULL/0 values in MVAs
|
70
76
|
Given Sphinx is running
|
71
77
|
And I am searching on boxes
|
@@ -166,3 +172,10 @@ Feature: Searching on a single model
|
|
166
172
|
And I am searching on posts
|
167
173
|
When I search for "Shakespeare"
|
168
174
|
Then I should get 1 result
|
175
|
+
|
176
|
+
Scenario: Searching on content from file field
|
177
|
+
Given Sphinx is running
|
178
|
+
And I am searching on posts
|
179
|
+
When I search for "foo bar baz"
|
180
|
+
Then I should get 1 result
|
181
|
+
|
@@ -1,5 +1,9 @@
|
|
1
1
|
post = Post.create(
|
2
|
-
:subject => "Hello World",
|
2
|
+
:subject => "Hello World",
|
3
|
+
:content => "Um Text",
|
4
|
+
:id => 1,
|
5
|
+
:category_id => 1,
|
6
|
+
:keywords_file => (File.dirname(__FILE__) + '/post_keywords.txt')
|
3
7
|
)
|
4
8
|
|
5
9
|
post.authors << Author.find(:first)
|
@@ -11,6 +11,7 @@ class Post < ActiveRecord::Base
|
|
11
11
|
indexes tags.text, :as => :tags
|
12
12
|
indexes comments.content, :as => :comments
|
13
13
|
indexes authors.name, :as => :authors
|
14
|
+
indexes keywords_file, :as => :keywords, :file => true
|
14
15
|
|
15
16
|
has comments(:id), :as => :comment_ids, :source => :ranged_query,
|
16
17
|
:facet => true
|
data/lib/thinking_sphinx.rb
CHANGED
@@ -108,8 +108,8 @@ module ThinkingSphinx
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
def self.unique_id_expression(offset = nil)
|
112
|
-
"* #{context.indexed_models.size} + #{offset || 0}"
|
111
|
+
def self.unique_id_expression(adapter, offset = nil)
|
112
|
+
"* #{adapter.cast_to_int context.indexed_models.size} + #{offset || 0}"
|
113
113
|
end
|
114
114
|
|
115
115
|
# Check if index definition is disabled.
|
@@ -285,6 +285,33 @@ module ThinkingSphinx
|
|
285
285
|
index eldest_indexed_ancestor
|
286
286
|
end
|
287
287
|
|
288
|
+
# Temporarily disable delta indexing inside a block, then perform a
|
289
|
+
# single rebuild of index at the end.
|
290
|
+
#
|
291
|
+
# Useful when performing updates to batches of models to prevent
|
292
|
+
# the delta index being rebuilt after each individual update.
|
293
|
+
#
|
294
|
+
# In the following example, the delta index will only be rebuilt
|
295
|
+
# once, not 10 times.
|
296
|
+
#
|
297
|
+
# SomeModel.suspended_delta do
|
298
|
+
# 10.times do
|
299
|
+
# SomeModel.create( ... )
|
300
|
+
# end
|
301
|
+
# end
|
302
|
+
#
|
303
|
+
def suspended_delta(reindex_after = true, &block)
|
304
|
+
define_indexes
|
305
|
+
original_setting = ThinkingSphinx.deltas_suspended?
|
306
|
+
ThinkingSphinx.deltas_suspended = true
|
307
|
+
begin
|
308
|
+
yield
|
309
|
+
ensure
|
310
|
+
ThinkingSphinx.deltas_suspended = original_setting
|
311
|
+
self.index_delta if reindex_after
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
288
315
|
private
|
289
316
|
|
290
317
|
def local_sphinx_indexes
|
@@ -22,33 +22,6 @@ module ThinkingSphinx
|
|
22
22
|
def delta_objects
|
23
23
|
self.sphinx_indexes.collect(&:delta_object).compact
|
24
24
|
end
|
25
|
-
|
26
|
-
# Temporarily disable delta indexing inside a block, then perform a
|
27
|
-
# single rebuild of index at the end.
|
28
|
-
#
|
29
|
-
# Useful when performing updates to batches of models to prevent
|
30
|
-
# the delta index being rebuilt after each individual update.
|
31
|
-
#
|
32
|
-
# In the following example, the delta index will only be rebuilt
|
33
|
-
# once, not 10 times.
|
34
|
-
#
|
35
|
-
# SomeModel.suspended_delta do
|
36
|
-
# 10.times do
|
37
|
-
# SomeModel.create( ... )
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
def suspended_delta(reindex_after = true, &block)
|
42
|
-
define_indexes
|
43
|
-
original_setting = ThinkingSphinx.deltas_suspended?
|
44
|
-
ThinkingSphinx.deltas_suspended = true
|
45
|
-
begin
|
46
|
-
yield
|
47
|
-
ensure
|
48
|
-
ThinkingSphinx.deltas_suspended = original_setting
|
49
|
-
self.index_delta if reindex_after
|
50
|
-
end
|
51
|
-
end
|
52
25
|
end
|
53
26
|
|
54
27
|
def toggled_delta?
|
@@ -71,9 +71,7 @@ module ThinkingSphinx
|
|
71
71
|
# join conditions avoid column name collisions.
|
72
72
|
#
|
73
73
|
def to_sql
|
74
|
-
|
75
|
-
"#{@reflection.klass.connection.quote_table_name(@join.parent.aliased_table_name)}"
|
76
|
-
)
|
74
|
+
rewrite_conditions
|
77
75
|
end
|
78
76
|
|
79
77
|
# Returns true if the association - or a parent - is a has_many or
|
@@ -160,5 +158,27 @@ module ThinkingSphinx
|
|
160
158
|
|
161
159
|
options
|
162
160
|
end
|
161
|
+
|
162
|
+
def rewrite_conditions
|
163
|
+
rewrite_condition @join.association_join
|
164
|
+
end
|
165
|
+
|
166
|
+
def rewrite_condition(condition)
|
167
|
+
return condition unless condition.is_a?(String)
|
168
|
+
|
169
|
+
if defined?(ActsAsTaggableOn) &&
|
170
|
+
@reflection.klass == ActsAsTaggableOn::Tagging &&
|
171
|
+
@reflection.name.to_s[/_taggings$/]
|
172
|
+
condition = condition.gsub /taggings\./, "#{quoted_alias @join}."
|
173
|
+
end
|
174
|
+
|
175
|
+
condition.gsub /::ts_join_alias::/, quoted_alias(@join.parent)
|
176
|
+
end
|
177
|
+
|
178
|
+
def quoted_alias(join)
|
179
|
+
@reflection.klass.connection.quote_table_name(
|
180
|
+
join.aliased_table_name
|
181
|
+
)
|
182
|
+
end
|
163
183
|
end
|
164
184
|
end
|
@@ -11,6 +11,21 @@ module ThinkingSphinx
|
|
11
11
|
class Attribute < ThinkingSphinx::Property
|
12
12
|
attr_accessor :query_source
|
13
13
|
|
14
|
+
SphinxTypeMappings = {
|
15
|
+
:multi => :sql_attr_multi,
|
16
|
+
:datetime => :sql_attr_timestamp,
|
17
|
+
:string => :sql_attr_str2ordinal,
|
18
|
+
:float => :sql_attr_float,
|
19
|
+
:boolean => :sql_attr_bool,
|
20
|
+
:integer => :sql_attr_uint,
|
21
|
+
:bigint => :sql_attr_bigint,
|
22
|
+
:wordcount => :sql_attr_str2wordcount
|
23
|
+
}
|
24
|
+
|
25
|
+
if Riddle.loaded_version.to_i > 1
|
26
|
+
SphinxTypeMappings[:string] = :sql_attr_string
|
27
|
+
end
|
28
|
+
|
14
29
|
# To create a new attribute, you'll need to pass in either a single Column
|
15
30
|
# or an array of them, and some (optional) options.
|
16
31
|
#
|
@@ -117,15 +132,7 @@ module ThinkingSphinx
|
|
117
132
|
end
|
118
133
|
|
119
134
|
def type_to_config
|
120
|
-
|
121
|
-
:multi => :sql_attr_multi,
|
122
|
-
:datetime => :sql_attr_timestamp,
|
123
|
-
:string => :sql_attr_str2ordinal,
|
124
|
-
:float => :sql_attr_float,
|
125
|
-
:boolean => :sql_attr_bool,
|
126
|
-
:integer => :sql_attr_uint,
|
127
|
-
:bigint => :sql_attr_bigint
|
128
|
-
}[type]
|
135
|
+
SphinxTypeMappings[type]
|
129
136
|
end
|
130
137
|
|
131
138
|
def include_as_association?
|
@@ -226,7 +233,7 @@ module ThinkingSphinx
|
|
226
233
|
|
227
234
|
<<-SQL
|
228
235
|
SELECT #{foreign_key_for_mva base_assoc}
|
229
|
-
#{ThinkingSphinx.unique_id_expression(offset)} AS #{quote_column('id')},
|
236
|
+
#{ThinkingSphinx.unique_id_expression(adapter, offset)} AS #{quote_column('id')},
|
230
237
|
#{primary_key_for_mva(end_assoc)} AS #{quote_column(unique_name)}
|
231
238
|
FROM #{quote_table_name base_assoc.table} #{association_joins}
|
232
239
|
SQL
|
@@ -5,12 +5,16 @@ module ThinkingSphinx
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def attribute_name
|
8
|
-
|
8
|
+
Riddle.loaded_version.to_i < 2 ? 'class_crc' : 'sphinx_internal_class'
|
9
9
|
end
|
10
10
|
|
11
11
|
def value(object, attribute_hash)
|
12
|
-
|
13
|
-
|
12
|
+
if Riddle.loaded_version.to_i < 2
|
13
|
+
crc = attribute_hash['class_crc']
|
14
|
+
ThinkingSphinx::Configuration.instance.models_by_crc[crc]
|
15
|
+
else
|
16
|
+
attribute_hash['sphinx_internal_class']
|
17
|
+
end
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
@@ -91,10 +91,10 @@ module ThinkingSphinx
|
|
91
91
|
if custom_app_root
|
92
92
|
self.app_root = custom_app_root
|
93
93
|
else
|
94
|
-
self.app_root
|
95
|
-
self.app_root
|
96
|
-
self.app_root
|
97
|
-
self.app_root
|
94
|
+
self.app_root = Merb.root if defined?(Merb)
|
95
|
+
self.app_root = Sinatra::Application.root if defined?(Sinatra)
|
96
|
+
self.app_root = RAILS_ROOT if defined?(RAILS_ROOT)
|
97
|
+
self.app_root ||= app_root
|
98
98
|
end
|
99
99
|
|
100
100
|
@configuration = Riddle::Configuration.new
|
@@ -132,10 +132,10 @@ module ThinkingSphinx
|
|
132
132
|
ThinkingSphinx.mutex.synchronize do
|
133
133
|
@@environment ||= if defined?(Merb)
|
134
134
|
Merb.environment
|
135
|
-
elsif defined?(Sinatra)
|
136
|
-
Sinatra::Application.environment.to_s
|
137
135
|
elsif defined?(RAILS_ENV)
|
138
136
|
RAILS_ENV
|
137
|
+
elsif defined?(Sinatra)
|
138
|
+
Sinatra::Application.environment.to_s
|
139
139
|
else
|
140
140
|
ENV['RAILS_ENV'] || 'development'
|
141
141
|
end
|
@@ -29,7 +29,7 @@ module ThinkingSphinx
|
|
29
29
|
names = options[:all_facets] ?
|
30
30
|
facet_names_for_all_classes : facet_names_common_to_all_classes
|
31
31
|
|
32
|
-
names.delete
|
32
|
+
names.delete class_facet unless options[:class_facet]
|
33
33
|
names
|
34
34
|
end
|
35
35
|
end
|
@@ -162,5 +162,9 @@ module ThinkingSphinx
|
|
162
162
|
facet.name == name
|
163
163
|
}
|
164
164
|
end
|
165
|
+
|
166
|
+
def class_facet
|
167
|
+
Riddle.loaded_version.to_i < 2 ? 'class_crc' : 'sphinx_internal_class'
|
168
|
+
end
|
165
169
|
end
|
166
170
|
end
|
@@ -19,6 +19,8 @@ module ThinkingSphinx
|
|
19
19
|
# - :sortable => true
|
20
20
|
# - :infixes => true
|
21
21
|
# - :prefixes => true
|
22
|
+
# - :file => true
|
23
|
+
# - :with => :attribute # or :wordcount
|
22
24
|
#
|
23
25
|
# Alias is only required in three circumstances: when there's
|
24
26
|
# another attribute or field with the same name, when the column name is
|
@@ -58,6 +60,8 @@ module ThinkingSphinx
|
|
58
60
|
@sortable = options[:sortable] || false
|
59
61
|
@infixes = options[:infixes] || false
|
60
62
|
@prefixes = options[:prefixes] || false
|
63
|
+
@file = options[:file] || false
|
64
|
+
@with = options[:with]
|
61
65
|
|
62
66
|
source.fields << self
|
63
67
|
end
|
@@ -78,5 +82,17 @@ module ThinkingSphinx
|
|
78
82
|
|
79
83
|
"#{clause} AS #{quote_column(unique_name)}"
|
80
84
|
end
|
85
|
+
|
86
|
+
def file?
|
87
|
+
@file
|
88
|
+
end
|
89
|
+
|
90
|
+
def with_attribute?
|
91
|
+
@with == :attribute
|
92
|
+
end
|
93
|
+
|
94
|
+
def with_wordcount?
|
95
|
+
@with == :wordcount
|
96
|
+
end
|
81
97
|
end
|
82
98
|
end
|
@@ -22,7 +22,7 @@ module ThinkingSphinx
|
|
22
22
|
undef_method method
|
23
23
|
}
|
24
24
|
|
25
|
-
HashOptions = [:conditions, :with, :without, :with_all]
|
25
|
+
HashOptions = [:conditions, :with, :without, :with_all, :without_any]
|
26
26
|
ArrayOptions = [:classes, :without_ids]
|
27
27
|
|
28
28
|
attr_reader :args, :options
|
@@ -474,9 +474,12 @@ module ThinkingSphinx
|
|
474
474
|
|
475
475
|
def match_hash(object)
|
476
476
|
@results[:matches].detect { |match|
|
477
|
+
class_crc = object.class.name
|
478
|
+
class_crc = object.class.to_crc32 if Riddle.loaded_version.to_i < 2
|
479
|
+
|
477
480
|
match[:attributes]['sphinx_internal_id'] == object.
|
478
481
|
primary_key_for_sphinx &&
|
479
|
-
match[:attributes][
|
482
|
+
match[:attributes][crc_attribute] == class_crc
|
480
483
|
}
|
481
484
|
end
|
482
485
|
|
@@ -714,6 +717,11 @@ module ThinkingSphinx
|
|
714
717
|
Array(values).collect { |value|
|
715
718
|
Riddle::Client::Filter.new attrib.to_s, filter_value(value)
|
716
719
|
}
|
720
|
+
}.flatten +
|
721
|
+
(options[:without_any] || {}).collect { |attrib, values|
|
722
|
+
Array(values).collect { |value|
|
723
|
+
Riddle::Client::Filter.new attrib.to_s, filter_value(value), true
|
724
|
+
}
|
717
725
|
}.flatten
|
718
726
|
end
|
719
727
|
|
@@ -869,7 +877,7 @@ module ThinkingSphinx
|
|
869
877
|
return single_class_results if one_class
|
870
878
|
|
871
879
|
groups = results[:matches].group_by { |match|
|
872
|
-
match[:attributes][
|
880
|
+
match[:attributes][crc_attribute]
|
873
881
|
}
|
874
882
|
groups.each do |crc, group|
|
875
883
|
group.replace(
|
@@ -879,7 +887,7 @@ module ThinkingSphinx
|
|
879
887
|
|
880
888
|
results[:matches].collect do |match|
|
881
889
|
groups.detect { |crc, group|
|
882
|
-
crc == match[:attributes][
|
890
|
+
crc == match[:attributes][crc_attribute]
|
883
891
|
}[1].compact.detect { |obj|
|
884
892
|
obj.primary_key_for_sphinx == match[:attributes]["sphinx_internal_id"]
|
885
893
|
}
|
@@ -891,7 +899,11 @@ module ThinkingSphinx
|
|
891
899
|
end
|
892
900
|
|
893
901
|
def class_from_crc(crc)
|
894
|
-
|
902
|
+
if Riddle.loaded_version.to_i < 2
|
903
|
+
config.models_by_crc[crc].constantize
|
904
|
+
else
|
905
|
+
crc.constantize
|
906
|
+
end
|
895
907
|
end
|
896
908
|
|
897
909
|
def each_with_attribute(attribute, &block)
|
@@ -944,5 +956,9 @@ module ThinkingSphinx
|
|
944
956
|
|
945
957
|
results_count
|
946
958
|
end
|
959
|
+
|
960
|
+
def crc_attribute
|
961
|
+
Riddle.loaded_version.to_i < 2 ? 'class_crc' : 'sphinx_internal_class'
|
962
|
+
end
|
947
963
|
end
|
948
964
|
end
|
@@ -45,6 +45,7 @@ module ThinkingSphinx
|
|
45
45
|
)
|
46
46
|
|
47
47
|
set_source_database_settings source
|
48
|
+
set_source_fields source
|
48
49
|
set_source_attributes source, offset
|
49
50
|
set_source_settings source
|
50
51
|
set_source_sql source, offset
|
@@ -59,6 +60,7 @@ module ThinkingSphinx
|
|
59
60
|
source.parent = "#{index.core_name}_#{position}"
|
60
61
|
|
61
62
|
set_source_database_settings source
|
63
|
+
set_source_fields source
|
62
64
|
set_source_attributes source, offset, true
|
63
65
|
set_source_settings source
|
64
66
|
set_source_sql source, offset, true
|
@@ -97,6 +99,14 @@ module ThinkingSphinx
|
|
97
99
|
source.sql_sock = config[:socket]
|
98
100
|
end
|
99
101
|
|
102
|
+
def set_source_fields(source)
|
103
|
+
fields.each do |field|
|
104
|
+
source.sql_file_field << field.unique_name if field.file?
|
105
|
+
source.sql_field_string << field.unique_name if field.with_attribute?
|
106
|
+
source.sql_field_str2wordcount << field.unique_name if field.with_wordcount?
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
100
110
|
def set_source_attributes(source, offset, delta = false)
|
101
111
|
available_attributes.each do |attrib|
|
102
112
|
source.send(attrib.type_to_config) << attrib.config_value(offset, delta)
|
@@ -4,10 +4,15 @@ module ThinkingSphinx
|
|
4
4
|
def add_internal_attributes_and_facets
|
5
5
|
add_internal_attribute :sphinx_internal_id, nil,
|
6
6
|
@model.primary_key_for_sphinx.to_sym
|
7
|
-
add_internal_attribute :class_crc, :integer, crc_column, true
|
8
7
|
add_internal_attribute :sphinx_deleted, :integer, "0"
|
9
|
-
|
10
|
-
|
8
|
+
add_internal_attribute :class_crc, :integer, crc_column, true
|
9
|
+
|
10
|
+
unless Riddle.loaded_version.to_i < 2
|
11
|
+
add_internal_attribute :sphinx_internal_class, :string, internal_class_column, true
|
12
|
+
add_internal_facet :sphinx_internal_class
|
13
|
+
else
|
14
|
+
add_internal_facet :class_crc
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
18
|
def add_internal_attribute(name, type, contents, facet = false)
|
@@ -59,7 +59,7 @@ GROUP BY #{ sql_group_clause }
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def sql_select_clause(offset)
|
62
|
-
unique_id_expr = ThinkingSphinx.unique_id_expression(offset)
|
62
|
+
unique_id_expr = ThinkingSphinx.unique_id_expression(adapter, offset)
|
63
63
|
|
64
64
|
(
|
65
65
|
["#{@model.quoted_table_name}.#{quote_column(@model.primary_key_for_sphinx)} #{unique_id_expr} AS #{quote_column(@model.primary_key_for_sphinx)} "] +
|
@@ -128,6 +128,15 @@ GROUP BY #{ sql_group_clause }
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
+
def internal_class_column
|
132
|
+
if @model.table_exists? &&
|
133
|
+
@model.column_names.include?(@model.inheritance_column)
|
134
|
+
adapter.quote_with_table(@model.inheritance_column)
|
135
|
+
else
|
136
|
+
"'#{@model.name}'"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
131
140
|
def type_values
|
132
141
|
@model.connection.select_values <<-SQL
|
133
142
|
SELECT DISTINCT #{@model.inheritance_column}
|
@@ -298,184 +298,176 @@ describe ThinkingSphinx::Attribute do
|
|
298
298
|
end
|
299
299
|
|
300
300
|
describe "MVA with source query" do
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
end
|
301
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
302
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
303
|
+
:as => :tag_ids, :source => :query)
|
304
|
+
}
|
305
|
+
let(:adapter) { attribute.send(:adapter) }
|
307
306
|
|
308
307
|
it "should use a query" do
|
309
|
-
|
308
|
+
attribute.type_to_config.should == :sql_attr_multi
|
310
309
|
|
311
|
-
declaration, query =
|
310
|
+
declaration, query = attribute.config_value.split('; ')
|
312
311
|
declaration.should == "uint tag_ids from query"
|
313
|
-
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags`"
|
312
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags`"
|
314
313
|
end
|
315
314
|
end
|
316
315
|
|
317
316
|
describe "MVA with source query for a delta source" do
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
end
|
317
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
318
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
319
|
+
:as => :tag_ids, :source => :query)
|
320
|
+
}
|
321
|
+
let(:adapter) { attribute.send(:adapter) }
|
324
322
|
|
325
323
|
it "should use a query" do
|
326
|
-
|
324
|
+
attribute.type_to_config.should == :sql_attr_multi
|
327
325
|
|
328
|
-
declaration, query =
|
326
|
+
declaration, query = attribute.config_value(nil, true).split('; ')
|
329
327
|
declaration.should == "uint tag_ids from query"
|
330
|
-
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` IN (SELECT `id` FROM `people` WHERE `people`.`delta` = 1)"
|
328
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` IN (SELECT `id` FROM `people` WHERE `people`.`delta` = 1)"
|
331
329
|
end
|
332
330
|
end
|
333
331
|
|
334
332
|
describe "MVA via a HABTM association with a source query" do
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
end
|
333
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
334
|
+
[ThinkingSphinx::Index::FauxColumn.new(:links, :id)],
|
335
|
+
:as => :link_ids, :source => :query)
|
336
|
+
}
|
337
|
+
let(:adapter) { attribute.send(:adapter) }
|
341
338
|
|
342
339
|
it "should use a ranged query" do
|
343
|
-
|
340
|
+
attribute.type_to_config.should == :sql_attr_multi
|
344
341
|
|
345
|
-
declaration, query =
|
342
|
+
declaration, query = attribute.config_value.split('; ')
|
346
343
|
declaration.should == "uint link_ids from query"
|
347
|
-
query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people`"
|
344
|
+
query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people`"
|
348
345
|
end
|
349
346
|
end
|
350
347
|
|
351
348
|
describe "MVA with ranged source query" do
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
end
|
349
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
350
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
351
|
+
:as => :tag_ids, :source => :ranged_query)
|
352
|
+
}
|
353
|
+
let(:adapter) { attribute.send(:adapter) }
|
358
354
|
|
359
355
|
it "should use a ranged query" do
|
360
|
-
|
356
|
+
attribute.type_to_config.should == :sql_attr_multi
|
361
357
|
|
362
|
-
declaration, query, range_query =
|
358
|
+
declaration, query, range_query = attribute.config_value.split('; ')
|
363
359
|
declaration.should == "uint tag_ids from ranged-query"
|
364
|
-
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
|
360
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
|
365
361
|
range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
|
366
362
|
end
|
367
363
|
end
|
368
364
|
|
369
365
|
describe "MVA with ranged source query for a delta source" do
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
end
|
366
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
367
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
368
|
+
:as => :tag_ids, :source => :ranged_query)
|
369
|
+
}
|
370
|
+
let(:adapter) { attribute.send(:adapter) }
|
376
371
|
|
377
372
|
it "should use a ranged query" do
|
378
|
-
|
373
|
+
attribute.type_to_config.should == :sql_attr_multi
|
379
374
|
|
380
|
-
declaration, query, range_query =
|
375
|
+
declaration, query, range_query = attribute.config_value(nil, true).split('; ')
|
381
376
|
declaration.should == "uint tag_ids from ranged-query"
|
382
|
-
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end AND `tags`.`person_id` IN (SELECT `id` FROM `people` WHERE `people`.`delta` = 1)"
|
377
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end AND `tags`.`person_id` IN (SELECT `id` FROM `people` WHERE `people`.`delta` = 1)"
|
383
378
|
range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
|
384
379
|
end
|
385
380
|
end
|
386
381
|
|
387
382
|
describe "MVA via a has-many :through with a ranged source query" do
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
end
|
383
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
384
|
+
[ThinkingSphinx::Index::FauxColumn.new(:football_teams, :id)],
|
385
|
+
:as => :football_team_ids, :source => :ranged_query)
|
386
|
+
}
|
387
|
+
let(:adapter) { attribute.send(:adapter) }
|
394
388
|
|
395
389
|
it "should use a ranged query" do
|
396
|
-
|
390
|
+
attribute.type_to_config.should == :sql_attr_multi
|
397
391
|
|
398
|
-
declaration, query, range_query =
|
392
|
+
declaration, query, range_query = attribute.config_value.split('; ')
|
399
393
|
declaration.should == "uint football_team_ids from ranged-query"
|
400
|
-
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`football_team_id` AS `football_team_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
|
394
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`football_team_id` AS `football_team_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
|
401
395
|
range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
|
402
396
|
end
|
403
397
|
end
|
404
398
|
|
405
399
|
describe "MVA via a has-many :through using a foreign key with a ranged source query" do
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
end
|
400
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
401
|
+
[ThinkingSphinx::Index::FauxColumn.new(:friends, :id)],
|
402
|
+
:as => :friend_ids, :source => :ranged_query)
|
403
|
+
}
|
404
|
+
let(:adapter) { attribute.send(:adapter) }
|
412
405
|
|
413
406
|
it "should use a ranged query" do
|
414
|
-
|
407
|
+
attribute.type_to_config.should == :sql_attr_multi
|
415
408
|
|
416
|
-
declaration, query, range_query =
|
409
|
+
declaration, query, range_query = attribute.config_value.split('; ')
|
417
410
|
declaration.should == "uint friend_ids from ranged-query"
|
418
|
-
query.should == "SELECT `friendships`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `friendships`.`friend_id` AS `friend_ids` FROM `friendships` WHERE `friendships`.`person_id` >= $start AND `friendships`.`person_id` <= $end"
|
411
|
+
query.should == "SELECT `friendships`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `friendships`.`friend_id` AS `friend_ids` FROM `friendships` WHERE `friendships`.`person_id` >= $start AND `friendships`.`person_id` <= $end"
|
419
412
|
range_query.should == "SELECT MIN(`friendships`.`person_id`), MAX(`friendships`.`person_id`) FROM `friendships`"
|
420
413
|
end
|
421
414
|
end
|
422
415
|
|
423
416
|
describe "MVA via a HABTM with a ranged source query" do
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
end
|
417
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
418
|
+
[ThinkingSphinx::Index::FauxColumn.new(:links, :id)],
|
419
|
+
:as => :link_ids, :source => :ranged_query)
|
420
|
+
}
|
421
|
+
let(:adapter) { attribute.send(:adapter) }
|
430
422
|
|
431
423
|
it "should use a ranged query" do
|
432
|
-
|
424
|
+
attribute.type_to_config.should == :sql_attr_multi
|
433
425
|
|
434
|
-
declaration, query, range_query =
|
426
|
+
declaration, query, range_query = attribute.config_value.split('; ')
|
435
427
|
declaration.should == "uint link_ids from ranged-query"
|
436
|
-
query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people` WHERE `links_people`.`person_id` >= $start AND `links_people`.`person_id` <= $end"
|
428
|
+
query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people` WHERE `links_people`.`person_id` >= $start AND `links_people`.`person_id` <= $end"
|
437
429
|
range_query.should == "SELECT MIN(`links_people`.`person_id`), MAX(`links_people`.`person_id`) FROM `links_people`"
|
438
430
|
end
|
439
431
|
end
|
440
432
|
|
441
433
|
describe "MVA via two has-many associations with a ranged source query" do
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
end
|
434
|
+
let(:index) { ThinkingSphinx::Index.new(Alpha) }
|
435
|
+
let(:source) { ThinkingSphinx::Source.new(index) }
|
436
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(source,
|
437
|
+
[ThinkingSphinx::Index::FauxColumn.new(:betas, :gammas, :value)],
|
438
|
+
:as => :gamma_values, :source => :ranged_query)
|
439
|
+
}
|
440
|
+
let(:adapter) { attribute.send(:adapter) }
|
450
441
|
|
451
442
|
it "should use a ranged query" do
|
452
|
-
|
443
|
+
attribute.type_to_config.should == :sql_attr_multi
|
453
444
|
|
454
|
-
declaration, query, range_query =
|
445
|
+
declaration, query, range_query = attribute.config_value.split('; ')
|
455
446
|
declaration.should == "uint gamma_values from ranged-query"
|
456
|
-
query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `gammas`.`value` AS `gamma_values` FROM `betas` LEFT OUTER JOIN `gammas` ON gammas.beta_id = betas.id WHERE `betas`.`alpha_id` >= $start AND `betas`.`alpha_id` <= $end"
|
447
|
+
query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `gammas`.`value` AS `gamma_values` FROM `betas` LEFT OUTER JOIN `gammas` ON gammas.beta_id = betas.id WHERE `betas`.`alpha_id` >= $start AND `betas`.`alpha_id` <= $end"
|
457
448
|
range_query.should == "SELECT MIN(`betas`.`alpha_id`), MAX(`betas`.`alpha_id`) FROM `betas`"
|
458
449
|
end
|
459
450
|
end
|
460
451
|
|
461
452
|
describe "MVA via two has-many associations with a ranged source query for a delta source" do
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
453
|
+
let(:index) { ThinkingSphinx::Index.new(Alpha) }
|
454
|
+
let(:source) { ThinkingSphinx::Source.new(index) }
|
455
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(source,
|
456
|
+
[ThinkingSphinx::Index::FauxColumn.new(:betas, :gammas, :value)],
|
457
|
+
:as => :gamma_values, :source => :ranged_query)
|
458
|
+
}
|
459
|
+
let(:adapter) { attribute.send(:adapter) }
|
469
460
|
|
470
|
-
|
461
|
+
before :each do
|
462
|
+
index.delta_object = ThinkingSphinx::Deltas::DefaultDelta.new index, index.local_options
|
471
463
|
end
|
472
464
|
|
473
465
|
it "should use a ranged query" do
|
474
|
-
|
466
|
+
attribute.type_to_config.should == :sql_attr_multi
|
475
467
|
|
476
|
-
declaration, query, range_query =
|
468
|
+
declaration, query, range_query = attribute.config_value(nil, true).split('; ')
|
477
469
|
declaration.should == "uint gamma_values from ranged-query"
|
478
|
-
query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `gammas`.`value` AS `gamma_values` FROM `betas` LEFT OUTER JOIN `gammas` ON gammas.beta_id = betas.id WHERE `betas`.`alpha_id` >= $start AND `betas`.`alpha_id` <= $end AND `betas`.`alpha_id` IN (SELECT `id` FROM `alphas` WHERE `alphas`.`delta` = 1)"
|
470
|
+
query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `gammas`.`value` AS `gamma_values` FROM `betas` LEFT OUTER JOIN `gammas` ON gammas.beta_id = betas.id WHERE `betas`.`alpha_id` >= $start AND `betas`.`alpha_id` <= $end AND `betas`.`alpha_id` IN (SELECT `id` FROM `alphas` WHERE `alphas`.`delta` = 1)"
|
479
471
|
range_query.should == "SELECT MIN(`betas`.`alpha_id`), MAX(`betas`.`alpha_id`) FROM `betas`"
|
480
472
|
end
|
481
473
|
end
|
@@ -46,6 +46,14 @@ describe ThinkingSphinx::AutoVersion do
|
|
46
46
|
ThinkingSphinx::AutoVersion.detect
|
47
47
|
end
|
48
48
|
|
49
|
+
it "should require 2.0.1 if using Sphinx 2.0.2 dev" do
|
50
|
+
ThinkingSphinx::AutoVersion.should_receive(:require).
|
51
|
+
with('riddle/2.0.1')
|
52
|
+
|
53
|
+
@config.stub!(:version => '2.0.2-dev')
|
54
|
+
ThinkingSphinx::AutoVersion.detect
|
55
|
+
end
|
56
|
+
|
49
57
|
it "should output a warning if the detected version is unsupported" do
|
50
58
|
STDERR.should_receive(:puts).with(/unsupported/i)
|
51
59
|
|
@@ -16,16 +16,22 @@ describe ThinkingSphinx::FacetSearch do
|
|
16
16
|
|
17
17
|
it "should request all shared facets in a multi-model request by default" do
|
18
18
|
ThinkingSphinx.stub!(:search => search)
|
19
|
-
|
19
|
+
if Riddle.loaded_version.to_i < 2
|
20
|
+
ThinkingSphinx::FacetSearch.new.facet_names.should == ['class_crc']
|
21
|
+
else
|
22
|
+
ThinkingSphinx::FacetSearch.new.facet_names.should == ['sphinx_internal_class']
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
it "should request all facets in a multi-model request if specified" do
|
23
27
|
ThinkingSphinx.stub!(:search => search)
|
24
|
-
ThinkingSphinx::FacetSearch.new(
|
25
|
-
|
26
|
-
|
27
|
-
'class_crc', 'city_facet', 'state_facet', 'birthday'
|
28
|
-
|
28
|
+
names = ThinkingSphinx::FacetSearch.new(:all_facets => true).facet_names
|
29
|
+
|
30
|
+
if Riddle.loaded_version.to_i < 2
|
31
|
+
names.should == ['class_crc', 'city_facet', 'state_facet', 'birthday']
|
32
|
+
else
|
33
|
+
names.should == ['sphinx_internal_class', 'city_facet', 'state_facet', 'birthday']
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
37
|
it "should use the system-set max_matches for limit on facet calls" do
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ThinkingSphinx::Index::Builder do
|
4
|
+
let(:internal_attribute_count) {
|
5
|
+
Riddle.loaded_version.to_i < 2 ? 3 : 4
|
6
|
+
}
|
4
7
|
describe ".generate without source scope" do
|
5
8
|
before :each do
|
6
9
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
@@ -31,10 +34,10 @@ describe ThinkingSphinx::Index::Builder do
|
|
31
34
|
@source.fields[1].unique_name.should == :last_name
|
32
35
|
end
|
33
36
|
|
34
|
-
it "should have two attributes alongside the
|
35
|
-
@source.attributes.length.should ==
|
36
|
-
@source.attributes[
|
37
|
-
@source.attributes[
|
37
|
+
it "should have two attributes alongside the internal ones" do
|
38
|
+
@source.attributes.length.should == 2 + internal_attribute_count
|
39
|
+
@source.attributes[internal_attribute_count].unique_name.should == :birthday
|
40
|
+
@source.attributes[1 + internal_attribute_count].unique_name.should == :internal_id
|
38
41
|
end
|
39
42
|
|
40
43
|
it "should have one condition" do
|
@@ -95,8 +98,8 @@ describe ThinkingSphinx::Index::Builder do
|
|
95
98
|
@source.fields.length.should == 1
|
96
99
|
end
|
97
100
|
|
98
|
-
it "should have one attribute alongside the
|
99
|
-
@source.attributes.length.should ==
|
101
|
+
it "should have one attribute alongside the internal ones" do
|
102
|
+
@source.attributes.length.should == 1 + internal_attribute_count
|
100
103
|
end
|
101
104
|
|
102
105
|
it "should set the attribute name to have the _sort suffix" do
|
@@ -142,8 +145,8 @@ describe ThinkingSphinx::Index::Builder do
|
|
142
145
|
@source.fields.length.should == 1
|
143
146
|
end
|
144
147
|
|
145
|
-
it "should have one attribute alongside the
|
146
|
-
@source.attributes.length.should ==
|
148
|
+
it "should have one attribute alongside the internal ones" do
|
149
|
+
@source.attributes.length.should == 1 + internal_attribute_count
|
147
150
|
end
|
148
151
|
|
149
152
|
it "should set the attribute name to have the _facet suffix" do
|
@@ -174,8 +177,8 @@ describe ThinkingSphinx::Index::Builder do
|
|
174
177
|
Alpha.sphinx_facets.delete_at(-1)
|
175
178
|
end
|
176
179
|
|
177
|
-
it "should have just one attribute alongside the
|
178
|
-
@source.attributes.length.should ==
|
180
|
+
it "should have just one attribute alongside the internal ones" do
|
181
|
+
@source.attributes.length.should == 1 + internal_attribute_count
|
179
182
|
end
|
180
183
|
end
|
181
184
|
|
@@ -193,8 +196,8 @@ describe ThinkingSphinx::Index::Builder do
|
|
193
196
|
Person.sphinx_facets.delete_at(-1)
|
194
197
|
end
|
195
198
|
|
196
|
-
it "should have just one attribute alongside the
|
197
|
-
@source.attributes.length.should ==
|
199
|
+
it "should have just one attribute alongside the internal ones" do
|
200
|
+
@source.attributes.length.should == 1 + internal_attribute_count
|
198
201
|
end
|
199
202
|
end
|
200
203
|
|
@@ -212,8 +215,8 @@ describe ThinkingSphinx::Index::Builder do
|
|
212
215
|
Beta.sphinx_facets.delete_at(-1)
|
213
216
|
end
|
214
217
|
|
215
|
-
it "should have just one attribute alongside the
|
216
|
-
@source.attributes.length.should ==
|
218
|
+
it "should have just one attribute alongside the internal ones" do
|
219
|
+
@source.attributes.length.should == 1 + internal_attribute_count
|
217
220
|
end
|
218
221
|
end
|
219
222
|
|
@@ -231,8 +234,8 @@ describe ThinkingSphinx::Index::Builder do
|
|
231
234
|
Alpha.sphinx_facets.delete_at(-1)
|
232
235
|
end
|
233
236
|
|
234
|
-
it "should have just one attribute alongside the
|
235
|
-
@source.attributes.length.should ==
|
237
|
+
it "should have just one attribute alongside the internal ones" do
|
238
|
+
@source.attributes.length.should == 1 + internal_attribute_count
|
236
239
|
end
|
237
240
|
end
|
238
241
|
|
@@ -250,8 +253,8 @@ describe ThinkingSphinx::Index::Builder do
|
|
250
253
|
Person.sphinx_facets.delete_at(-1)
|
251
254
|
end
|
252
255
|
|
253
|
-
it "should have two attributes alongside the
|
254
|
-
@source.attributes.length.should ==
|
256
|
+
it "should have two attributes alongside the internal ones" do
|
257
|
+
@source.attributes.length.should == 2 + internal_attribute_count
|
255
258
|
end
|
256
259
|
|
257
260
|
it "should set the facet attribute name to have the _facet suffix" do
|
@@ -282,8 +285,8 @@ describe ThinkingSphinx::Index::Builder do
|
|
282
285
|
Person.sphinx_facets.delete_at(-1)
|
283
286
|
end
|
284
287
|
|
285
|
-
it "should have two attributes alongside the
|
286
|
-
@source.attributes.length.should ==
|
288
|
+
it "should have two attributes alongside the internal ones" do
|
289
|
+
@source.attributes.length.should == 2 + internal_attribute_count
|
287
290
|
end
|
288
291
|
|
289
292
|
it "should set the facet attribute name to have the _facet suffix" do
|
@@ -321,8 +324,8 @@ describe ThinkingSphinx::Index::Builder do
|
|
321
324
|
@source.fields.length.should == 1
|
322
325
|
end
|
323
326
|
|
324
|
-
it "should have one attribute alongside the
|
325
|
-
@source.attributes.length.should ==
|
327
|
+
it "should have one attribute alongside the internal ones" do
|
328
|
+
@source.attributes.length.should == 1 + internal_attribute_count
|
326
329
|
end
|
327
330
|
|
328
331
|
it "should set the attribute name to have the _facet suffix" do
|
@@ -381,10 +384,10 @@ describe ThinkingSphinx::Index::Builder do
|
|
381
384
|
@source.fields[1].unique_name.should == :last_name
|
382
385
|
end
|
383
386
|
|
384
|
-
it "should have two attributes alongside the
|
385
|
-
@source.attributes.length.should ==
|
386
|
-
@source.attributes[
|
387
|
-
@source.attributes[
|
387
|
+
it "should have two attributes alongside the internal ones" do
|
388
|
+
@source.attributes.length.should == 2 + internal_attribute_count
|
389
|
+
@source.attributes[internal_attribute_count].unique_name.should == :birthday
|
390
|
+
@source.attributes[1 + internal_attribute_count].unique_name.should == :internal_id
|
388
391
|
end
|
389
392
|
end
|
390
393
|
|
@@ -418,12 +421,12 @@ describe ThinkingSphinx::Index::Builder do
|
|
418
421
|
end
|
419
422
|
|
420
423
|
it "should have two attributes alongside the six internal ones" do
|
421
|
-
@index.attributes.length.should ==
|
424
|
+
@index.attributes.length.should == 2 + (internal_attribute_count * 2)
|
422
425
|
end
|
423
426
|
|
424
|
-
it "should have one attribute in each source alongside the
|
427
|
+
it "should have one attribute in each source alongside the internal ones" do
|
425
428
|
@index.sources.each do |source|
|
426
|
-
source.attributes.length.should ==
|
429
|
+
source.attributes.length.should == 1 + internal_attribute_count
|
427
430
|
end
|
428
431
|
end
|
429
432
|
end
|
@@ -1135,10 +1135,11 @@ describe ThinkingSphinx::Search do
|
|
1135
1135
|
@client.stub! :query => {
|
1136
1136
|
:matches => [{
|
1137
1137
|
:attributes => {
|
1138
|
-
'sphinx_internal_id'
|
1139
|
-
'
|
1140
|
-
'
|
1141
|
-
'@
|
1138
|
+
'sphinx_internal_id' => @alpha.id,
|
1139
|
+
'sphinx_internal_class' => 'Alpha',
|
1140
|
+
'class_crc' => Alpha.to_crc32,
|
1141
|
+
'@groupby' => 101,
|
1142
|
+
'@count' => 5
|
1142
1143
|
}
|
1143
1144
|
}]
|
1144
1145
|
}
|
@@ -1172,8 +1173,9 @@ describe ThinkingSphinx::Search do
|
|
1172
1173
|
@client.stub! :query => {
|
1173
1174
|
:matches => [{
|
1174
1175
|
:attributes => {
|
1175
|
-
'sphinx_internal_id'
|
1176
|
-
'
|
1176
|
+
'sphinx_internal_id' => @alpha.id,
|
1177
|
+
'sphinx_internal_class' => 'Alpha',
|
1178
|
+
'class_crc' => Alpha.to_crc32
|
1177
1179
|
}, :weight => 12
|
1178
1180
|
}]
|
1179
1181
|
}
|
@@ -1197,11 +1199,12 @@ describe ThinkingSphinx::Search do
|
|
1197
1199
|
@client.stub! :query => {
|
1198
1200
|
:matches => [{
|
1199
1201
|
:attributes => {
|
1200
|
-
'sphinx_internal_id'
|
1201
|
-
'
|
1202
|
-
'
|
1203
|
-
'@
|
1204
|
-
'@
|
1202
|
+
'sphinx_internal_id' => @alpha.id,
|
1203
|
+
'sphinx_internal_class' => 'Alpha',
|
1204
|
+
'class_crc' => Alpha.to_crc32,
|
1205
|
+
'@geodist' => 101,
|
1206
|
+
'@groupby' => 102,
|
1207
|
+
'@count' => 103
|
1205
1208
|
}, :weight => 12
|
1206
1209
|
}]
|
1207
1210
|
}
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: thinking-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.4.
|
5
|
+
version: 1.4.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Pat Allan
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-25 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ">="
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 1.3.
|
37
|
+
version: 1.3.3
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: *id002
|
@@ -382,7 +382,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
382
382
|
requirements:
|
383
383
|
- - ">="
|
384
384
|
- !ruby/object:Gem::Version
|
385
|
-
hash:
|
385
|
+
hash: -3557249456082129398
|
386
386
|
segments:
|
387
387
|
- 0
|
388
388
|
version: "0"
|