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.



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

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)



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

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



211
212
213
# File 'lib/groonga/expression-builder.rb', line 211

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

#*(other) ⇒ Object



203
204
205
# File 'lib/groonga/expression-builder.rb', line 203

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

#+(other) ⇒ Object



195
196
197
# File 'lib/groonga/expression-builder.rb', line 195

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

#-(other) ⇒ Object



199
200
201
# File 'lib/groonga/expression-builder.rb', line 199

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

#/(other) ⇒ Object



207
208
209
# File 'lib/groonga/expression-builder.rb', line 207

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

#<(other) ⇒ Object



179
180
181
# File 'lib/groonga/expression-builder.rb', line 179

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

#<=(other) ⇒ Object



183
184
185
# File 'lib/groonga/expression-builder.rb', line 183

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

#==(other) ⇒ Object



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

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

#=~(other) ⇒ Object



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

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



187
188
189
# File 'lib/groonga/expression-builder.rb', line 187

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

#>=(other) ⇒ Object



191
192
193
# File 'lib/groonga/expression-builder.rb', line 191

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

#build(expression, variable) ⇒ Object



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

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



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

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

#prefix_search(other) ⇒ Object



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

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

#similar_search(other) ⇒ Object



230
231
232
# File 'lib/groonga/expression-builder.rb', line 230

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

#suffix_search(other) ⇒ Object



226
227
228
# File 'lib/groonga/expression-builder.rb', line 226

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

#term_extract(other) ⇒ Object



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

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