Hi Jon The first thing to note - and this is at least one piece of the puzzle missed for deltas - is that the delta option belongs as an argument in the ThinkingSphinx::Index.define call, not within the provided block. Add delta: true alongside with: :active_record and see how you go with that approach. (What you tried was valid for TS v1/2, so it’s a case of close but no cigar.)
As for the real-time indices, it’s important to note that your model_order attribute will not work - it’s written as if it’s going to be inserted into a SQL statement, which isn’t the case in this scenario. A possible alternative is to add a model_order method which returns an integer to each model as required, and then the attribute is defined more simply: has model_order, type: :integer I’m not sure if that’s the cause of the index updates not working though… Rails 4 is certainly supported with TS v3 - hopefully we can get this working reliably with a little persistence :) If you try deltas again, hopefully that setting in the wrong place was the only thing that requires changing… but if you’d like to keep going with real-time indices, see if model_order as a method does the trick, but if not, let me know. Any stack traces of errors would certainly be appreciated too! Good luck — Pat On 25 Nov 2013, at 4:15 am, [email protected] wrote: > I'll preface this entirely by saying I'm a thinking sphinx newb. > > I successfully got a basic index and search up and running in my app. The > next step was to get the index updated as changes were made. For my app the > indexed values don't change much as they are song, album, and artist records > that go largely unchanged once created. However they will change form time to > time as well as be added to a collection model via a polymophic relationship > of CollectionItem. > > My issue though is that despite my attempts I cannot get deltas or realtime > indexing up and running. I don't really care which I use, I just want the > option I go with to be stable. > > Delta Attempt > I setup a song index as follows: > > ThinkingSphinx::Index.define :song, with: :active_record do > indexes :name > > has collectionitems(:collection_id), type: :integer, as: :collection_id > > has '4', as: :model_order, type: :integer > > has album_id, type: :integer > has artist_id, type: :integer > has created_at, type: :timestamp > has updated_at, type: :timestamp > > set_property delta: true > end > > The I added the delta column to songs with default true ran rake ts:rebuild > and was ready to go. After the intial index search results are being returned > as expected. However when I changed a songs name via the update method the > index wasn't updated. Its worth noting I don't know how to inspect the index > I simple performed a search for the new name and got no results. If I > searched for the old song name it was found. Then I tried a new song record > folled by a search for it and got no results. > > As soon as I rake ts:rebuild everything is fine (as the index is rebuilt) So > I'm unsure why it didn't work on update or new record? > > > > > > Realtime indices Attempt > This was my preferred option as I'm always down with cutting edge but I ran > into basically the same issue as with deltas and then some. > > Song Index > ThinkingSphinx::Index.define :song, with: :real_time do > indexes :name > > has collectionitems(:collection_id), type: :integer, as: :collection_id > > has '4', as: :model_order, type: :integer > > has album_id, type: :integer > has artist_id, type: :integer > has created_at, type: :timestamp > has updated_at, type: :timestamp > end > > > Song model > class Song < ActiveRecord::Base > belongs_to :album, counter_cache: true > belongs_to :artist, counter_cache: true > > has_many :collections, through: :collectionitems > has_many :collectionitems, as: :collectable > > has_many :services, through: :servicesongs > has_many :servicesongs > > has_many :tracks > has_many :charts > > after_save ThinkingSphinx::RealTime.callback_for(:song) > end > > CollectionItem Model > class Collectionitem < ActiveRecord::Base > belongs_to :collection > belongs_to :collectable, polymorphic: true > > validates_uniqueness_of :collectable_id, scope: [:collection_id, > :collectable_type] > > #after_save ThinkingSphinx::RealTime.callback_for(:collectable > [:collectable]) > end > > There are two parts to this: I want to reindex on a new or updated > Collectionitem so I can perfrom searches for song based on its Collections. > However In this scenario I get a Rails error on the after_save callback in > the CollectionItem of 'no implicit conversion of Symbol into Integer' I have > no clue what this means. It however prevented pages from loading and any ts > task form being called so I commented it out and decided to just test > realtime updates on the song first. > > Putting aside the Collectionitem callback I was able to run 'rake > ts:regenerate' and get the index created and search with results but once > again as with delta scenario above, changes and new records were not being > indexed. Yet when I ran 'rake ts:generate' the index updates and all results > expected are found. > > > I feel like an idiot and I'm sorry for such a long post. I just don't see > what I'm doing wrong here? Neither option for update the index has worked at > all. Any help at all is appreciated, I can provide whatever code necessary to > work this out. > > Its worth noting I'm using rails 4.0 with thinking_sphinx 3.0.6 (I assume 4.0 > is supported) > > > > -- > You received this message because you are subscribed to the Google Groups > "Thinking Sphinx" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/thinking-sphinx. > For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/thinking-sphinx. For more options, visit https://groups.google.com/groups/opt_out.
