Hi Andrey

I think you're going to have better luck indexing on the translation records 
instead of the parent records:

  ThinkingSphinx::Index.define "section/translation", with: :active_record do
    indexes title, sortable: true
    indexes content

    has locale_id
  end

I know locale_id doesn't exist, but you can't filter on string attributes, so 
I'd recommend creating a reliable foreign key for referring to specific locales.

Also, an advantage of this approach is that it's actually now sortable by title 
- before, you had a collection of titles, and it would have sorted by all of 
them concatenated together.

As for different steamers for different locales, you'd need to define an index 
per locale:

  %w( en fr es ).each do |locale|
    ThinkingSphinx::Index.define "section/translation", name: 
"section_translation_#{locale}", with: :active_record do
      indexes title, sortable: true
      indexes content

      has locale_id

      where "locale = '#{locale}'"

      set_property morphology: "stem_#{locale}"
    end
  end

-- 
Pat

On 24/09/2013, at 12:02 AM, Andrey Novikov <[email protected]> wrote:

> Hello.
> 
> I'm using globalize3 gem to store translations for Rails models in 
> multilingual application. Shortly, globalize3 gem uses an additional table 
> for each model to store translations for attributes, and in Rails it hooks 
> model attribute getter calls, transparently queries that table and return 
> values for current locales. Also it adds translations association for those, 
> who need manual control.
> 
> I want make sphinx to index all translations for every record with a locale, 
> and on search I want to restrict search only for the current locale with 
> ability of showing something like "View results in other languages". One more 
> thing that I wish to do (if possible) — to use different stemmers for 
> searching in different locales.
> 
> And worst thing — I don't know how it ever could look like in configuration, 
> as I'm newbie in Thinking sphinx, Sphinx and such a software in general.
> 
> Currently, I've tried such a configuration.
> ThinkingSphinx::Index.define :section, :with => :active_record do
>   indexes translations.title,   as: :title,  sortable: true
>   indexes translations.content, as: :content
>   #has    translations.locale,  as: :locale, type: :string # Throws an error, 
> requires integer field, but it's a string
> end
> 
> And on searching I want to use something like:
> Section.search params[:q], with: { locale: I18n.locale }
> 
> But sphinx indexes only first translation for record (first returned by 
> mysql, not all).
> 
> P.S> On stackoverflow, there is proposed solution with a metaprogramming 
> usage (for ElasticSearch), but I dislike it (what I've 10 languages?): 
> http://stackoverflow.com/questions/9951348/i18n-search-using-tire-and-globalize3
> 
> -- 
> 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.

Reply via email to