Ah, duh, that's so obvious.
Hmm, for some reason, I can't find the RDocs from the documentation site...
might want to make it a little more obvious. I've been spelunking through
the source to find out what I can, lol.
I'm not familiar with the "where" method in the define_index block... what
does that apply to? I'm sure the RDoc would make it a little more obvious.
I will use this:
has_many :accepted_model_versions, :class_name => "Model::Version",
:conditions => "model_versions.state = 'accepted'", :order =>
"created_at DESC"
You can specify table names in the conditions to make sure it won't
conflict.
Thanks for the inspiration :)
The acts_as_revisible looks interesting, though we're already committed with
a significant codebase built on acts_as_versioned. I will keep it in mind,
though :)
Matt
On Thu, May 21, 2009 at 7:49 PM, Pat Allan <[email protected]> wrote:
>
> Hi Matt
>
> I'd probably add a specific association pointing to the most recent
> version:
> has_one :accepted_version, :class_name => "ModelVersion",
> :conditions => "state = 'accepted'", :order => "created_at DESC"
>
> However, not sure how well that condition gets translated in the joins
> built by ActiveRecord - it will likely fall over if there's another
> table joined to that has the column 'state'.
>
> An alternative that could be worth trying is putting the condition in
> your define_index block:
> where "model_versions.state = 'accepted'"
>
> Hope this provides some inspiration.
>
> Cheers
>
> --
> Pat
>
> On 21/05/2009, at 3:38 PM, Matt Todd wrote:
>
> >
> > I'm tasked with indexing a model that has associations (specifically,
> > this model acts_as_versioned so we have model_versions table that
> > we're indexing). This is really simple and works like a charm, but now
> > I need to be able to only index those versions that have a specific
> > column set to a specific value (the versions acts_as_state_machine so
> > we only want to index those that are marked as accepted).
> >
> > This means, our model should only be indexed when it is accepted.
> >
> > Now, I can easily handle this after the search returns normally, but
> > I'd rather not. It could be done easily by modifying the SQL generated
> > for the configuration file, but I can't determine how to modify the ON
> > condition for joins. Is this possible or easily patchable?
> >
> > For instance, i would want something like:
> >
> > SELECT
> > models.id * 1 + 0 AS id ,
> > CAST(models.name AS CHAR) AS name,
> > FROM models
> > LEFT OUTER JOIN models
> > ON model_versions.id = models.id AND model_versions.state =
> > 'accepted'
> > WHERE ...;
> >
> > Currently, my define_index block looks like this:
> >
> > define_index do
> > indexes versions.names, :as => :version_names
> > end
> >
> > But I'd like to be able to do something like:
> >
> > indexes versions.names, :as => :version_names, :if =>
> > ["model_versions.state = ?", "accepted"]
> >
> > :conditions could be used instead, since this should be rendered as a
> > condition statement.
> >
> > Obviously I've simplified things a bit, but all the essential
> > information should be here.
> >
> > ALTERNATIVELY, perhaps there's a way to use attributes and filters on
> > the search to create the same results? From my understanding, though,
> > since all of the field values are combined, there wouldn't be a way to
> > prevent select portions of the history.
> >
> > To be specific, the goal is to be able to search for the models and
> > only return the models that have been accepted. The problem comes in
> > that the models include pending and rejected versions (they are kept
> > in the history) and would thus get indexed.
> >
> > What sucks is that the model is always the most recent edit, even if
> > the most recent edit isn't the accepted version.
> >
> > One last alternative that I've just thought of would be to have a view
> > of accepted_model_versions that I would then make a model with and
> > define that as an index... or an attribute to filter on... hmm.
> >
> > Thanks for your input, if any ^_^
> >
> > Matt
> >
> >
> >
> > --
> > Matt Todd
> > Highgroove Studios
> > www.highgroove.com
> > cell: 404-314-2612
> > blog: maraby.org
> >
> > Scout - Web Monitoring and Reporting Software
> > www.scoutapp.com
> >
> > >
>
>
> >
>
--
Matt Todd
Highgroove Studios
www.highgroove.com
cell: 404-314-2612
blog: maraby.org
Scout - Web Monitoring and Reporting Software
www.scoutapp.com
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---