Hi Milan

This isn't a common scenario (as you may have guessed), but you could try the 
following:
  User.define_indexes
  source = User.sphinx_indexes.first.sources.first
  ThinkingSphinx::Attribute.new(source, FauxColumn.coerce(localities.id), :as 
=> :localities_ids_facet).to_facet
  User.sphinx_facets << ThinkingSphinx::Attribute.new(source, 
FauxColumn.coerce(localities.id), :as => :localities_ids).to_facet

You may want to look through the ThinkingSphinx::Index::Builder source to 
ensure I've got that right.
https://github.com/freelancing-god/thinking-sphinx/blob/master/lib/thinking_sphinx/index/builder.rb

On the other hand, given you're not using the auto-generated index definition, 
you could add it there instead:
  has localities.id, :as => :localities_ids, :facet => true

That might do the job as well :)

-- 
Pat

On 06/01/2012, at 12:09 AM, milann wrote:

> Hi everyone,
> 
> I need a multi value facet for my application and since I wasn't able
> to index it through a field (comma separated string wasn't parsed into
> multiple values by Sphinx for some reason) nor through an association,
> I decided to add my custom attribute to sphinx configuration.
> 
> This is what I've added:
> 
>  sql_attr_multi = uint localities_ids_facet from query; SELECT
> lt.localizable_id * CAST(3 AS SIGNED) + 2 AS id, lca.id AS
> localities_ids_facet \
>    FROM locatings lt \
>    JOIN localities lc ON lt.locality_id = lc.id \
>    JOIN localities lca ON lca.lft <= lc.lft AND lca.rgt >= lc.rgt \
>    WHERE lt.localizable_type="User"
> 
> Now when I reindex, everything seems to work just fine. When querying
> Sphinx via SphinxQL I can see the MVA's and can filter the results
> based on particular values.
> 
> The problem is that TS doesn't recognize my attribute so when I call
> something like User.facets(:facets => :locality_ids) an empty hash is
> returned.
> 
> This is obviously because I didn't declare this attribute in my
> define_index block.
> 
> My question then is: How to force TS to recognize my facet/attribute?
> 
> Thanks for any advice!
> Milan
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/thinking-sphinx?hl=en.
> 


-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to