Hi Pat,
> Also, why are you joining and then splitting again?

oh I think I should have included some data because it's not clear that I
actually have only one table here. I've been somewhat influenced by CouchDB,
and your earlir reply on tags management (
http://groups.google.com/group/thinking-sphinx/msg/6972ad7c1ca83f76). I'm
storing my subcategories on the item row directly (fake data), no separate
table:

row 1 { :category => "car", :subcategories => "fast,easy to drive,cheap" }
row 2 { :category => "car", :subcategories => "fast,cheap" }

So I'm doing the split and the join to get this:

["fast,easy to drive,cheap","fast,cheap"] => ["fast","easy to
drive","cheap"]

I found out that having it written with facets gives:

    @subcategories = Item.facets(:conditions => { :category =>
params[:category] })[:sub_categories].keys.join(',').split(',').uniq.sort

which is shorted than the select distinct version with AR.

With my current datasets, it works very well (I've been quite surprised). It
helps me keep my ETL process (which feeds the mysql DB) lightweight (no
lookup etc, less complexity - I like that).

Do you think there might be a way to keep this kind of structure while
letting sphinx work for me a little bit more ? (avoid split  / join) ?

Thanks for your insight,

-- Thibaut

Personally, I'd be getting this information out via normal SQL... if I
> take some random guesses with your schema, and assume you're using a
> HABTM join:
>
> SELECT * FROM sub_categories WHERE id IN (
>   SELECT sub_category_id FROM items_sub_categories WHERE item_id IN (
>     SELECT id FROM items WHERE category = 'SomeTopic'
>   )
> )
>
> Or you could do that using joins, in a similar manner. It's not so
> clean, but put it into the model, and you could get the subcategories
> easily enough.
>
> Also, why are you joining and then splitting again?
>
> If you can think of a different method that involves Sphinx, you know
> where the code is :)
>
> Cheers
>
> --
> Pat
>
> On 30/01/2009, at 10:57 PM, Thibaut Barrère wrote:
>
> >
> > Hi,
> >
> > I have a model with an only one (exclusive) category and several
> > possible sub_categories. The sub_categories are stored into a string
> > on the AR model and are just comma-separated. I'm able to filter
> > properly with both categories and sub-categories.
> >
> > Now when a category is selected, I need to retrieve the available sub-
> > categories to fill a select-box, basically. I found out that this was
> > working, thanks to the facets feature:
> >
> > Item.facets(:conditions => { :category => 'SomeTopic' })
> > [:sub_categories].keys.join(',').split(',').uniq.sort
> >
> > Do you have any idea of some cleaner version, maybe using some built-
> > in feature I'm not aware of ?
> >
> > thanks for any hint,
> >
> > -- Thibaut
> > >
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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