I have a model.  A Parent has many children.  Each child has a
zip_code.

class Parent < AR::B
  has_many :children

  define_index do
    has children(:zip_code), :as => :child_zip_codes
  end
end

When I search for Parents that have a child zip code of 01518, I get 4
results:
Parent.search(:with => {:child_zip_codes => ['01518']}) #=> 4 results

When I search for Parents that have a child zip code 0f 01007, I only
get 1 result.
Parent.search(:with => {:child_zip_codes => ['01007']}) #=> 1 result

The problem is upon further review:
Parent.search(:with => {:child_zip_codes => ['01518']}).map {|x|
x.children.find_by_zip_code('01007').present? } #=> [true, true, true,
true]

Each of the results for 01518 should also show up in the 01007 search
because each of those Parents has a child with each zip_code.

The only difference between the results is the number of children per
Parent.  The ones that are "missing" have a lot more children.
Parent.search(:with => {:child_zip_codes => ['01518']}).map {|x|
x.children.count } #=> [201, 335, 566, 335]

and the index of the zip code with missing results is higher:
Parent.search(:with => {:child_zip_codes => ['01518']}).map {|x|
x.child_listings.map(&:zip_code).index('01007') } #=> [84, 179, 280,
179]

If I delete a bunch of children such that the index of my child w/ zip
code 01007 # goes down:
Parent.search(:with => {:child_zip_codes => ['01518']}).map {|x|
x.child_listings.map(&:zip_code).index('01007') } #=> [84, 79, 280,
179]

I get two results:
Parent.search(:with => {:child_zip_codes => ['01007']}) #=> 2 results


Is there a hard-coded limit relating to the number of relationships
when defining attributes somewhere that I'm missing?

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to