0

In the examples for sunspot sunspot.github.com, a belongs_to :blog association is indexed inside a searchable block with integer :blog_id. Later, the search can be constrained to a particular blog using with(:blog_id, 1).

If have done this, except the association is for a retailer and the index is on retailer_id. Yet, when searching, there are no results returned as soon as I use with(:retailer_id, 4). If this condition is left off, all of the results returned have a retailer_id = 4.

I have reindexed, numerous times. I've tried both sunspot_rails 1.3.3 and 2.0.0.

All of the other text fields appear to be indexing fine.

The query displayed in the Rails logs, going to solr, appears to include the proper fields.

What else might cause this?

Tony Pitale
  • 1,192
  • 2
  • 11
  • 23

1 Answers1

0

After attempting to Sunspot.index(Item.first) and seeing that the xml did include the retailer_id. I checked the logs for the import done by the rake task.

As it turns out, the problem that I was experiencing is because DataMapper does not create the association properties until after DataMapper.finalize is called. This never happens as a part of the included sunspot_rails tasks.rb for reindexing.

The quick solution for me was to simply copy over the rake task, and add the call to finalize after all the models are required.

Tony Pitale
  • 1,192
  • 2
  • 11
  • 23