searchlogic 1.6.6 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/CHANGELOG.rdoc +17 -0
- data/{MIT-LICENSE → LICENSE} +2 -2
- data/README.rdoc +128 -379
- data/Rakefile +56 -20
- data/VERSION.yml +4 -0
- data/init.rb +1 -1
- data/lib/searchlogic.rb +18 -98
- data/lib/searchlogic/core_ext/object.rb +33 -13
- data/lib/searchlogic/core_ext/proc.rb +11 -0
- data/lib/searchlogic/named_scopes/alias_scope.rb +63 -0
- data/lib/searchlogic/named_scopes/associations.rb +126 -0
- data/lib/searchlogic/named_scopes/conditions.rb +215 -0
- data/lib/searchlogic/named_scopes/ordering.rb +53 -0
- data/lib/searchlogic/rails_helpers.rb +69 -0
- data/lib/searchlogic/search.rb +146 -0
- data/rails/init.rb +1 -0
- data/searchlogic.gemspec +69 -0
- data/spec/core_ext/object_spec.rb +7 -0
- data/spec/core_ext/proc_spec.rb +9 -0
- data/spec/named_scopes/alias_scope_spec.rb +15 -0
- data/spec/named_scopes/associations_spec.rb +120 -0
- data/spec/named_scopes/conditions_spec.rb +253 -0
- data/spec/named_scopes/ordering_spec.rb +23 -0
- data/spec/search_spec.rb +283 -0
- data/spec/spec_helper.rb +78 -0
- metadata +40 -231
- data/Manifest.txt +0 -158
- data/TODO.rdoc +0 -4
- data/lib/searchlogic/active_record/associations.rb +0 -52
- data/lib/searchlogic/active_record/base.rb +0 -224
- data/lib/searchlogic/active_record/connection_adapters/mysql_adapter.rb +0 -176
- data/lib/searchlogic/active_record/connection_adapters/postgresql_adapter.rb +0 -172
- data/lib/searchlogic/active_record/connection_adapters/sqlite_adapter.rb +0 -80
- data/lib/searchlogic/condition/base.rb +0 -165
- data/lib/searchlogic/condition/begins_with.rb +0 -17
- data/lib/searchlogic/condition/blank.rb +0 -24
- data/lib/searchlogic/condition/child_of.rb +0 -11
- data/lib/searchlogic/condition/descendant_of.rb +0 -11
- data/lib/searchlogic/condition/ends_with.rb +0 -17
- data/lib/searchlogic/condition/equals.rb +0 -33
- data/lib/searchlogic/condition/greater_than.rb +0 -15
- data/lib/searchlogic/condition/greater_than_or_equal_to.rb +0 -15
- data/lib/searchlogic/condition/inclusive_descendant_of.rb +0 -10
- data/lib/searchlogic/condition/keywords.rb +0 -52
- data/lib/searchlogic/condition/less_than.rb +0 -15
- data/lib/searchlogic/condition/less_than_or_equal_to.rb +0 -15
- data/lib/searchlogic/condition/like.rb +0 -15
- data/lib/searchlogic/condition/nested_set.rb +0 -17
- data/lib/searchlogic/condition/nil.rb +0 -21
- data/lib/searchlogic/condition/not_begin_with.rb +0 -20
- data/lib/searchlogic/condition/not_blank.rb +0 -19
- data/lib/searchlogic/condition/not_end_with.rb +0 -20
- data/lib/searchlogic/condition/not_equal.rb +0 -27
- data/lib/searchlogic/condition/not_have_keywords.rb +0 -20
- data/lib/searchlogic/condition/not_like.rb +0 -20
- data/lib/searchlogic/condition/not_nil.rb +0 -19
- data/lib/searchlogic/condition/sibling_of.rb +0 -14
- data/lib/searchlogic/conditions/any_or_all.rb +0 -42
- data/lib/searchlogic/conditions/base.rb +0 -244
- data/lib/searchlogic/conditions/groups.rb +0 -74
- data/lib/searchlogic/conditions/magic_methods.rb +0 -286
- data/lib/searchlogic/conditions/multiparameter_attributes.rb +0 -105
- data/lib/searchlogic/conditions/protection.rb +0 -36
- data/lib/searchlogic/config.rb +0 -31
- data/lib/searchlogic/config/helpers.rb +0 -338
- data/lib/searchlogic/config/search.rb +0 -53
- data/lib/searchlogic/core_ext/hash.rb +0 -75
- data/lib/searchlogic/helpers/control_types/link.rb +0 -310
- data/lib/searchlogic/helpers/control_types/links.rb +0 -242
- data/lib/searchlogic/helpers/control_types/remote_link.rb +0 -87
- data/lib/searchlogic/helpers/control_types/remote_links.rb +0 -72
- data/lib/searchlogic/helpers/control_types/remote_select.rb +0 -36
- data/lib/searchlogic/helpers/control_types/select.rb +0 -82
- data/lib/searchlogic/helpers/form.rb +0 -208
- data/lib/searchlogic/helpers/utilities.rb +0 -197
- data/lib/searchlogic/modifiers/absolute.rb +0 -15
- data/lib/searchlogic/modifiers/acos.rb +0 -11
- data/lib/searchlogic/modifiers/asin.rb +0 -11
- data/lib/searchlogic/modifiers/atan.rb +0 -11
- data/lib/searchlogic/modifiers/avg.rb +0 -15
- data/lib/searchlogic/modifiers/base.rb +0 -27
- data/lib/searchlogic/modifiers/ceil.rb +0 -15
- data/lib/searchlogic/modifiers/char_length.rb +0 -15
- data/lib/searchlogic/modifiers/cos.rb +0 -15
- data/lib/searchlogic/modifiers/cot.rb +0 -15
- data/lib/searchlogic/modifiers/count.rb +0 -11
- data/lib/searchlogic/modifiers/day_of_month.rb +0 -15
- data/lib/searchlogic/modifiers/day_of_week.rb +0 -15
- data/lib/searchlogic/modifiers/day_of_year.rb +0 -15
- data/lib/searchlogic/modifiers/degrees.rb +0 -11
- data/lib/searchlogic/modifiers/exp.rb +0 -15
- data/lib/searchlogic/modifiers/floor.rb +0 -15
- data/lib/searchlogic/modifiers/hex.rb +0 -11
- data/lib/searchlogic/modifiers/hour.rb +0 -11
- data/lib/searchlogic/modifiers/log.rb +0 -15
- data/lib/searchlogic/modifiers/log10.rb +0 -11
- data/lib/searchlogic/modifiers/log2.rb +0 -11
- data/lib/searchlogic/modifiers/lower.rb +0 -15
- data/lib/searchlogic/modifiers/ltrim.rb +0 -15
- data/lib/searchlogic/modifiers/md5.rb +0 -11
- data/lib/searchlogic/modifiers/microseconds.rb +0 -11
- data/lib/searchlogic/modifiers/milliseconds.rb +0 -11
- data/lib/searchlogic/modifiers/minute.rb +0 -15
- data/lib/searchlogic/modifiers/month.rb +0 -15
- data/lib/searchlogic/modifiers/octal.rb +0 -15
- data/lib/searchlogic/modifiers/radians.rb +0 -11
- data/lib/searchlogic/modifiers/round.rb +0 -11
- data/lib/searchlogic/modifiers/rtrim.rb +0 -15
- data/lib/searchlogic/modifiers/second.rb +0 -15
- data/lib/searchlogic/modifiers/sign.rb +0 -11
- data/lib/searchlogic/modifiers/sin.rb +0 -11
- data/lib/searchlogic/modifiers/square_root.rb +0 -15
- data/lib/searchlogic/modifiers/sum.rb +0 -11
- data/lib/searchlogic/modifiers/tan.rb +0 -15
- data/lib/searchlogic/modifiers/trim.rb +0 -15
- data/lib/searchlogic/modifiers/upper.rb +0 -15
- data/lib/searchlogic/modifiers/week.rb +0 -11
- data/lib/searchlogic/modifiers/year.rb +0 -11
- data/lib/searchlogic/search/base.rb +0 -148
- data/lib/searchlogic/search/conditions.rb +0 -53
- data/lib/searchlogic/search/ordering.rb +0 -244
- data/lib/searchlogic/search/pagination.rb +0 -121
- data/lib/searchlogic/search/protection.rb +0 -89
- data/lib/searchlogic/search/searching.rb +0 -32
- data/lib/searchlogic/shared/utilities.rb +0 -57
- data/lib/searchlogic/shared/virtual_classes.rb +0 -39
- data/lib/searchlogic/version.rb +0 -79
- data/test/active_record_tests/associations_test.rb +0 -94
- data/test/active_record_tests/base_test.rb +0 -115
- data/test/condition_tests/base_test.rb +0 -62
- data/test/condition_tests/begins_with_test.rb +0 -11
- data/test/condition_tests/blank_test.rb +0 -31
- data/test/condition_tests/child_of_test.rb +0 -17
- data/test/condition_tests/descendant_of_test.rb +0 -12
- data/test/condition_tests/ends_with_test.rb +0 -11
- data/test/condition_tests/equals_test.rb +0 -28
- data/test/condition_tests/greater_than_or_equal_to_test.rb +0 -11
- data/test/condition_tests/greater_than_test.rb +0 -11
- data/test/condition_tests/inclusive_descendant_of_test.rb +0 -12
- data/test/condition_tests/keywords_test.rb +0 -23
- data/test/condition_tests/less_than_or_equal_to_test.rb +0 -11
- data/test/condition_tests/less_than_test.rb +0 -11
- data/test/condition_tests/like_test.rb +0 -11
- data/test/condition_tests/nil_test.rb +0 -31
- data/test/condition_tests/not_begin_with_test.rb +0 -8
- data/test/condition_tests/not_blank_test.rb +0 -8
- data/test/condition_tests/not_end_with_test.rb +0 -8
- data/test/condition_tests/not_equal_test.rb +0 -19
- data/test/condition_tests/not_have_keywords_test.rb +0 -8
- data/test/condition_tests/not_like_test.rb +0 -8
- data/test/condition_tests/not_nil_test.rb +0 -13
- data/test/condition_tests/sibling_of_test.rb +0 -15
- data/test/conditions_tests/any_or_all_test.rb +0 -23
- data/test/conditions_tests/base_test.rb +0 -185
- data/test/conditions_tests/groups_test.rb +0 -68
- data/test/conditions_tests/magic_methods_test.rb +0 -36
- data/test/conditions_tests/multiparameter_attributes_test.rb +0 -15
- data/test/conditions_tests/protection_test.rb +0 -18
- data/test/config_test.rb +0 -23
- data/test/fixtures/accounts.yml +0 -12
- data/test/fixtures/animals.yml +0 -7
- data/test/fixtures/orders.yml +0 -12
- data/test/fixtures/user_groups.yml +0 -5
- data/test/fixtures/users.yml +0 -45
- data/test/libs/awesome_nested_set.rb +0 -545
- data/test/libs/awesome_nested_set/.autotest +0 -13
- data/test/libs/awesome_nested_set/compatability.rb +0 -29
- data/test/libs/awesome_nested_set/helper.rb +0 -40
- data/test/libs/awesome_nested_set/named_scope.rb +0 -140
- data/test/libs/rexml_fix.rb +0 -14
- data/test/modifier_tests/day_of_month_test.rb +0 -16
- data/test/search_tests/base_test.rb +0 -241
- data/test/search_tests/conditions_test.rb +0 -21
- data/test/search_tests/ordering_test.rb +0 -167
- data/test/search_tests/pagination_test.rb +0 -74
- data/test/search_tests/protection_test.rb +0 -26
- data/test/test_helper.rb +0 -122
@@ -1,148 +0,0 @@
|
|
1
|
-
module Searchlogic #:nodoc:
|
2
|
-
module Search #:nodoc:
|
3
|
-
# = Searchlogic
|
4
|
-
#
|
5
|
-
# Please refer the README.rdoc for usage, examples, and installation.
|
6
|
-
class Base
|
7
|
-
include Searchlogic::Shared::Utilities
|
8
|
-
include Searchlogic::Shared::VirtualClasses
|
9
|
-
|
10
|
-
# Options ActiveRecord allows when searching
|
11
|
-
AR_FIND_OPTIONS = ::ActiveRecord::Base.valid_find_options
|
12
|
-
|
13
|
-
# Options ActiveRecord allows when performing calculations
|
14
|
-
AR_CALCULATIONS_OPTIONS = (::ActiveRecord::Base.valid_calculations_options - [:select, :limit, :offset, :order, :group, :include])
|
15
|
-
|
16
|
-
AR_OPTIONS = (AR_FIND_OPTIONS + AR_CALCULATIONS_OPTIONS).uniq
|
17
|
-
|
18
|
-
# Options that ActiveRecord doesn't suppport, but Searchlogic does
|
19
|
-
SPECIAL_FIND_OPTIONS = [:order_by, :order_as, :page, :per_page, :priority_order, :priority_order_by, :priority_order_as]
|
20
|
-
|
21
|
-
# Valid options you can use when searching
|
22
|
-
OPTIONS = SPECIAL_FIND_OPTIONS + AR_OPTIONS # the order is very important, these options get set in this order
|
23
|
-
|
24
|
-
attr_accessor *AR_OPTIONS
|
25
|
-
attr_writer :scope
|
26
|
-
|
27
|
-
class << self
|
28
|
-
# Used in the ActiveRecord methods to determine if Searchlogic should get involved or not.
|
29
|
-
# This keeps Searchlogic out of the way unless it is needed.
|
30
|
-
def needed?(model_class, options)
|
31
|
-
return false if options.blank?
|
32
|
-
|
33
|
-
SPECIAL_FIND_OPTIONS.each do |option|
|
34
|
-
return true if options.symbolize_keys.keys.include?(option)
|
35
|
-
end
|
36
|
-
|
37
|
-
Searchlogic::Conditions::Base.needed?(model_class, options[:conditions])
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def initialize(init_options = {})
|
42
|
-
self.options = init_options
|
43
|
-
end
|
44
|
-
|
45
|
-
# Flag to determine if searchlogic is acting as a filter for the ActiveRecord search methods.
|
46
|
-
# By filter it means that searchlogic is being used on the default ActiveRecord search methods, like all, count, find(:all), first, etc.
|
47
|
-
def acting_as_filter=(value)
|
48
|
-
@acting_as_filter = value
|
49
|
-
end
|
50
|
-
|
51
|
-
# See acting_as_filter=
|
52
|
-
def acting_as_filter?
|
53
|
-
@acting_as_filter == true
|
54
|
-
end
|
55
|
-
|
56
|
-
# Specific implementation of cloning
|
57
|
-
def clone
|
58
|
-
options = {}
|
59
|
-
(AR_OPTIONS - [:conditions]).each { |option| options[option] = instance_variable_get("@#{option}") }
|
60
|
-
options[:conditions] = conditions.conditions
|
61
|
-
SPECIAL_FIND_OPTIONS.each { |option| options[option] = send(option) }
|
62
|
-
obj = self.class.new(options)
|
63
|
-
obj.protect = protected?
|
64
|
-
obj.scope = scope
|
65
|
-
obj
|
66
|
-
end
|
67
|
-
alias_method :dup, :clone
|
68
|
-
|
69
|
-
# Makes using searchlogic in the console less annoying and keeps the output meaningful and useful
|
70
|
-
def inspect
|
71
|
-
current_find_options = {}
|
72
|
-
(AR_OPTIONS - [:conditions]).each do |option|
|
73
|
-
value = send(option)
|
74
|
-
next if value.nil?
|
75
|
-
current_find_options[option] = value
|
76
|
-
end
|
77
|
-
conditions_value = conditions.conditions
|
78
|
-
current_find_options[:conditions] = conditions_value unless conditions_value.blank?
|
79
|
-
current_find_options[:scope] = scope unless scope.blank?
|
80
|
-
"#<#{klass}Search #{current_find_options.inspect}>"
|
81
|
-
end
|
82
|
-
|
83
|
-
# Merges all joins together, including the scopes joins for
|
84
|
-
def joins
|
85
|
-
all_joins = (safe_to_array(conditions.auto_joins) + safe_to_array(order_by_auto_joins) + safe_to_array(priority_order_by_auto_joins) + safe_to_array(@joins)).uniq
|
86
|
-
all_joins.size <= 1 ? all_joins.first : all_joins
|
87
|
-
end
|
88
|
-
|
89
|
-
def limit=(value)
|
90
|
-
@set_limit = true
|
91
|
-
@limit = value.blank? || value == 0 ? nil : value.to_i
|
92
|
-
end
|
93
|
-
|
94
|
-
def limit
|
95
|
-
@limit ||= Config.search.per_page if !acting_as_filter? && !@set_limit
|
96
|
-
@limit
|
97
|
-
end
|
98
|
-
|
99
|
-
def offset=(value)
|
100
|
-
@offset = value.blank? ? nil : value.to_i
|
101
|
-
end
|
102
|
-
|
103
|
-
def options=(values)
|
104
|
-
return unless values.is_a?(Hash)
|
105
|
-
values.symbolize_keys.fast_assert_valid_keys(OPTIONS)
|
106
|
-
values.each { |key, value| send("#{key}=", value) }
|
107
|
-
end
|
108
|
-
|
109
|
-
# Sanitizes everything down into options ActiveRecord::Base.find can understand
|
110
|
-
def sanitize(searching = true)
|
111
|
-
find_options = {}
|
112
|
-
|
113
|
-
(searching ? AR_FIND_OPTIONS : AR_CALCULATIONS_OPTIONS).each do |find_option|
|
114
|
-
value = send(find_option)
|
115
|
-
next if value.blank?
|
116
|
-
find_options[find_option] = value
|
117
|
-
end
|
118
|
-
|
119
|
-
find_options
|
120
|
-
end
|
121
|
-
|
122
|
-
def select
|
123
|
-
@select ||= "DISTINCT #{klass.connection.quote_table_name(klass.table_name)}.*" if !joins.blank? && Config.search.remove_duplicates? && klass.connection.adapter_name != "PostgreSQL"
|
124
|
-
@select
|
125
|
-
end
|
126
|
-
|
127
|
-
def scope
|
128
|
-
@scope ||= {}
|
129
|
-
end
|
130
|
-
|
131
|
-
private
|
132
|
-
def safe_to_array(o)
|
133
|
-
case o
|
134
|
-
when NilClass
|
135
|
-
[]
|
136
|
-
when Array
|
137
|
-
o
|
138
|
-
else
|
139
|
-
[o]
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def array_of_strings?(o)
|
144
|
-
o.is_a?(Array) && o.all?{|obj| obj.is_a?(String)}
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|