searchlogic 1.6.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/lib/searchlogic/active_record/base.rb +44 -48
- data/lib/searchlogic/version.rb +1 -1
- data/searchlogic.gemspec +2 -2
- metadata +2 -2
data/CHANGELOG.rdoc
CHANGED
@@ -104,6 +104,47 @@ module Searchlogic
|
|
104
104
|
end
|
105
105
|
|
106
106
|
private
|
107
|
+
def construct_finder_sql_with_included_associations_with_searchlogic(*args)
|
108
|
+
sql = construct_finder_sql_with_included_associations_without_searchlogic(*args)
|
109
|
+
remove_duplicate_joins(sql)
|
110
|
+
end
|
111
|
+
|
112
|
+
def construct_finder_sql_with_searchlogic(*args)
|
113
|
+
sql = construct_finder_sql_without_searchlogic(*args)
|
114
|
+
remove_duplicate_joins(sql)
|
115
|
+
end
|
116
|
+
|
117
|
+
def construct_calculation_sql_with_searchlogic(*args)
|
118
|
+
sql = construct_calculation_sql_without_searchlogic(*args)
|
119
|
+
remove_duplicate_joins(sql)
|
120
|
+
end
|
121
|
+
|
122
|
+
def remove_duplicate_joins(sql)
|
123
|
+
join_expr = /(LEFT OUTER JOIN|INNER JOIN)/i
|
124
|
+
sql_parts = sql.split(join_expr)
|
125
|
+
if !sql_parts.empty?
|
126
|
+
last_parts = sql_parts.pop.split(/ (?!ON|AS)([A-Z]+) /)
|
127
|
+
sql_parts += last_parts
|
128
|
+
is_join_statement = false
|
129
|
+
cleaned_parts = []
|
130
|
+
sql_parts.each do |part|
|
131
|
+
part = part.strip
|
132
|
+
if is_join_statement
|
133
|
+
if !cleaned_parts.include?(part)
|
134
|
+
cleaned_parts << part
|
135
|
+
else
|
136
|
+
cleaned_parts.pop
|
137
|
+
end
|
138
|
+
else
|
139
|
+
cleaned_parts << part
|
140
|
+
end
|
141
|
+
is_join_statement = part =~ join_expr
|
142
|
+
end
|
143
|
+
sql = cleaned_parts.join(" ")
|
144
|
+
end
|
145
|
+
sql
|
146
|
+
end
|
147
|
+
|
107
148
|
def filter_options_with_searchlogic(options = {}, searching = true)
|
108
149
|
return options unless Searchlogic::Search::Base.needed?(self, options)
|
109
150
|
search = Searchlogic::Search::Base.create_virtual_class(self).new # call explicitly to avoid merging the scopes into the search
|
@@ -153,6 +194,9 @@ module ActiveRecord #:nodoc: all
|
|
153
194
|
class Base
|
154
195
|
class << self
|
155
196
|
alias_method_chain :calculate, :searchlogic
|
197
|
+
alias_method_chain :construct_finder_sql, :searchlogic
|
198
|
+
alias_method_chain :construct_finder_sql_with_included_associations, :searchlogic
|
199
|
+
alias_method_chain :construct_calculation_sql, :searchlogic
|
156
200
|
alias_method_chain :find, :searchlogic
|
157
201
|
alias_method_chain :with_scope, :searchlogic
|
158
202
|
alias_method :new_search, :build_search
|
@@ -165,54 +209,6 @@ module ActiveRecord #:nodoc: all
|
|
165
209
|
def valid_calculations_options
|
166
210
|
Calculations::CALCULATIONS_OPTIONS
|
167
211
|
end
|
168
|
-
|
169
|
-
private
|
170
|
-
# This is copied over from 2 different versions of ActiveRecord. I have to do this in order to preserve the "auto joins"
|
171
|
-
# as symbols. Keeping them as symbols allows ActiveRecord to merge them properly. The problem is when they conflict with includes.
|
172
|
-
# Includes add joins also, and they add them before joins do. So if they already added them skip them. Now you can do queries like:
|
173
|
-
#
|
174
|
-
# User.all(:joins => {:orders => :line_items}, :include => :orders)
|
175
|
-
#
|
176
|
-
# Where as before, the only way to get the above query to work would be to include line_items also, which is not neccessarily what you want.
|
177
|
-
def add_joins!(sql, options_or_joins, scope = :auto) # :nodoc:
|
178
|
-
code_type = (respond_to?(:array_of_strings?, true) && :array_of_strings) || (respond_to?(:merge_joins, true) && :merge_joins)
|
179
|
-
|
180
|
-
case code_type
|
181
|
-
when :array_of_strings, :merge_joins
|
182
|
-
joins = options_or_joins
|
183
|
-
scope = scope(:find) if :auto == scope
|
184
|
-
merged_joins = scope && scope[:joins] && joins ? merge_joins(scope[:joins], joins) : (joins || scope && scope[:joins])
|
185
|
-
case merged_joins
|
186
|
-
when Symbol, Hash, Array
|
187
|
-
if code_type == :array_of_strings && array_of_strings?(merged_joins)
|
188
|
-
merged_joins.each { |merged_join| sql << " #{merged_join} " unless sql.include?(merged_join) }
|
189
|
-
else
|
190
|
-
join_dependency = ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, merged_joins, nil)
|
191
|
-
join_dependency.join_associations.each do |assoc|
|
192
|
-
join_sql = assoc.association_join
|
193
|
-
sql << " #{join_sql} " unless sql.include?(join_sql)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
when String
|
197
|
-
sql << " #{merged_joins} " if merged_joins && !sql.include?(merged_joins)
|
198
|
-
end
|
199
|
-
else
|
200
|
-
options = options_or_joins
|
201
|
-
scope = scope(:find) if :auto == scope
|
202
|
-
[(scope && scope[:joins]), options[:joins]].each do |join|
|
203
|
-
case join
|
204
|
-
when Symbol, Hash, Array
|
205
|
-
join_dependency = ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, join, nil)
|
206
|
-
join_dependency.join_associations.each do |assoc|
|
207
|
-
join_sql = assoc.association_join
|
208
|
-
sql << " #{join_sql} " unless sql.include?(join_sql)
|
209
|
-
end
|
210
|
-
else
|
211
|
-
sql << " #{join} " if join && !sql.include?(join)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
212
|
end
|
217
213
|
end
|
218
214
|
end
|
data/lib/searchlogic/version.rb
CHANGED
data/searchlogic.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{searchlogic}
|
5
|
-
s.version = "1.6.
|
5
|
+
s.version = "1.6.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ben Johnson of Binary Logic"]
|
9
|
-
s.date = %q{2008-12-
|
9
|
+
s.date = %q{2008-12-13}
|
10
10
|
s.description = %q{Object based ActiveRecord searching, ordering, pagination, and more!}
|
11
11
|
s.email = %q{bjohnson@binarylogic.com}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/searchlogic/active_record/associations.rb", "lib/searchlogic/active_record/base.rb", "lib/searchlogic/active_record/connection_adapters/mysql_adapter.rb", "lib/searchlogic/active_record/connection_adapters/postgresql_adapter.rb", "lib/searchlogic/active_record/connection_adapters/sqlite_adapter.rb", "lib/searchlogic/condition/base.rb", "lib/searchlogic/condition/begins_with.rb", "lib/searchlogic/condition/blank.rb", "lib/searchlogic/condition/child_of.rb", "lib/searchlogic/condition/descendant_of.rb", "lib/searchlogic/condition/ends_with.rb", "lib/searchlogic/condition/equals.rb", "lib/searchlogic/condition/greater_than.rb", "lib/searchlogic/condition/greater_than_or_equal_to.rb", "lib/searchlogic/condition/inclusive_descendant_of.rb", "lib/searchlogic/condition/keywords.rb", "lib/searchlogic/condition/less_than.rb", "lib/searchlogic/condition/less_than_or_equal_to.rb", "lib/searchlogic/condition/like.rb", "lib/searchlogic/condition/nested_set.rb", "lib/searchlogic/condition/nil.rb", "lib/searchlogic/condition/not_begin_with.rb", "lib/searchlogic/condition/not_blank.rb", "lib/searchlogic/condition/not_end_with.rb", "lib/searchlogic/condition/not_equal.rb", "lib/searchlogic/condition/not_have_keywords.rb", "lib/searchlogic/condition/not_like.rb", "lib/searchlogic/condition/not_nil.rb", "lib/searchlogic/condition/sibling_of.rb", "lib/searchlogic/conditions/any_or_all.rb", "lib/searchlogic/conditions/base.rb", "lib/searchlogic/conditions/groups.rb", "lib/searchlogic/conditions/magic_methods.rb", "lib/searchlogic/conditions/multiparameter_attributes.rb", "lib/searchlogic/conditions/protection.rb", "lib/searchlogic/config/helpers.rb", "lib/searchlogic/config/search.rb", "lib/searchlogic/config.rb", "lib/searchlogic/core_ext/hash.rb", "lib/searchlogic/core_ext/object.rb", "lib/searchlogic/helpers/control_types/link.rb", "lib/searchlogic/helpers/control_types/links.rb", "lib/searchlogic/helpers/control_types/remote_link.rb", "lib/searchlogic/helpers/control_types/remote_links.rb", "lib/searchlogic/helpers/control_types/remote_select.rb", "lib/searchlogic/helpers/control_types/select.rb", "lib/searchlogic/helpers/form.rb", "lib/searchlogic/helpers/utilities.rb", "lib/searchlogic/modifiers/absolute.rb", "lib/searchlogic/modifiers/acos.rb", "lib/searchlogic/modifiers/asin.rb", "lib/searchlogic/modifiers/atan.rb", "lib/searchlogic/modifiers/avg.rb", "lib/searchlogic/modifiers/base.rb", "lib/searchlogic/modifiers/ceil.rb", "lib/searchlogic/modifiers/char_length.rb", "lib/searchlogic/modifiers/cos.rb", "lib/searchlogic/modifiers/cot.rb", "lib/searchlogic/modifiers/count.rb", "lib/searchlogic/modifiers/day_of_month.rb", "lib/searchlogic/modifiers/day_of_week.rb", "lib/searchlogic/modifiers/day_of_year.rb", "lib/searchlogic/modifiers/degrees.rb", "lib/searchlogic/modifiers/exp.rb", "lib/searchlogic/modifiers/floor.rb", "lib/searchlogic/modifiers/hex.rb", "lib/searchlogic/modifiers/hour.rb", "lib/searchlogic/modifiers/log.rb", "lib/searchlogic/modifiers/log10.rb", "lib/searchlogic/modifiers/log2.rb", "lib/searchlogic/modifiers/lower.rb", "lib/searchlogic/modifiers/ltrim.rb", "lib/searchlogic/modifiers/md5.rb", "lib/searchlogic/modifiers/microseconds.rb", "lib/searchlogic/modifiers/milliseconds.rb", "lib/searchlogic/modifiers/minute.rb", "lib/searchlogic/modifiers/month.rb", "lib/searchlogic/modifiers/octal.rb", "lib/searchlogic/modifiers/radians.rb", "lib/searchlogic/modifiers/round.rb", "lib/searchlogic/modifiers/rtrim.rb", "lib/searchlogic/modifiers/second.rb", "lib/searchlogic/modifiers/sign.rb", "lib/searchlogic/modifiers/sin.rb", "lib/searchlogic/modifiers/square_root.rb", "lib/searchlogic/modifiers/sum.rb", "lib/searchlogic/modifiers/tan.rb", "lib/searchlogic/modifiers/trim.rb", "lib/searchlogic/modifiers/upper.rb", "lib/searchlogic/modifiers/week.rb", "lib/searchlogic/modifiers/year.rb", "lib/searchlogic/search/base.rb", "lib/searchlogic/search/conditions.rb", "lib/searchlogic/search/ordering.rb", "lib/searchlogic/search/pagination.rb", "lib/searchlogic/search/protection.rb", "lib/searchlogic/search/searching.rb", "lib/searchlogic/shared/utilities.rb", "lib/searchlogic/shared/virtual_classes.rb", "lib/searchlogic/version.rb", "lib/searchlogic.rb", "README.rdoc", "TODO.rdoc"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchlogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Johnson of Binary Logic
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-13 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|