TS support for STI in Rails3 as of now

10 views
Skip to first unread message

cec

unread,
Oct 11, 2011, 10:39:25 AM10/11/11
to Thinking Sphinx
Hi!

I'm writing a small rails3 apps ecosystem at work and I'm already
using TS on some of them.

For the app I am working on now, I have to manage a catalog of both
digital and paper magazines.
The two share various fields, but at the same time they quite differ
in various logic aspects.
These are the models I would use:

Magazine < AR:Base
DigitalMag < Magazine
PaperMag < Magazine

Users need to be able to search for digitals, paperMags or both.

The columns that have to be searched on are shared between the two
kinds of magazines, so I would define only an index in Magazine,
hoping that its children "inherit" the index.
Is it possible to do so with TS at the moment?

I know this is all trivial stuff, but I think it is always better to
be exhaustive when describing one's needs.


Timo Virkkala

unread,
Oct 12, 2011, 12:44:00 AM10/12/11
to thinkin...@googlegroups.com
Hi,

Everything you've described so far is quite possible with TS. I'm
doing something quite similar at the moment and TS is handling the STI
situation fine.

After you define your index on Magazine, you can do any of the following:

Magazine.search(phrase) # Searches both kinds of magazines
DigitalMag.search(phrase) # Searches only digital mags
PaperMag.search(phrase) # Searches only paper mags
ThinkingSphinx.search(phrase) # Searches all of your indexed models
ThinkingSphinx.search(phrase, :classes => [DigitalMag, PaperMag])

-T-

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

cec

unread,
Oct 12, 2011, 4:28:08 AM10/12/11
to Thinking Sphinx
Nice!
Thanks for the example searches!
Reply all
Reply to author
Forward
0 new messages