Class: Groonga::ExpressionBuildable::ColumnValueExpressionBuilder

Inherits:
ExpressionBuilder
  • Object
show all
Defined in:
lib/groonga/expression-builder.rb,
lib/groonga/expression-builder-19.rb

Direct Known Subclasses

MatchTargetColumnExpressionBuilder

Instance Method Summary collapse

Methods inherited from ExpressionBuilder

#&, #|

Constructor Details

#initialize(column, options = {}) ⇒ ColumnValueExpressionBuilder

Returns a new instance of ColumnValueExpressionBuilder.



148
149
150
151
152
153
154
155
# File 'lib/groonga/expression-builder.rb', line 148

def initialize(column, options={})
  super()
  @table = options[:table] || column.table
  @column = column
  @column_name = options[:column_name] || @column.local_name
  @range = options[:range] || @column.range
  @name = options[:name]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



263
264
265
266
267
268
269
270
271
# File 'lib/groonga/expression-builder.rb', line 263

def method_missing(name, *args, &block)
  return super if block
  return super unless args.empty?
  if VALID_COLUMN_NAME_RE =~ name.to_s
    RecordExpressionBuilder.new(@table, @name)["#{@column_name}.#{name}"]
  else
    super
  end
end

Instance Method Details

#!=(other) ⇒ Object



21
22
23
# File 'lib/groonga/expression-builder-19.rb', line 21

def !=(other)
  NotEqualExpressionBuilder.new(self, normalize(other))
end

#%(other) ⇒ Object



217
218
219
# File 'lib/groonga/expression-builder.rb', line 217

def %(other)
  ModExpressionBuilder.new(self, normalize(other))
end

#*(other) ⇒ Object



209
210
211
# File 'lib/groonga/expression-builder.rb', line 209

def *(other)
  StarExpressionBuilder.new(self, normalize(other))
end

#+(other) ⇒ Object



201
202
203
# File 'lib/groonga/expression-builder.rb', line 201

def +(other)
  PlusExpressionBuilder.new(self, normalize(other))
end

#-(other) ⇒ Object



205
206
207
# File 'lib/groonga/expression-builder.rb', line 205

def -(other)
  MinusExpressionBuilder.new(self, normalize(other))
end

#/(other) ⇒ Object



213
214
215
# File 'lib/groonga/expression-builder.rb', line 213

def /(other)
  SlashExpressionBuilder.new(self, normalize(other))
end

#<(other) ⇒ Object



185
186
187
# File 'lib/groonga/expression-builder.rb', line 185

def <(other)
  LessExpressionBuilder.new(self, normalize(other))
end

#<=(other) ⇒ Object



189
190
191
# File 'lib/groonga/expression-builder.rb', line 189

def <=(other)
  LessEqualExpressionBuilder.new(self, normalize(other))
end

#==(other) ⇒ Object



167
168
169
# File 'lib/groonga/expression-builder.rb', line 167

def ==(other)
  EqualExpressionBuilder.new(self, normalize(other))
end

#=~(other) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/groonga/expression-builder.rb', line 171

def =~(other)
  if other.nil?
    full_column_name = "#{@table.name}.#{@column_name}"
    raise ArgumentError,
           "match word should not be nil: #{full_column_name}"
  end

  if other.is_a?(Regexp)
    RegexpExpressionBuilder.new(self, normalize(other.source))
  else
    MatchExpressionBuilder.new(self, normalize(other))
  end
end

#>(other) ⇒ Object



193
194
195
# File 'lib/groonga/expression-builder.rb', line 193

def >(other)
  GreaterExpressionBuilder.new(self, normalize(other))
end

#>=(other) ⇒ Object



197
198
199
# File 'lib/groonga/expression-builder.rb', line 197

def >=(other)
  GreaterEqualExpressionBuilder.new(self, normalize(other))
end

#build(expression, variable) ⇒ Object



157
158
159
160
161
162
163
164
165
# File 'lib/groonga/expression-builder.rb', line 157

def build(expression, variable)
  expression.append_object(variable)
  if @column.is_a?(String)
    expression.append_constant(@column)
  else
    expression.append_object(@column)
  end
  expression.append_operation(Groonga::Operation::GET_VALUE, 2)
end

#match(query, options = {}) ⇒ Object



221
222
223
224
225
226
# File 'lib/groonga/expression-builder.rb', line 221

def match(query, options={})
  options = options.dup
  options[:syntax] ||= :query
  options[:default_column] = @column_name
  SubExpressionBuilder.new(query, options)
end

#prefix_search(other) ⇒ Object



228
229
230
# File 'lib/groonga/expression-builder.rb', line 228

def prefix_search(other)
  PrefixSearchExpressionBuilder.new(self, normalize(other))
end

#similar_search(other) ⇒ Object



236
237
238
# File 'lib/groonga/expression-builder.rb', line 236

def similar_search(other)
  SimilarSearchExpressionBuilder.new(self, normalize(other))
end

#suffix_search(other) ⇒ Object



232
233
234
# File 'lib/groonga/expression-builder.rb', line 232

def suffix_search(other)
  SuffixSearchExpressionBuilder.new(self, normalize(other))
end

#term_extract(other) ⇒ Object



240
241
242
243
244
245
246
247
248
# File 'lib/groonga/expression-builder.rb', line 240

def term_extract(other)
  if @column_name == "_key"
    TermExtractExpressionBuilder.new(self, normalize(other))
  else
    message = "term extraction supports _key column only: " +
      "<#{@column_name}>"
    raise ArgumentError, message
  end
end