Module: ActiveRecord::ConnectionAdapters::OracleEnhanced::ContextIndex::ContextIndexClassMethods

Defined in:
lib/active_record/connection_adapters/oracle_enhanced/context_index.rb

Instance Method Summary collapse

Instance Method Details

#contains(column, query, options = {}) ⇒ Object

Add context index condition.



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/active_record/connection_adapters/oracle_enhanced/context_index.rb', line 331

def contains(column, query, options = {})
  score_label = options[:label].to_i || 1
  quoted_column = connection.quote_table_name(column)

  # Create an Arel node for the CONTAINS function
  contains_node = Arel::Nodes::NamedFunction.new(
    "CONTAINS",
    [
      Arel::Nodes::SqlLiteral.new(quoted_column),
      Arel::Nodes::BindParam.new(query),
      Arel::Nodes::SqlLiteral.new(score_label.to_s)
    ]
  )

  # Create comparison node: CONTAINS(...) > 0
  condition = Arel::Nodes::GreaterThan.new(contains_node, Arel::Nodes::SqlLiteral.new("0"))

  # Create the where clause and order by score
  where(condition).order(Arel.sql("SCORE(#{score_label}) DESC"))
end