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.



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

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)



259
260
261
262
263
264
265
266
267
# File 'lib/groonga/expression-builder.rb', line 259

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



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

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

#*(other) ⇒ Object



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

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

#+(other) ⇒ Object



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

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

#-(other) ⇒ Object



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

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

#/(other) ⇒ Object



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

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

#<(other) ⇒ Object



181
182
183
# File 'lib/groonga/expression-builder.rb', line 181

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

#<=(other) ⇒ Object



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

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

#==(other) ⇒ Object



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

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

#=~(other) ⇒ Object



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

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

#>(other) ⇒ Object



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

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

#>=(other) ⇒ Object



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

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

#build(expression, variable) ⇒ Object



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

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



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

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

#prefix_search(other) ⇒ Object



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

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

#similar_search(other) ⇒ Object



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

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

#suffix_search(other) ⇒ Object



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

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

#term_extract(other) ⇒ Object



236
237
238
239
240
241
242
243
244
# File 'lib/groonga/expression-builder.rb', line 236

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