Hi Patrick
To answer your first question - Sphinx doesn't have much in the way of date
functions, but there are a few available:
http://sphinxsearch.com/docs/manual-2.0.1.html#date-time-functions
It's worth noting that Sphinx stores dates and times as timestamps, so it's
just an integer calculating the number of seconds since 1st Jan 1970. This
means that 3 hours = 60 * 60 * 3 = 10800 seconds. And to compare times, you're
just finding the difference in integer values. Thinking Sphinx has a
:sphinx_select option to allow generating custom attributes on the fly, so this
should do the trick:
Post.search :conditions => {:title => params[:title], :description =>
params[:description]},
:sphinx_select => '*, (NOW() + 10800) - created_at AS difference"
And then you can use that value in a filter, or to sort by it.
And yes, to answer your second question, there's no difference between your
facets(args).for call and a straight search(args) call.
Cheers
--
Pat
On 27/01/2012, at 10:10 AM, patrick99e99 wrote:
> After doing some more reading on facets-- I am wondering if this is
> really the wrong way to go. From what I can tell, the point of facets
> is to get a quick breakdown of how many records have similar values,
> and then drill down from there.. ? The app that I am working on had
> most all of the TS code written before I joined the team.. And it
> looks like facets is the only method called for any sort of retrieval
> of records... I am thinking perhaps TS isn't being used
> appropriately-- For example, the index action does:
>
> @posts = Post.facets(:conditions => { :title =>
> params[:title], :description => params[:description] } ).for
>
> ...
>
> So in this context, there's no real reason to be using facets, right?
> That should just be a regular search method call, right?
>
> @posts = Post.search(:conditions => { :title =>
> params[:title], :description => params[:description] } )
>
> ... But still am wondering how should I add "TIMESTAMPDIFF(SECOND,
> posts.created_at, (SELECT DATE_ADD(NOW(), INTERVAL 3 HOUR))) as
> difference" to this search call?
>
> --
> 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.