searchgasm 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +8 -0
- data/Manifest +42 -3
- data/README.rdoc +101 -82
- data/TODO.rdoc +1 -3
- data/lib/searchgasm/active_record/connection_adapters/mysql_adapter.rb +143 -6
- data/lib/searchgasm/active_record/connection_adapters/postgresql_adapter.rb +148 -0
- data/lib/searchgasm/active_record/connection_adapters/sqlite_adapter.rb +54 -0
- data/lib/searchgasm/condition/base.rb +59 -86
- data/lib/searchgasm/condition/begins_with.rb +3 -8
- data/lib/searchgasm/condition/blank.rb +5 -5
- data/lib/searchgasm/condition/ends_with.rb +3 -8
- data/lib/searchgasm/condition/equals.rb +4 -3
- data/lib/searchgasm/condition/greater_than.rb +3 -14
- data/lib/searchgasm/condition/greater_than_or_equal_to.rb +3 -14
- data/lib/searchgasm/condition/keywords.rb +3 -8
- data/lib/searchgasm/condition/less_than.rb +3 -14
- data/lib/searchgasm/condition/less_than_or_equal_to.rb +3 -14
- data/lib/searchgasm/condition/like.rb +15 -0
- data/lib/searchgasm/condition/nil.rb +5 -5
- data/lib/searchgasm/condition/not_begin_with.rb +17 -0
- data/lib/searchgasm/condition/not_end_with.rb +17 -0
- data/lib/searchgasm/condition/{does_not_equal.rb → not_equal.rb} +5 -4
- data/lib/searchgasm/condition/not_have_keywords.rb +17 -0
- data/lib/searchgasm/condition/not_like.rb +17 -0
- data/lib/searchgasm/condition/tree.rb +4 -5
- data/lib/searchgasm/conditions/base.rb +218 -72
- data/lib/searchgasm/modifiers/absolute.rb +15 -0
- data/lib/searchgasm/modifiers/acos.rb +11 -0
- data/lib/searchgasm/modifiers/asin.rb +11 -0
- data/lib/searchgasm/modifiers/atan.rb +11 -0
- data/lib/searchgasm/modifiers/base.rb +27 -0
- data/lib/searchgasm/modifiers/ceil.rb +15 -0
- data/lib/searchgasm/modifiers/char_length.rb +15 -0
- data/lib/searchgasm/modifiers/cos.rb +15 -0
- data/lib/searchgasm/modifiers/cot.rb +15 -0
- data/lib/searchgasm/modifiers/day_of_month.rb +15 -0
- data/lib/searchgasm/modifiers/day_of_week.rb +15 -0
- data/lib/searchgasm/modifiers/day_of_year.rb +15 -0
- data/lib/searchgasm/modifiers/degrees.rb +11 -0
- data/lib/searchgasm/modifiers/exp.rb +15 -0
- data/lib/searchgasm/modifiers/floor.rb +15 -0
- data/lib/searchgasm/modifiers/hex.rb +11 -0
- data/lib/searchgasm/modifiers/hour.rb +11 -0
- data/lib/searchgasm/modifiers/log.rb +15 -0
- data/lib/searchgasm/modifiers/log10.rb +11 -0
- data/lib/searchgasm/modifiers/log2.rb +11 -0
- data/lib/searchgasm/modifiers/md5.rb +11 -0
- data/lib/searchgasm/modifiers/microseconds.rb +11 -0
- data/lib/searchgasm/modifiers/milliseconds.rb +11 -0
- data/lib/searchgasm/modifiers/minute.rb +15 -0
- data/lib/searchgasm/modifiers/month.rb +15 -0
- data/lib/searchgasm/modifiers/octal.rb +15 -0
- data/lib/searchgasm/modifiers/radians.rb +11 -0
- data/lib/searchgasm/modifiers/round.rb +11 -0
- data/lib/searchgasm/modifiers/second.rb +15 -0
- data/lib/searchgasm/modifiers/sign.rb +11 -0
- data/lib/searchgasm/modifiers/sin.rb +11 -0
- data/lib/searchgasm/modifiers/square_root.rb +15 -0
- data/lib/searchgasm/modifiers/tan.rb +15 -0
- data/lib/searchgasm/modifiers/week.rb +11 -0
- data/lib/searchgasm/modifiers/year.rb +11 -0
- data/lib/searchgasm/shared/utilities.rb +0 -10
- data/lib/searchgasm/version.rb +2 -2
- data/lib/searchgasm.rb +15 -19
- data/searchgasm.gemspec +86 -9
- data/test/libs/ordered_hash.rb +9 -0
- data/test/test_condition_base.rb +21 -47
- data/test/test_condition_types.rb +44 -44
- data/test/test_conditions_base.rb +34 -21
- data/test/test_helper.rb +1 -0
- data/test/test_search_conditions.rb +1 -1
- metadata +85 -8
- data/lib/searchgasm/condition/contains.rb +0 -20
- data/lib/searchgasm/condition/during_evening.rb +0 -32
@@ -0,0 +1,54 @@
|
|
1
|
+
module Searchgasm
|
2
|
+
module ActiveRecord
|
3
|
+
module ConnectionAdapters
|
4
|
+
module SQLiteAdapter
|
5
|
+
# Date functions
|
6
|
+
def microseconds_sql(column_name)
|
7
|
+
"((strftime('%f', #{column_name}) % 1) * 1000000)"
|
8
|
+
end
|
9
|
+
|
10
|
+
def milliseconds_sql(column_name)
|
11
|
+
"((strftime('%f', #{column_name}) % 1) * 1000)"
|
12
|
+
end
|
13
|
+
|
14
|
+
def second_sql(column_name)
|
15
|
+
"strftime('%S', #{column_name})"
|
16
|
+
end
|
17
|
+
|
18
|
+
def minute_sql(column_name)
|
19
|
+
"strftime('%M', #{column_name})"
|
20
|
+
end
|
21
|
+
|
22
|
+
def hour_sql(column_name)
|
23
|
+
"strftime('%H', #{column_name})"
|
24
|
+
end
|
25
|
+
|
26
|
+
def day_of_week_sql(column_name)
|
27
|
+
"strftime('%w', #{column_name})"
|
28
|
+
end
|
29
|
+
|
30
|
+
def day_of_month_sql(column_name)
|
31
|
+
"strftime('%d', #{column_name})"
|
32
|
+
end
|
33
|
+
|
34
|
+
def day_of_year_sql(column_name)
|
35
|
+
"strftime('%j', #{column_name})"
|
36
|
+
end
|
37
|
+
|
38
|
+
def week_sql(column_name)
|
39
|
+
"strftime('%W', #{column_name})"
|
40
|
+
end
|
41
|
+
|
42
|
+
def month_sql(column_name)
|
43
|
+
"strftime('%m', #{column_name})"
|
44
|
+
end
|
45
|
+
|
46
|
+
def year_sql(column_name)
|
47
|
+
"strftime('%Y', #{column_name})"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
::ActiveRecord::ConnectionAdapters::SQLiteAdapter.send(:include, Searchgasm::ActiveRecord::ConnectionAdapters::SQLiteAdapter)
|
@@ -7,71 +7,47 @@ module Searchgasm
|
|
7
7
|
class Base
|
8
8
|
include Shared::Utilities
|
9
9
|
|
10
|
-
attr_accessor :column, :klass
|
11
|
-
class_inheritable_accessor :
|
12
|
-
self.
|
10
|
+
attr_accessor :column, :column_for_type_cast, :column_sql, :klass
|
11
|
+
class_inheritable_accessor :handle_array_value, :ignore_meaningless_value, :value_type
|
12
|
+
self.ignore_meaningless_value = true
|
13
13
|
|
14
14
|
class << self
|
15
|
-
# Name of the condition inferred from the class name
|
16
|
-
def
|
17
|
-
name.split("::").last.
|
15
|
+
# Name of the condition type inferred from the class name
|
16
|
+
def condition_type_name
|
17
|
+
name.split("::").last.underscore
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
def name_for_column(column)
|
23
|
-
"#{column.name}_#{condition_name}"
|
20
|
+
def handle_array_value?
|
21
|
+
handle_array_value == true
|
24
22
|
end
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
[]
|
29
|
-
end
|
30
|
-
|
31
|
-
def ignore_meaningless? # :nodoc:
|
32
|
-
ignore_meaningless == true
|
33
|
-
end
|
34
|
-
|
35
|
-
# Sane as name_for_column but for the class as a whole. For example the tree methods apply to the class as a whole and not
|
36
|
-
# specific columns. Any condition that applies to columns should probably return nil here.
|
37
|
-
def name_for_klass(klass)
|
38
|
-
nil
|
24
|
+
def ignore_meaningless_value? # :nodoc:
|
25
|
+
ignore_meaningless_value == true
|
39
26
|
end
|
40
27
|
|
41
|
-
#
|
42
|
-
|
28
|
+
# Determines what to call the condition for the model
|
29
|
+
#
|
30
|
+
# Searchgasm tries to create conditions on each model. Before it does this it passes the model to this method to see what to call the condition. If the condition type doesnt want to create a condition on
|
31
|
+
# a model it will just return nil and Searchgasm will skip over it.
|
32
|
+
def condition_names_for_model
|
43
33
|
[]
|
44
34
|
end
|
45
35
|
|
46
|
-
#
|
47
|
-
def
|
48
|
-
[
|
49
|
-
end
|
50
|
-
|
51
|
-
# A utility method for using in name_for_column. Determines if a column contains a date and a time.
|
52
|
-
def datetime_column?(column)
|
53
|
-
[:datetime, :timestamp, :time, :date].include?(column.type)
|
54
|
-
end
|
55
|
-
|
56
|
-
# A utility method for using in name_for_column. For example the keywords condition only applied to string columns, the great than condition doesnt.
|
57
|
-
def string_column?(column)
|
58
|
-
[:string, :text].include?(column.type)
|
59
|
-
end
|
60
|
-
|
61
|
-
# A utility method for using in name_for_column. For example you wouldn't want a string column to use the greater thann condition, but you would for an integer column.
|
62
|
-
def comparable_column?(column)
|
63
|
-
[:integer, :float, :decimal, :datetime, :timestamp, :time, :date].include?(column.type)
|
64
|
-
end
|
65
|
-
|
66
|
-
# A utility method for using in name_for_column. Determines if a column contains a time.
|
67
|
-
def time_column?(column)
|
68
|
-
[:datetime, :timestamp, :time].include?(column.type)
|
36
|
+
# Same as condition_name_for_model, but for a model's column obj
|
37
|
+
def condition_names_for_column
|
38
|
+
[condition_type_name]
|
69
39
|
end
|
70
40
|
end
|
71
41
|
|
72
|
-
def initialize(klass,
|
42
|
+
def initialize(klass, column_obj = nil, column_type = nil, column_sql = nil)
|
73
43
|
self.klass = klass
|
74
|
-
|
44
|
+
|
45
|
+
if column_obj
|
46
|
+
self.column = column_obj.class < ::ActiveRecord::ConnectionAdapters::Column ? column_obj : klass.columns_hash[column_obj.to_s]
|
47
|
+
column_type ||= column.type
|
48
|
+
self.column_for_type_cast = column.class.new(column.name, column.default.to_s, self.class.value_type.to_s || column_type.to_s, column.null)
|
49
|
+
self.column_sql = column_sql || "#{klass.connection.quote_table_name(klass.table_name)}.#{klass.connection.quote_column_name(column.name)}"
|
50
|
+
end
|
75
51
|
end
|
76
52
|
|
77
53
|
# Allows nils to be meaninful values
|
@@ -84,63 +60,60 @@ module Searchgasm
|
|
84
60
|
@explicitly_set_value == true
|
85
61
|
end
|
86
62
|
|
87
|
-
|
88
|
-
|
89
|
-
column ? self.class.name_for_column(column) : self.class.name_for_klass(klass)
|
90
|
-
end
|
91
|
-
|
92
|
-
# A convenience method for the name of this condition
|
93
|
-
def condition_name
|
94
|
-
self.class.condition_name
|
95
|
-
end
|
96
|
-
|
97
|
-
# Quotes a column name properly for sql.
|
98
|
-
def quote_column_name(column_name)
|
99
|
-
klass.connection.quote_column_name(column_name)
|
100
|
-
end
|
101
|
-
|
102
|
-
# A convenience method for using when writing your sql in to_conditions. This is the proper way to use a column name in a query for most databases
|
103
|
-
def quoted_column_name
|
104
|
-
quote_column_name(column.name)
|
105
|
-
end
|
106
|
-
|
107
|
-
# Quotes a table name properly for sql
|
108
|
-
def quote_table_name(table_name)
|
109
|
-
klass.connection.quote_table_name(table_name)
|
110
|
-
end
|
111
|
-
|
112
|
-
# A convenience method for using when writing your sql in to_conditions. This is the proper way to use a table name in a query for most databases
|
113
|
-
def quoted_table_name
|
114
|
-
quote_table_name(klass.table_name)
|
63
|
+
def meaningless_value?
|
64
|
+
!explicitly_set_value? || (self.class.ignore_meaningless_value? && meaningless?(@value))
|
115
65
|
end
|
116
66
|
|
117
67
|
# You should refrain from overwriting this method, it performs various tasks before callign your to_conditions method, allowing you to keep to_conditions simple.
|
118
68
|
def sanitize(alt_value = nil) # :nodoc:
|
119
|
-
return
|
69
|
+
return if meaningless_value?
|
120
70
|
v = alt_value || value
|
121
|
-
if v.is_a?(Array) && !
|
71
|
+
if v.is_a?(Array) && !self.class.handle_array_value?
|
122
72
|
merge_conditions(*v.collect { |i| sanitize(i) })
|
123
73
|
else
|
124
|
-
v = v.utc if column && [:time, :timestamp, :datetime].include?(column.type) && klass.time_zone_aware_attributes && !klass.skip_time_zone_conversion_for_attributes.include?(column.name.to_sym)
|
74
|
+
v = v.utc if column && v.respond_to?(:utc) && [:time, :timestamp, :datetime].include?(column.type) && klass.time_zone_aware_attributes && !klass.skip_time_zone_conversion_for_attributes.include?(column.name.to_sym)
|
125
75
|
to_conditions(v)
|
126
76
|
end
|
127
77
|
end
|
128
|
-
|
78
|
+
|
129
79
|
# The value for the condition
|
130
80
|
def value
|
131
|
-
|
81
|
+
return @casted_value if @casted_value
|
82
|
+
|
83
|
+
if !column_for_type_cast || meaningless_value?
|
84
|
+
@casted_value = @value
|
85
|
+
else
|
86
|
+
@casted_value = @value.is_a?(String) ? column_for_type_cast.type_cast(@value) : @value
|
87
|
+
end
|
132
88
|
end
|
133
89
|
|
134
90
|
# Sets the value for the condition
|
135
91
|
def value=(v)
|
136
|
-
return if self.class.ignore_meaningless? && meaningless?(v)
|
137
92
|
self.explicitly_set_value = true
|
93
|
+
@casted_value = nil
|
138
94
|
@value = v
|
139
95
|
end
|
140
96
|
|
141
97
|
private
|
142
|
-
def
|
143
|
-
|
98
|
+
def meaningless?(v)
|
99
|
+
return false if v == false
|
100
|
+
v.blank?
|
101
|
+
end
|
102
|
+
|
103
|
+
def meaningful?(v)
|
104
|
+
!meaningless?(v)
|
105
|
+
end
|
106
|
+
|
107
|
+
def quote_column_name(column_name)
|
108
|
+
klass.connection.quote_column_name(column_name)
|
109
|
+
end
|
110
|
+
|
111
|
+
def quote_table_name(table_name)
|
112
|
+
klass.connection.quote_table_name(table_name)
|
113
|
+
end
|
114
|
+
|
115
|
+
def quoted_table_name
|
116
|
+
quote_table_name(klass.table_name)
|
144
117
|
end
|
145
118
|
end
|
146
119
|
end
|
@@ -2,18 +2,13 @@ module Searchgasm
|
|
2
2
|
module Condition
|
3
3
|
class BeginsWith < Base
|
4
4
|
class << self
|
5
|
-
def
|
6
|
-
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def aliases_for_column(column)
|
11
|
-
["#{column.name}_bw", "#{column.name}_sw", "#{column.name}_starts_with", "#{column.name}_start"]
|
5
|
+
def condition_names_for_column
|
6
|
+
super + ["bw", "sw", "starts_with", "start"]
|
12
7
|
end
|
13
8
|
end
|
14
9
|
|
15
10
|
def to_conditions(value)
|
16
|
-
["#{
|
11
|
+
["#{column_sql} LIKE ?", "#{value}%"]
|
17
12
|
end
|
18
13
|
end
|
19
14
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
module Searchgasm
|
2
2
|
module Condition
|
3
3
|
class Blank < Base
|
4
|
-
self.
|
4
|
+
self.value_type = :boolean
|
5
5
|
|
6
6
|
class << self
|
7
|
-
def
|
8
|
-
["
|
7
|
+
def condition_names_for_column
|
8
|
+
super + ["is_blank"]
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_conditions(value)
|
13
13
|
# Some databases handle null values differently, let AR handle this
|
14
14
|
if value == true
|
15
|
-
"#{
|
15
|
+
"#{column_sql} is NULL or #{column_sql} = ''"
|
16
16
|
elsif value == false
|
17
|
-
"#{
|
17
|
+
"#{column_sql} is NOT NULL and #{column_sql} != ''"
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -2,18 +2,13 @@ module Searchgasm
|
|
2
2
|
module Condition
|
3
3
|
class EndsWith < Base
|
4
4
|
class << self
|
5
|
-
def
|
6
|
-
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def aliases_for_column(column)
|
11
|
-
["#{column.name}_ew", "#{column.name}_ends", "#{column.name}_end"]
|
5
|
+
def condition_names_for_column
|
6
|
+
super + ["ew", "ends", "end"]
|
12
7
|
end
|
13
8
|
end
|
14
9
|
|
15
10
|
def to_conditions(value)
|
16
|
-
["#{
|
11
|
+
["#{column_sql} LIKE ?", "%#{value}"]
|
17
12
|
end
|
18
13
|
end
|
19
14
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module Searchgasm
|
2
2
|
module Condition
|
3
3
|
class Equals < Base
|
4
|
-
self.
|
4
|
+
self.handle_array_value = true
|
5
|
+
self.ignore_meaningless_value = false
|
5
6
|
|
6
7
|
class << self
|
7
|
-
def
|
8
|
-
["
|
8
|
+
def condition_names_for_column
|
9
|
+
super + ["", "is"]
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
@@ -2,24 +2,13 @@ module Searchgasm
|
|
2
2
|
module Condition
|
3
3
|
class GreaterThan < Base
|
4
4
|
class << self
|
5
|
-
def
|
6
|
-
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def aliases_for_column(column)
|
11
|
-
column_names = [column.name]
|
12
|
-
column_names << column.name.gsub(/_(at|on)$/, "") if datetime_column?(column) && column.name =~ /_(at|on)$/
|
13
|
-
|
14
|
-
aliases = []
|
15
|
-
column_names.each { |column_name| aliases += ["#{column_name}_gt", "#{column_name}_after"] }
|
16
|
-
aliases << "#{column_names.last}_greater_than" if column_names.size > 1
|
17
|
-
aliases
|
5
|
+
def condition_names_for_column
|
6
|
+
super + ["gt", "after"]
|
18
7
|
end
|
19
8
|
end
|
20
9
|
|
21
10
|
def to_conditions(value)
|
22
|
-
["#{
|
11
|
+
["#{column_sql} > ?", value]
|
23
12
|
end
|
24
13
|
end
|
25
14
|
end
|
@@ -2,24 +2,13 @@ module Searchgasm
|
|
2
2
|
module Condition
|
3
3
|
class GreaterThanOrEqualTo < Base
|
4
4
|
class << self
|
5
|
-
def
|
6
|
-
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def aliases_for_column(column)
|
11
|
-
column_names = [column.name]
|
12
|
-
column_names << column.name.gsub(/_(at|on)$/, "") if datetime_column?(column) && column.name =~ /_(at|on)$/
|
13
|
-
|
14
|
-
aliases = []
|
15
|
-
column_names.each { |column_name| aliases += ["#{column_name}_gte", "#{column_name}_at_least"] }
|
16
|
-
aliases << "#{column_names.last}_greater_than_or_equal_to" if column_names.size > 1
|
17
|
-
aliases
|
5
|
+
def condition_names_for_column
|
6
|
+
super + ["gte", "at_least", "least"]
|
18
7
|
end
|
19
8
|
end
|
20
9
|
|
21
10
|
def to_conditions(value)
|
22
|
-
["#{
|
11
|
+
["#{column_sql} >= ?", value]
|
23
12
|
end
|
24
13
|
end
|
25
14
|
end
|
@@ -4,13 +4,8 @@ module Searchgasm
|
|
4
4
|
BLACKLISTED_WORDS = ('a'..'z').to_a + ["about", "an", "are", "as", "at", "be", "by", "com", "de", "en", "for", "from", "how", "in", "is", "it", "la", "of", "on", "or", "that", "the", "the", "this", "to", "und", "was", "what", "when", "where", "who", "will", "with", "www"] # from ranks.nl
|
5
5
|
|
6
6
|
class << self
|
7
|
-
def
|
8
|
-
|
9
|
-
super
|
10
|
-
end
|
11
|
-
|
12
|
-
def aliases_for_column(column)
|
13
|
-
["#{column.name}_kwords", "#{column.name}_kw"]
|
7
|
+
def condition_names_for_column
|
8
|
+
super + ["kwords", "kw"]
|
14
9
|
end
|
15
10
|
end
|
16
11
|
|
@@ -22,7 +17,7 @@ module Searchgasm
|
|
22
17
|
return if search_parts.blank?
|
23
18
|
|
24
19
|
search_parts.each do |search_part|
|
25
|
-
strs << "#{
|
20
|
+
strs << "#{column_sql} LIKE ?"
|
26
21
|
subs << "%#{search_part}%"
|
27
22
|
end
|
28
23
|
|
@@ -2,24 +2,13 @@ module Searchgasm
|
|
2
2
|
module Condition
|
3
3
|
class LessThan < Base
|
4
4
|
class << self
|
5
|
-
def
|
6
|
-
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def aliases_for_column(column)
|
11
|
-
column_names = [column.name]
|
12
|
-
column_names << column.name.gsub(/_(at|on)$/, "") if datetime_column?(column) && column.name =~ /_(at|on)$/
|
13
|
-
|
14
|
-
aliases = []
|
15
|
-
column_names.each { |column_name| aliases += ["#{column_name}_lt", "#{column_name}_before"] }
|
16
|
-
aliases << "#{column_names.last}_less_than" if column_names.size > 1
|
17
|
-
aliases
|
5
|
+
def condition_names_for_column
|
6
|
+
super + ["lt", "before"]
|
18
7
|
end
|
19
8
|
end
|
20
9
|
|
21
10
|
def to_conditions(value)
|
22
|
-
["#{
|
11
|
+
["#{column_sql} < ?", value]
|
23
12
|
end
|
24
13
|
end
|
25
14
|
end
|
@@ -2,24 +2,13 @@ module Searchgasm
|
|
2
2
|
module Condition
|
3
3
|
class LessThanOrEqualTo < Base
|
4
4
|
class << self
|
5
|
-
def
|
6
|
-
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def aliases_for_column(column)
|
11
|
-
column_names = [column.name]
|
12
|
-
column_names << column.name.gsub(/_(at|on)$/, "") if datetime_column?(column) && column.name =~ /_(at|on)$/
|
13
|
-
|
14
|
-
aliases = []
|
15
|
-
column_names.each { |column_name| aliases += ["#{column_name}_lte", "#{column_name}_at_most"] }
|
16
|
-
aliases << "#{column_names.last}_less_than_or_equal_to" if column_names.size > 1
|
17
|
-
aliases
|
5
|
+
def condition_names_for_column
|
6
|
+
super + ["lte", "at_most", "most"]
|
18
7
|
end
|
19
8
|
end
|
20
9
|
|
21
10
|
def to_conditions(value)
|
22
|
-
["#{
|
11
|
+
["#{column_sql} <= ?", value]
|
23
12
|
end
|
24
13
|
end
|
25
14
|
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module Searchgasm
|
2
2
|
module Condition
|
3
3
|
class Nil < Base
|
4
|
-
self.
|
4
|
+
self.value_type = :boolean
|
5
5
|
|
6
6
|
class << self
|
7
|
-
def
|
8
|
-
["
|
7
|
+
def condition_names_for_column
|
8
|
+
super + ["is_nil", "is_null", "null"]
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_conditions(value)
|
13
13
|
if value == true
|
14
|
-
"#{
|
14
|
+
"#{column_sql} is NULL"
|
15
15
|
elsif value == false
|
16
|
-
"#{
|
16
|
+
"#{column_sql} is NOT NULL"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Searchgasm
|
2
|
+
module Condition
|
3
|
+
class NotBeginWith < Base
|
4
|
+
class << self
|
5
|
+
def condition_names_for_column
|
6
|
+
super + ["not_bw", "not_sw", "not_start_with", "not_start", "beginning_is_not", "beginning_not"]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_conditions(value)
|
11
|
+
begin_with = BeginWith.new
|
12
|
+
begin_with.value = value
|
13
|
+
being_with.to_conditions.gsub(" LIKE ", " NOT LIKE ")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Searchgasm
|
2
|
+
module Condition
|
3
|
+
class NotEndWith < Base
|
4
|
+
class << self
|
5
|
+
def condition_names_for_column
|
6
|
+
super + ["not_ew", "not_end", "end_is_not", "end_not"]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_conditions(value)
|
11
|
+
ends_with = EndsWith.new
|
12
|
+
ends_with.value = value
|
13
|
+
ends_with.to_conditions.gsub(" LIKE ", " NOT LIKE ")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module Searchgasm
|
2
2
|
module Condition
|
3
|
-
class
|
4
|
-
self.
|
3
|
+
class NotEqual < Base
|
4
|
+
self.handle_array_value = true
|
5
|
+
self.ignore_meaningless_value = false
|
5
6
|
|
6
7
|
class << self
|
7
|
-
def
|
8
|
-
["
|
8
|
+
def condition_names_for_column
|
9
|
+
super + ["does_not_equal", "not_equal", "is_not", "not"]
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Searchgasm
|
2
|
+
module Condition
|
3
|
+
class NotHaveKeywords < Base
|
4
|
+
class << self
|
5
|
+
def condition_names_for_column
|
6
|
+
super + ["not_have_keywords", "not_keywords", "not_have_kw", "not_kw", "not_have_kwwords", "not_kwwords"]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_conditions(value)
|
11
|
+
keywords = Keywords.new
|
12
|
+
keywords.value = value
|
13
|
+
keywords.to_conditions.gsub(" LIKE ", " NOT LIKE ")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Searchgasm
|
2
|
+
module Condition
|
3
|
+
class NotLike < Base
|
4
|
+
class << self
|
5
|
+
def condition_names_for_column
|
6
|
+
super + ["not_contain", "not_have"]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_conditions(value)
|
11
|
+
like = Like.new
|
12
|
+
like.value = value
|
13
|
+
like.to_conditions.gsub(" LIKE ", " NOT LIKE ")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -2,13 +2,12 @@ module Searchgasm
|
|
2
2
|
module Condition
|
3
3
|
class Tree < Base # :nodoc:
|
4
4
|
class << self
|
5
|
-
def
|
6
|
-
|
5
|
+
def condition_names_for_column
|
6
|
+
[]
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
condition_name
|
9
|
+
def condition_names_for_model(model)
|
10
|
+
[condition_type_name]
|
12
11
|
end
|
13
12
|
end
|
14
13
|
end
|