#150 ✓resolved

Model#index throws exception when :first_id is not 0

Reported by zgavin | November 18th, 2010 @ 12:45 PM

When you call #index on any sunspot rails model with a :first_id option set to anything greater than 0, the outcome is an inevitable error. The problem is in Sunspot::Rails::Searchable#solr_index starting on line 230:

            offset = 0
            counter = 1
            record_count = count
            last_id = options[:first_id]
            while(offset < record_count)

Specifically 'record_count = count' on line 232. If you are starting at an index above 0, the number of rows you want to index will be smaller than the total number of rows in the table.

To fix you simply need to change line 232 and 233 to:

            last_id = options[:first_id]
            record_count = count(:conditions => ["`#{table_name}`.`#{primary_key}` > ?", last_id])

Until this bug is fixed, you can simply rescue the exception that is thrown, since sunspot rails won't throw the exception until it runs out of content to index.

I'd also add that 'first_id' is a confusing parameter name. It implies that the record in question will get indexed, when in fact sunspot will start with the next record in the table(ordered by primary key).

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Awesome Solr interaction for Ruby

People watching this ticket