freelancing-god-thinking-sphinx 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -145,3 +145,4 @@ Since I first released this library, there's been quite a few people who have su
145
145
  * Ole Riesenberg
146
146
  * Josh Kalderimis
147
147
  * J.D. Hollis
148
+ * Jeffrey Chupp
@@ -38,7 +38,7 @@ module ThinkingSphinx
38
38
  module Version #:nodoc:
39
39
  Major = 1
40
40
  Minor = 2
41
- Tiny = 1
41
+ Tiny = 2
42
42
 
43
43
  String = [Major, Minor, Tiny].join('.')
44
44
  end
@@ -13,6 +13,15 @@ module ThinkingSphinx
13
13
  base.class_eval do
14
14
  class_inheritable_array :sphinx_indexes, :sphinx_facets
15
15
  class << self
16
+
17
+ def set_sphinx_primary_key(attribute)
18
+ @sphinx_primary_key_attribute = attribute
19
+ end
20
+
21
+ def primary_key_for_sphinx
22
+ @sphinx_primary_key_attribute || primary_key
23
+ end
24
+
16
25
  # Allows creation of indexes for Sphinx. If you don't do this, there
17
26
  # isn't much point trying to search (or using this plugin at all,
18
27
  # really).
@@ -265,13 +274,18 @@ module ThinkingSphinx
265
274
  # nothing
266
275
  end
267
276
 
277
+ def primary_key_for_sphinx
278
+ self.send(self.class.primary_key_for_sphinx)
279
+ end
280
+
268
281
  def sphinx_document_id
269
- (self.id * ThinkingSphinx.indexed_models.size) +
282
+ key = self.class.primary_key_for_sphinx
283
+ self.attributes[key] * ThinkingSphinx.indexed_models.size +
270
284
  ThinkingSphinx.indexed_models.index(self.class.source_of_sphinx_index.name)
271
285
  end
272
-
286
+
273
287
  private
274
-
288
+
275
289
  def sphinx_index_name(suffix)
276
290
  "#{self.class.source_of_sphinx_index.name.underscore.tr(':/\\', '_')}_#{suffix}"
277
291
  end
@@ -8,6 +8,9 @@ module ThinkingSphinx
8
8
  module Deltas
9
9
  class DelayedDelta < ThinkingSphinx::Deltas::DefaultDelta
10
10
  def index(model, instance = nil)
11
+ return true unless ThinkingSphinx.updates_enabled? && ThinkingSphinx.deltas_enabled?
12
+ return true if instance && !toggled(instance)
13
+
11
14
  ThinkingSphinx::Deltas::Job.enqueue(
12
15
  ThinkingSphinx::Deltas::DeltaJob.new(delta_index_name(model)),
13
16
  ThinkingSphinx::Configuration.instance.delayed_job_priority
@@ -90,8 +90,9 @@ DESC
90
90
  end
91
91
 
92
92
  def rake(*tasks)
93
+ rails_env = fetch(:rails_env, "production")
93
94
  tasks.each do |t|
94
- run "cd #{current_path} && rake #{t} RAILS_ENV=production"
95
+ run "cd #{current_path} && rake #{t} RAILS_ENV=#{rails_env}"
95
96
  end
96
97
  end
97
98
  end
@@ -554,7 +554,7 @@ module ThinkingSphinx
554
554
  instances = ids.length > 0 ? klass.find(
555
555
  :all,
556
556
  :joins => options[:joins],
557
- :conditions => {klass.primary_key.to_sym => ids},
557
+ :conditions => {klass.primary_key_for_sphinx.to_sym => ids},
558
558
  :include => (options[:include] || index_options[:include]),
559
559
  :select => (options[:select] || index_options[:select]),
560
560
  :order => (options[:sql_order] || index_options[:sql_order])
@@ -564,7 +564,7 @@ module ThinkingSphinx
564
564
  # the search method can retry without them. See
565
565
  # ThinkingSphinx::Search.retry_search_on_stale_index.
566
566
  if options[:raise_on_stale] && instances.length < ids.length
567
- stale_ids = ids - instances.map {|i| i.id }
567
+ stale_ids = ids - instances.map { |i| i.id }
568
568
  raise StaleIdsException, stale_ids
569
569
  end
570
570
 
@@ -573,7 +573,9 @@ module ThinkingSphinx
573
573
  return instances if options[:sql_order]
574
574
 
575
575
  ids.collect { |obj_id|
576
- instances.detect { |obj| obj.id == obj_id }
576
+ instances.detect do |obj|
577
+ obj.primary_key_for_sphinx == obj_id
578
+ end
577
579
  }
578
580
  end
579
581
 
@@ -593,8 +595,8 @@ module ThinkingSphinx
593
595
  results[:matches].collect do |match|
594
596
  groups.detect { |crc, group|
595
597
  crc == match[:attributes]["class_crc"]
596
- }[1].detect { |obj|
597
- obj && obj.id == match[:attributes]["sphinx_internal_id"]
598
+ }[1].compact.detect { |obj|
599
+ obj.primary_key_for_sphinx == match[:attributes]["sphinx_internal_id"]
598
600
  }
599
601
  end
600
602
  end
@@ -2,7 +2,7 @@ module ThinkingSphinx
2
2
  class Source
3
3
  module InternalProperties
4
4
  def add_internal_attributes_and_facets
5
- add_internal_attribute :sphinx_internal_id, :integer, @model.primary_key.to_sym
5
+ add_internal_attribute :sphinx_internal_id, :integer, @model.primary_key_for_sphinx.to_sym
6
6
  add_internal_attribute :class_crc, :integer, crc_column, true
7
7
  add_internal_attribute :subclass_crcs, :multi, subclasses_to_s
8
8
  add_internal_attribute :sphinx_deleted, :integer, "0"
@@ -33,10 +33,10 @@ GROUP BY #{ sql_group_clause }
33
33
  return nil if @index.options[:disable_range]
34
34
 
35
35
  min_statement = adapter.convert_nulls(
36
- "MIN(#{quote_column(@model.primary_key)})", 1
36
+ "MIN(#{quote_column(@model.primary_key_for_sphinx)})", 1
37
37
  )
38
38
  max_statement = adapter.convert_nulls(
39
- "MAX(#{quote_column(@model.primary_key)})", 1
39
+ "MAX(#{quote_column(@model.primary_key_for_sphinx)})", 1
40
40
  )
41
41
 
42
42
  sql = "SELECT #{min_statement}, #{max_statement} " +
@@ -53,14 +53,14 @@ GROUP BY #{ sql_group_clause }
53
53
  #
54
54
  def to_sql_query_info(offset)
55
55
  "SELECT * FROM #{@model.quoted_table_name} WHERE " +
56
- "#{quote_column(@model.primary_key)} = (($id - #{offset}) / #{ThinkingSphinx.indexed_models.size})"
56
+ "#{quote_column(@model.primary_key_for_sphinx)} = (($id - #{offset}) / #{ThinkingSphinx.indexed_models.size})"
57
57
  end
58
58
 
59
59
  def sql_select_clause(offset)
60
60
  unique_id_expr = ThinkingSphinx.unique_id_expression(offset)
61
61
 
62
62
  (
63
- ["#{@model.quoted_table_name}.#{quote_column(@model.primary_key)} #{unique_id_expr} AS #{quote_column(@model.primary_key)} "] +
63
+ ["#{@model.quoted_table_name}.#{quote_column(@model.primary_key_for_sphinx)} #{unique_id_expr} AS #{quote_column(@model.primary_key_for_sphinx)} "] +
64
64
  @fields.collect { |field| field.to_select_sql } +
65
65
  @attributes.collect { |attribute| attribute.to_select_sql }
66
66
  ).compact.join(", ")
@@ -69,8 +69,8 @@ GROUP BY #{ sql_group_clause }
69
69
  def sql_where_clause(options)
70
70
  logic = []
71
71
  logic += [
72
- "#{@model.quoted_table_name}.#{quote_column(@model.primary_key)} >= $start",
73
- "#{@model.quoted_table_name}.#{quote_column(@model.primary_key)} <= $end"
72
+ "#{@model.quoted_table_name}.#{quote_column(@model.primary_key_for_sphinx)} >= $start",
73
+ "#{@model.quoted_table_name}.#{quote_column(@model.primary_key_for_sphinx)} <= $end"
74
74
  ] unless @index.options[:disable_range]
75
75
 
76
76
  if self.delta? && !@index.delta_object.clause(@model, options[:delta]).blank?
@@ -88,7 +88,7 @@ GROUP BY #{ sql_group_clause }
88
88
  end
89
89
 
90
90
  (
91
- ["#{@model.quoted_table_name}.#{quote_column(@model.primary_key)}"] +
91
+ ["#{@model.quoted_table_name}.#{quote_column(@model.primary_key_for_sphinx)}"] +
92
92
  @fields.collect { |field| field.to_group_sql }.compact +
93
93
  @attributes.collect { |attribute| attribute.to_group_sql }.compact +
94
94
  @groupings + internal_groupings
@@ -18,7 +18,7 @@ module Riddle #:nodoc:
18
18
  Rev = 1533
19
19
  # Release number to mark my own fixes, beyond feature parity with
20
20
  # Sphinx itself.
21
- Release = 5
21
+ Release = 7
22
22
 
23
23
  String = [Major, Minor, Tiny].join('.')
24
24
  GemVersion = [Major, Minor, Tiny, Rev, Release].join('.')
@@ -10,14 +10,15 @@ module Riddle
10
10
 
11
11
  # Append raw data (only use if you know what you're doing)
12
12
  def append(*args)
13
- return if args.length == 0
14
-
15
13
  args.each { |arg| @message << arg }
16
14
  end
17
15
 
18
16
  # Append a string's length, then the string itself
19
17
  def append_string(str)
20
- @message << [str.send(@size_method)].pack('N') + str
18
+ string = str.respond_to?(:force_encoding) ?
19
+ str.dup.force_encoding('ASCII-8BIT') : str
20
+
21
+ @message << [string.send(@size_method)].pack('N') + string
21
22
  end
22
23
 
23
24
  # Append an integer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freelancing-god-thinking-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
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-07-27 00:00:00 -07:00
12
+ date: 2009-07-30 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15