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
data/Manifest.txt
DELETED
@@ -1,158 +0,0 @@
|
|
1
|
-
CHANGELOG.rdoc
|
2
|
-
MIT-LICENSE
|
3
|
-
Manifest.txt
|
4
|
-
README.rdoc
|
5
|
-
Rakefile
|
6
|
-
TODO.rdoc
|
7
|
-
init.rb
|
8
|
-
lib/searchlogic.rb
|
9
|
-
lib/searchlogic/active_record/associations.rb
|
10
|
-
lib/searchlogic/active_record/base.rb
|
11
|
-
lib/searchlogic/active_record/connection_adapters/mysql_adapter.rb
|
12
|
-
lib/searchlogic/active_record/connection_adapters/postgresql_adapter.rb
|
13
|
-
lib/searchlogic/active_record/connection_adapters/sqlite_adapter.rb
|
14
|
-
lib/searchlogic/condition/base.rb
|
15
|
-
lib/searchlogic/condition/begins_with.rb
|
16
|
-
lib/searchlogic/condition/blank.rb
|
17
|
-
lib/searchlogic/condition/child_of.rb
|
18
|
-
lib/searchlogic/condition/descendant_of.rb
|
19
|
-
lib/searchlogic/condition/ends_with.rb
|
20
|
-
lib/searchlogic/condition/equals.rb
|
21
|
-
lib/searchlogic/condition/greater_than.rb
|
22
|
-
lib/searchlogic/condition/greater_than_or_equal_to.rb
|
23
|
-
lib/searchlogic/condition/inclusive_descendant_of.rb
|
24
|
-
lib/searchlogic/condition/keywords.rb
|
25
|
-
lib/searchlogic/condition/less_than.rb
|
26
|
-
lib/searchlogic/condition/less_than_or_equal_to.rb
|
27
|
-
lib/searchlogic/condition/like.rb
|
28
|
-
lib/searchlogic/condition/nested_set.rb
|
29
|
-
lib/searchlogic/condition/nil.rb
|
30
|
-
lib/searchlogic/condition/not_begin_with.rb
|
31
|
-
lib/searchlogic/condition/not_blank.rb
|
32
|
-
lib/searchlogic/condition/not_end_with.rb
|
33
|
-
lib/searchlogic/condition/not_equal.rb
|
34
|
-
lib/searchlogic/condition/not_have_keywords.rb
|
35
|
-
lib/searchlogic/condition/not_like.rb
|
36
|
-
lib/searchlogic/condition/not_nil.rb
|
37
|
-
lib/searchlogic/condition/sibling_of.rb
|
38
|
-
lib/searchlogic/conditions/any_or_all.rb
|
39
|
-
lib/searchlogic/conditions/base.rb
|
40
|
-
lib/searchlogic/conditions/groups.rb
|
41
|
-
lib/searchlogic/conditions/magic_methods.rb
|
42
|
-
lib/searchlogic/conditions/multiparameter_attributes.rb
|
43
|
-
lib/searchlogic/conditions/protection.rb
|
44
|
-
lib/searchlogic/config.rb
|
45
|
-
lib/searchlogic/config/helpers.rb
|
46
|
-
lib/searchlogic/config/search.rb
|
47
|
-
lib/searchlogic/core_ext/hash.rb
|
48
|
-
lib/searchlogic/core_ext/object.rb
|
49
|
-
lib/searchlogic/helpers/control_types/link.rb
|
50
|
-
lib/searchlogic/helpers/control_types/links.rb
|
51
|
-
lib/searchlogic/helpers/control_types/remote_link.rb
|
52
|
-
lib/searchlogic/helpers/control_types/remote_links.rb
|
53
|
-
lib/searchlogic/helpers/control_types/remote_select.rb
|
54
|
-
lib/searchlogic/helpers/control_types/select.rb
|
55
|
-
lib/searchlogic/helpers/form.rb
|
56
|
-
lib/searchlogic/helpers/utilities.rb
|
57
|
-
lib/searchlogic/modifiers/absolute.rb
|
58
|
-
lib/searchlogic/modifiers/acos.rb
|
59
|
-
lib/searchlogic/modifiers/asin.rb
|
60
|
-
lib/searchlogic/modifiers/atan.rb
|
61
|
-
lib/searchlogic/modifiers/avg.rb
|
62
|
-
lib/searchlogic/modifiers/base.rb
|
63
|
-
lib/searchlogic/modifiers/ceil.rb
|
64
|
-
lib/searchlogic/modifiers/char_length.rb
|
65
|
-
lib/searchlogic/modifiers/cos.rb
|
66
|
-
lib/searchlogic/modifiers/cot.rb
|
67
|
-
lib/searchlogic/modifiers/count.rb
|
68
|
-
lib/searchlogic/modifiers/day_of_month.rb
|
69
|
-
lib/searchlogic/modifiers/day_of_week.rb
|
70
|
-
lib/searchlogic/modifiers/day_of_year.rb
|
71
|
-
lib/searchlogic/modifiers/degrees.rb
|
72
|
-
lib/searchlogic/modifiers/exp.rb
|
73
|
-
lib/searchlogic/modifiers/floor.rb
|
74
|
-
lib/searchlogic/modifiers/hex.rb
|
75
|
-
lib/searchlogic/modifiers/hour.rb
|
76
|
-
lib/searchlogic/modifiers/log.rb
|
77
|
-
lib/searchlogic/modifiers/log10.rb
|
78
|
-
lib/searchlogic/modifiers/log2.rb
|
79
|
-
lib/searchlogic/modifiers/lower.rb
|
80
|
-
lib/searchlogic/modifiers/ltrim.rb
|
81
|
-
lib/searchlogic/modifiers/md5.rb
|
82
|
-
lib/searchlogic/modifiers/microseconds.rb
|
83
|
-
lib/searchlogic/modifiers/milliseconds.rb
|
84
|
-
lib/searchlogic/modifiers/minute.rb
|
85
|
-
lib/searchlogic/modifiers/month.rb
|
86
|
-
lib/searchlogic/modifiers/octal.rb
|
87
|
-
lib/searchlogic/modifiers/radians.rb
|
88
|
-
lib/searchlogic/modifiers/round.rb
|
89
|
-
lib/searchlogic/modifiers/rtrim.rb
|
90
|
-
lib/searchlogic/modifiers/second.rb
|
91
|
-
lib/searchlogic/modifiers/sign.rb
|
92
|
-
lib/searchlogic/modifiers/sin.rb
|
93
|
-
lib/searchlogic/modifiers/square_root.rb
|
94
|
-
lib/searchlogic/modifiers/sum.rb
|
95
|
-
lib/searchlogic/modifiers/tan.rb
|
96
|
-
lib/searchlogic/modifiers/trim.rb
|
97
|
-
lib/searchlogic/modifiers/upper.rb
|
98
|
-
lib/searchlogic/modifiers/week.rb
|
99
|
-
lib/searchlogic/modifiers/year.rb
|
100
|
-
lib/searchlogic/search/base.rb
|
101
|
-
lib/searchlogic/search/conditions.rb
|
102
|
-
lib/searchlogic/search/ordering.rb
|
103
|
-
lib/searchlogic/search/pagination.rb
|
104
|
-
lib/searchlogic/search/protection.rb
|
105
|
-
lib/searchlogic/search/searching.rb
|
106
|
-
lib/searchlogic/shared/utilities.rb
|
107
|
-
lib/searchlogic/shared/virtual_classes.rb
|
108
|
-
lib/searchlogic/version.rb
|
109
|
-
test/active_record_tests/associations_test.rb
|
110
|
-
test/active_record_tests/base_test.rb
|
111
|
-
test/condition_tests/base_test.rb
|
112
|
-
test/condition_tests/begins_with_test.rb
|
113
|
-
test/condition_tests/blank_test.rb
|
114
|
-
test/condition_tests/child_of_test.rb
|
115
|
-
test/condition_tests/descendant_of_test.rb
|
116
|
-
test/condition_tests/ends_with_test.rb
|
117
|
-
test/condition_tests/equals_test.rb
|
118
|
-
test/condition_tests/greater_than_or_equal_to_test.rb
|
119
|
-
test/condition_tests/greater_than_test.rb
|
120
|
-
test/condition_tests/inclusive_descendant_of_test.rb
|
121
|
-
test/condition_tests/keywords_test.rb
|
122
|
-
test/condition_tests/less_than_or_equal_to_test.rb
|
123
|
-
test/condition_tests/less_than_test.rb
|
124
|
-
test/condition_tests/like_test.rb
|
125
|
-
test/condition_tests/nil_test.rb
|
126
|
-
test/condition_tests/not_begin_with_test.rb
|
127
|
-
test/condition_tests/not_blank_test.rb
|
128
|
-
test/condition_tests/not_end_with_test.rb
|
129
|
-
test/condition_tests/not_equal_test.rb
|
130
|
-
test/condition_tests/not_have_keywords_test.rb
|
131
|
-
test/condition_tests/not_like_test.rb
|
132
|
-
test/condition_tests/not_nil_test.rb
|
133
|
-
test/condition_tests/sibling_of_test.rb
|
134
|
-
test/conditions_tests/any_or_all_test.rb
|
135
|
-
test/conditions_tests/base_test.rb
|
136
|
-
test/conditions_tests/groups_test.rb
|
137
|
-
test/conditions_tests/magic_methods_test.rb
|
138
|
-
test/conditions_tests/multiparameter_attributes_test.rb
|
139
|
-
test/conditions_tests/protection_test.rb
|
140
|
-
test/config_test.rb
|
141
|
-
test/fixtures/accounts.yml
|
142
|
-
test/fixtures/animals.yml
|
143
|
-
test/fixtures/orders.yml
|
144
|
-
test/fixtures/user_groups.yml
|
145
|
-
test/fixtures/users.yml
|
146
|
-
test/libs/awesome_nested_set.rb
|
147
|
-
test/libs/awesome_nested_set/.autotest
|
148
|
-
test/libs/awesome_nested_set/compatability.rb
|
149
|
-
test/libs/awesome_nested_set/helper.rb
|
150
|
-
test/libs/awesome_nested_set/named_scope.rb
|
151
|
-
test/libs/rexml_fix.rb
|
152
|
-
test/modifier_tests/day_of_month_test.rb
|
153
|
-
test/search_tests/base_test.rb
|
154
|
-
test/search_tests/conditions_test.rb
|
155
|
-
test/search_tests/ordering_test.rb
|
156
|
-
test/search_tests/pagination_test.rb
|
157
|
-
test/search_tests/protection_test.rb
|
158
|
-
test/test_helper.rb
|
data/TODO.rdoc
DELETED
@@ -1,4 +0,0 @@
|
|
1
|
-
= To Do
|
2
|
-
|
3
|
-
1. Perform "more efficient" checks: year_of_created_at = 2008 and month_of_created_at = 8. Should result in a "BETWEEN" statement utilizing the column indexes. Thanks Georg for letting me know about this.
|
4
|
-
2. Solve conflicts between scope joins and joins in the search (for old versions of AR). Also solve conflicts between joins and includes.
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Searchlogic
|
2
|
-
module ActiveRecord
|
3
|
-
# = Searchlogic ActiveRecord Associations
|
4
|
-
#
|
5
|
-
# These methods hook into ActiveRecords association methods and add in searchlogic functionality.
|
6
|
-
module Associations
|
7
|
-
module AssociationCollection
|
8
|
-
# This needs to be implemented because AR doesn't leverage scopes with this method like it probably should
|
9
|
-
def find_with_searchlogic(*args)
|
10
|
-
options = args.extract_options!
|
11
|
-
args << filter_options_with_searchlogic(options)
|
12
|
-
find_without_searchlogic(*args)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
module HasManyAssociation
|
17
|
-
def count_with_searchlogic(*args)
|
18
|
-
options = args.extract_options!
|
19
|
-
args << filter_options_with_searchlogic(options)
|
20
|
-
count_without_searchlogic(*args)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
ActiveRecord::Associations::AssociationCollection.class_eval do
|
28
|
-
if respond_to?(:find)
|
29
|
-
include Searchlogic::ActiveRecord::Associations::AssociationCollection
|
30
|
-
alias_method_chain :find, :searchlogic
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
ActiveRecord::Associations::HasManyAssociation.class_eval do
|
35
|
-
include Searchlogic::ActiveRecord::Associations::HasManyAssociation
|
36
|
-
alias_method_chain :count, :searchlogic
|
37
|
-
|
38
|
-
# Older versions of AR have find in here, not in AssociationCollection
|
39
|
-
include Searchlogic::ActiveRecord::Associations::AssociationCollection
|
40
|
-
alias_method_chain :find, :searchlogic
|
41
|
-
end
|
42
|
-
|
43
|
-
ActiveRecord::Associations::ClassMethods::InnerJoinDependency::InnerJoinAssociation.class_eval do
|
44
|
-
private
|
45
|
-
# Inner joins impose limitations on queries. They can be quicker but you can't do OR conditions when conditions
|
46
|
-
# overlap from the base model to any of its associations. Also, inner joins won't allow you to order by an association
|
47
|
-
# attribute. What if the association is optional? All of those records are ommitted. It just doesn't make sense to default
|
48
|
-
# to inner joins when providing this as a "convenience" when searching. So let's change it.
|
49
|
-
def join_type
|
50
|
-
"LEFT OUTER JOIN"
|
51
|
-
end
|
52
|
-
end
|
@@ -1,224 +0,0 @@
|
|
1
|
-
module Searchlogic
|
2
|
-
# == Searchlogic ActiveRecord
|
3
|
-
#
|
4
|
-
# Hooks into ActiveRecord to add all of the searchlogic functionality into your models. Only uses what is publically available, doesn't dig into internals, and
|
5
|
-
# searchlogic only gets involved when needed.
|
6
|
-
module ActiveRecord
|
7
|
-
# = Searchlogic ActiveRecord Base
|
8
|
-
# Adds in base level functionality to ActiveRecord
|
9
|
-
module Base
|
10
|
-
# This is an alias method chain. It hook into ActiveRecord's "calculate" method and checks to see if Searchlogic should get involved.
|
11
|
-
def calculate_with_searchlogic(*args)
|
12
|
-
options = args.extract_options!
|
13
|
-
options = filter_options_with_searchlogic(options, false)
|
14
|
-
args << options
|
15
|
-
calculate_without_searchlogic(*args)
|
16
|
-
end
|
17
|
-
|
18
|
-
# This is an alias method chain. It hooks into ActiveRecord's "find" method and checks to see if Searchlogic should get involved.
|
19
|
-
def find_with_searchlogic(*args)
|
20
|
-
options = args.extract_options!
|
21
|
-
options = filter_options_with_searchlogic(options)
|
22
|
-
args << options
|
23
|
-
find_without_searchlogic(*args)
|
24
|
-
end
|
25
|
-
|
26
|
-
# This is an alias method chain. It hooks into ActiveRecord's scopes and checks to see if Searchlogic should get involved. Allowing you to use all of Searchlogics conditions and tools
|
27
|
-
# in scopes as well.
|
28
|
-
#
|
29
|
-
# === Examples
|
30
|
-
#
|
31
|
-
# Named scopes:
|
32
|
-
#
|
33
|
-
# named_scope :top_expensive, :conditions => {:total_gt => 1_000_000}, :per_page => 10
|
34
|
-
# named_scope :top_expensive_ordered, :conditions => {:total_gt => 1_000_000}, :per_page => 10, :order_by => {:user => :first_name}
|
35
|
-
#
|
36
|
-
# Good ole' regular scopes:
|
37
|
-
#
|
38
|
-
# with_scope(:find => {:conditions => {:total_gt => 1_000_000}, :per_page => 10}) do
|
39
|
-
# find(:all)
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
# with_scope(:find => {:conditions => {:total_gt => 1_000_000}, :per_page => 10}) do
|
43
|
-
# build_search
|
44
|
-
# end
|
45
|
-
def with_scope_with_searchlogic(method_scoping = {}, action = :merge, &block)
|
46
|
-
method_scoping[:find] = filter_options_with_searchlogic(method_scoping[:find]) if method_scoping[:find]
|
47
|
-
with_scope_without_searchlogic(method_scoping, action, &block)
|
48
|
-
end
|
49
|
-
|
50
|
-
# This is a special method that Searchlogic adds in. It returns a new search object on the model. So you can search via an object.
|
51
|
-
#
|
52
|
-
# <b>This method is "protected". Meaning it checks the passed options for SQL injections. So trying to write raw SQL in *any* of the option will result in a raised exception. It's safe to pass a params object when instantiating.</b>
|
53
|
-
#
|
54
|
-
# This method has an alias "new_search"
|
55
|
-
#
|
56
|
-
# === Examples
|
57
|
-
#
|
58
|
-
# search = User.new_search
|
59
|
-
# search.conditions.first_name_contains = "Ben"
|
60
|
-
# search.per_page = 20
|
61
|
-
# search.page = 2
|
62
|
-
# search.order_by = {:user_group => :name}
|
63
|
-
# search.all # can call any search method: first, find(:all), find(:first), sum("id"), etc...
|
64
|
-
def build_search(options = {}, &block)
|
65
|
-
search = searchlogic_search
|
66
|
-
search.protect = true
|
67
|
-
search.options = options
|
68
|
-
yield search if block_given?
|
69
|
-
search
|
70
|
-
end
|
71
|
-
|
72
|
-
# See build_search. This is the same method but *without* protection. Do *NOT* pass in a params object to this method.
|
73
|
-
#
|
74
|
-
# This also has an alias "new_search!"
|
75
|
-
def build_search!(options = {}, &block)
|
76
|
-
search = searchlogic_search(options)
|
77
|
-
yield search if block_given?
|
78
|
-
search
|
79
|
-
end
|
80
|
-
|
81
|
-
# Similar to ActiveRecord's attr_protected, but for conditions. It will block any conditions in this array that are being mass assigned. Mass assignments are:
|
82
|
-
#
|
83
|
-
# === Examples
|
84
|
-
#
|
85
|
-
# search = User.new_search(:conditions => {:first_name_like => "Ben", :email_contains => "binarylogic.com"})
|
86
|
-
# search.options = {:conditions => {:first_name_like => "Ben", :email_contains => "binarylogic.com"}}
|
87
|
-
#
|
88
|
-
# If first_name_like is in the list of conditions_protected then it will be removed from the hash.
|
89
|
-
def conditions_protected(*conditions)
|
90
|
-
write_inheritable_attribute(:conditions_protected, Set.new(conditions.map(&:to_s)) + (protected_conditions || []))
|
91
|
-
end
|
92
|
-
|
93
|
-
def protected_conditions # :nodoc:
|
94
|
-
read_inheritable_attribute(:conditions_protected)
|
95
|
-
end
|
96
|
-
|
97
|
-
# This is the reverse of conditions_protected. You can specify conditions here and *only* these conditions will be allowed in mass assignment. Any condition not specified here will be blocked.
|
98
|
-
def conditions_accessible(*conditions)
|
99
|
-
write_inheritable_attribute(:conditions_accessible, Set.new(conditions.map(&:to_s)) + (accessible_conditions || []))
|
100
|
-
end
|
101
|
-
|
102
|
-
def accessible_conditions # :nodoc:
|
103
|
-
read_inheritable_attribute(:conditions_accessible)
|
104
|
-
end
|
105
|
-
|
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 !includes_join?(cleaned_parts, 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
|
-
|
148
|
-
def includes_join?(cleaned_parts, part)
|
149
|
-
cleaned_parts.each do |cleaned_part|
|
150
|
-
a = cleaned_part.gsub("`", "")
|
151
|
-
b = part.gsub("`", "")
|
152
|
-
return true if a == b
|
153
|
-
return true if a == b.gsub(/([a-z\._]*) = ([a-z\._]*)/, '\2 = \1')
|
154
|
-
end
|
155
|
-
false
|
156
|
-
end
|
157
|
-
|
158
|
-
def filter_options_with_searchlogic(options = {}, searching = true)
|
159
|
-
return options unless Searchlogic::Search::Base.needed?(self, options)
|
160
|
-
search = Searchlogic::Search::Base.create_virtual_class(self).new # call explicitly to avoid merging the scopes into the search
|
161
|
-
search.acting_as_filter = true
|
162
|
-
search.scope = scope(:find)
|
163
|
-
conditions = options.delete(:conditions) || options.delete("conditions") || {}
|
164
|
-
if conditions
|
165
|
-
case conditions
|
166
|
-
when Hash
|
167
|
-
conditions.each { |condition, value| search.conditions.send("#{condition}=", value) } # explicitly call to enforce blanks
|
168
|
-
else
|
169
|
-
search.conditions = conditions
|
170
|
-
end
|
171
|
-
end
|
172
|
-
search.options = options
|
173
|
-
search.sanitize(searching)
|
174
|
-
end
|
175
|
-
|
176
|
-
def searchlogic_search(options = {})
|
177
|
-
scope = {}
|
178
|
-
current_scope = scope(:find) && scope(:find).deep_dup
|
179
|
-
if current_scope
|
180
|
-
[:conditions, :include, :joins].each do |option|
|
181
|
-
value = current_scope.delete(option)
|
182
|
-
next if value.blank?
|
183
|
-
scope[option] = value
|
184
|
-
end
|
185
|
-
|
186
|
-
# Delete nil values in the scope, for some reason habtm relationships like to pass :limit => nil
|
187
|
-
new_scope = {}
|
188
|
-
current_scope.each { |k, v| new_scope[k] = v unless v.nil? }
|
189
|
-
current_scope = new_scope
|
190
|
-
end
|
191
|
-
search = Searchlogic::Search::Base.create_virtual_class(self).new
|
192
|
-
search.scope = scope
|
193
|
-
search.options = current_scope
|
194
|
-
search.options = options
|
195
|
-
search
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
ActiveRecord::Base.send(:extend, Searchlogic::ActiveRecord::Base)
|
202
|
-
|
203
|
-
module ActiveRecord #:nodoc: all
|
204
|
-
class Base
|
205
|
-
class << self
|
206
|
-
alias_method_chain :calculate, :searchlogic
|
207
|
-
alias_method_chain :construct_finder_sql, :searchlogic
|
208
|
-
alias_method_chain :construct_finder_sql_with_included_associations, :searchlogic
|
209
|
-
alias_method_chain :construct_calculation_sql, :searchlogic
|
210
|
-
alias_method_chain :find, :searchlogic
|
211
|
-
alias_method_chain :with_scope, :searchlogic
|
212
|
-
alias_method :new_search, :build_search
|
213
|
-
alias_method :new_search!, :build_search!
|
214
|
-
|
215
|
-
def valid_find_options
|
216
|
-
VALID_FIND_OPTIONS
|
217
|
-
end
|
218
|
-
|
219
|
-
def valid_calculations_options
|
220
|
-
Calculations::CALCULATIONS_OPTIONS
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
@@ -1,176 +0,0 @@
|
|
1
|
-
module Searchlogic
|
2
|
-
module ActiveRecord
|
3
|
-
module ConnectionAdapters # :nodoc: all
|
4
|
-
module MysqlAdapter
|
5
|
-
# Date / time functions
|
6
|
-
def microseconds_sql(column_name)
|
7
|
-
"MICROSECOND(#{column_name})"
|
8
|
-
end
|
9
|
-
|
10
|
-
def milliseconds_sql(column_name)
|
11
|
-
"(MICROSECOND(#{column_name}) / 1000)"
|
12
|
-
end
|
13
|
-
|
14
|
-
def second_sql(column_name)
|
15
|
-
"SECOND(#{column_name})"
|
16
|
-
end
|
17
|
-
|
18
|
-
def minute_sql(column_name)
|
19
|
-
"MINUTE(#{column_name})"
|
20
|
-
end
|
21
|
-
|
22
|
-
def hour_sql(column_name)
|
23
|
-
"HOUR(#{column_name})"
|
24
|
-
end
|
25
|
-
|
26
|
-
def day_of_week_sql(column_name)
|
27
|
-
"DAYOFWEEK(#{column_name})"
|
28
|
-
end
|
29
|
-
|
30
|
-
def day_of_month_sql(column_name)
|
31
|
-
"DAYOFMONTH(#{column_name})"
|
32
|
-
end
|
33
|
-
|
34
|
-
def day_of_year_sql(column_name)
|
35
|
-
"DAYOFYEAR(#{column_name})"
|
36
|
-
end
|
37
|
-
|
38
|
-
def week_sql(column_name)
|
39
|
-
"WEEK(#{column_name}, 2)"
|
40
|
-
end
|
41
|
-
|
42
|
-
def month_sql(column_name)
|
43
|
-
"MONTH(#{column_name})"
|
44
|
-
end
|
45
|
-
|
46
|
-
def year_sql(column_name)
|
47
|
-
"YEAR(#{column_name})"
|
48
|
-
end
|
49
|
-
|
50
|
-
# String functions
|
51
|
-
def char_length_sql(column_name)
|
52
|
-
"CHAR_LENGTH(#{column_name})"
|
53
|
-
end
|
54
|
-
|
55
|
-
def lower_sql(column_name)
|
56
|
-
"LOWER(#{column_name})"
|
57
|
-
end
|
58
|
-
|
59
|
-
def ltrim_sql(column_name)
|
60
|
-
"LTRIM(#{column_name})"
|
61
|
-
end
|
62
|
-
|
63
|
-
def md5_sql(column_name)
|
64
|
-
"MD5(#{column_name})"
|
65
|
-
end
|
66
|
-
|
67
|
-
def rtrim_sql(column_name)
|
68
|
-
"RTRIM(#{column_name})"
|
69
|
-
end
|
70
|
-
|
71
|
-
def trim_sql(column_name)
|
72
|
-
"TRIM(#{column_name})"
|
73
|
-
end
|
74
|
-
|
75
|
-
def upper_sql(column_name)
|
76
|
-
"UPPER(#{column_name})"
|
77
|
-
end
|
78
|
-
|
79
|
-
# Number functions
|
80
|
-
def absolute_sql(column_name)
|
81
|
-
"ABS(#{column_name})"
|
82
|
-
end
|
83
|
-
|
84
|
-
def acos_sql(column_name)
|
85
|
-
"ACOS(#{column_name})"
|
86
|
-
end
|
87
|
-
|
88
|
-
def asin_sql(column_name)
|
89
|
-
"ASIN(#{column_name})"
|
90
|
-
end
|
91
|
-
|
92
|
-
def atan_sql(column_name)
|
93
|
-
"ATAN(#{column_name})"
|
94
|
-
end
|
95
|
-
|
96
|
-
def avg_sql(column_name)
|
97
|
-
"AVG(#{column_name})"
|
98
|
-
end
|
99
|
-
|
100
|
-
def ceil_sql(column_name)
|
101
|
-
"CEIL(#{column_name})"
|
102
|
-
end
|
103
|
-
|
104
|
-
def cos_sql(column_name)
|
105
|
-
"COS(#{column_name})"
|
106
|
-
end
|
107
|
-
|
108
|
-
def cot_sql(column_name)
|
109
|
-
"COT(#{column_name})"
|
110
|
-
end
|
111
|
-
|
112
|
-
def degrees_sql(column_name)
|
113
|
-
"DEGREES(#{column_name})"
|
114
|
-
end
|
115
|
-
|
116
|
-
def exp_sql(column_name)
|
117
|
-
"EXP(#{column_name})"
|
118
|
-
end
|
119
|
-
|
120
|
-
def floor_sql(column_name)
|
121
|
-
"FLOOR(#{column_name})"
|
122
|
-
end
|
123
|
-
|
124
|
-
def hex_sql(column_name)
|
125
|
-
"HEX(#{column_name})"
|
126
|
-
end
|
127
|
-
|
128
|
-
def ln_sql(column_name)
|
129
|
-
"LN(#{column_name})"
|
130
|
-
end
|
131
|
-
|
132
|
-
def log_sql(column_name)
|
133
|
-
"LOG(#{column_name})"
|
134
|
-
end
|
135
|
-
|
136
|
-
def log2_sql(column_name)
|
137
|
-
"LOG2(#{column_name})"
|
138
|
-
end
|
139
|
-
|
140
|
-
def log10_sql(column_name)
|
141
|
-
"LOG10(#{column_name})"
|
142
|
-
end
|
143
|
-
|
144
|
-
def octal_sql(column_name)
|
145
|
-
"OCT(#{column_name})"
|
146
|
-
end
|
147
|
-
|
148
|
-
def radians_sql(column_name)
|
149
|
-
"RADIANS(#{column_name})"
|
150
|
-
end
|
151
|
-
|
152
|
-
def round_sql(column_name)
|
153
|
-
"ROUND(#{column_name})"
|
154
|
-
end
|
155
|
-
|
156
|
-
def sign_sql(column_name)
|
157
|
-
"SIGN(#{column_name})"
|
158
|
-
end
|
159
|
-
|
160
|
-
def sin_sql(column_name)
|
161
|
-
"SIN(#{column_name})"
|
162
|
-
end
|
163
|
-
|
164
|
-
def square_root_sql(column_name)
|
165
|
-
"SQRT(#{column_name})"
|
166
|
-
end
|
167
|
-
|
168
|
-
def tan_sql(column_name)
|
169
|
-
"TAN(#{column_name})"
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
::ActiveRecord::ConnectionAdapters::MysqlAdapter.send(:include, Searchlogic::ActiveRecord::ConnectionAdapters::MysqlAdapter)
|