0

I'm using thinking sphinx, with the sphinx_select parameter to create a dynamic field, like so:

@subjects = Subject.search(sphinx_select: "*, petals < 1 or color = 2 as my_attribute")

Is there any way to access custom_attribute in the search results? For example:

@subjects.each do |s|
    s.my_attribute
end

Returns

undefined method `my_attribute' for #<Subject:0x007fb25cdcdb18>
Adrian Macneil
  • 13,017
  • 5
  • 57
  • 70

1 Answers1

0

Did some digging in the thinking sphinx source and figured this out. The dynamic attributes are stored in a match object, which can be accessed like so:

@subjects.each_with_match do |s, match|
    match[:attributes]["my_attribute"]
end
Adrian Macneil
  • 13,017
  • 5
  • 57
  • 70