3

Since I have a model with localized fields (using Globalize, I'd like to make localized search. I set up two indices on my model :

ThinkingSphinx::Index.define :document, name: "document_fr", :with => :active_record, :delta => true do

    indexes translations.name, :as => :options
    indexes translations.description
    where "(#{Document.translations_table_name}.locale='fr' OR #{Document.translations_table_name}.locale IS NULL)"
    has created_at, updated_at

end

ThinkingSphinx::Index.define :document, name: "document_nl", :with => :active_record, :delta => true do

    indexes translations.name, :as => :options
    indexes translations.description
    where "(#{Document.translations_table_name}.locale='nl' OR #{Document.translations_table_name}.locale IS NULL)"
    has created_at, updated_at

end

How can I make a search on one index, using the delta ?

I tried to use the indices options but it does not really work :

Document.search 'something', {
    indices: ["document_fr_core", "document_fr_delta"]
}

=> If I change a Document instance and save it, delta indexing happens and the change are indexed in *_delta. But since I am also searching on *_core, the modified instance is still found even when the has no match for the search anymore :-(

Edit (24/04/2015) Alternative solution may be to use facets search for the translations. But I am not really sure how to use them. If you think it's a better solution, please let me know :-)

LapinLove404
  • 1,939
  • 1
  • 21
  • 26
  • which server are you using? if Passenger then you need to add some configurations, to allow delta to be executed immediately – jaspreet21anand Apr 24 '15 at 10:20
  • Production will be on Passanger. But the problem is there in the development env (Mac OSX 10.9.5) as well. – LapinLove404 Apr 24 '15 at 11:37
  • In my opinion, you need to use realtime index in this case. – Truong Hua Apr 25 '15 at 07:33
  • Your search call looks correct to me - how is it not working? The core change should be marked as deleted by Thinking Sphinx (an internal flag, which is then used to filter out those results from searches). The SphinxQL query in your logs should confirm that this is the case. – pat May 02 '15 at 02:47
  • Odly enough, I retried exactly the same code recently and it worked. I think something else was messed up in my dev. environement and cause the strange behaviour - but I coudln't imagine what :-( – LapinLove404 Jun 25 '15 at 20:26

0 Answers0