Ranges in search conditions

420 views
Skip to first unread message

Sarniak

unread,
Mar 26, 2010, 7:00:14 AM3/26/10
to Thinking Sphinx
Hi!
I would like to build such query in sphinx:

(start_date >= date.today AND start_date <= date.today + 23.hours +
59minutes) OR (start_date <= date.today AND end_date >= date.today)

I found using ranges in shinx like:

:start_date => 1.week.ago..Time.now

And I could use it, but only for either first or second part of OR. Is
there possibility to somehow combine two parts of OR statement in
sphinx?

Regards
Lucas

Pat Allan

unread,
Mar 28, 2010, 1:18:57 AM3/28/10
to thinkin...@googlegroups.com
Hi Lucas

Unfortunately, the only way you can have OR behaviours in filters is searching across multi-value arrays (which are integers). Ranges don't have this ability.

Sorry - good luck finding a solution that works around this limitation.

--
Pat

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

Tiago Franco

unread,
Apr 6, 2010, 6:45:55 PM4/6/10
to Thinking Sphinx
Hi,

I'm having the same issue. Is there a workaround for this?

Thanks,
Tiago Franco

On Mar 28, 6:18 am, Pat Allan <p...@freelancing-gods.com> wrote:
> Hi Lucas
>

> Unfortunately, the only way you can have OR behaviours in filters is searching across multi-value arrays (which are integers).Rangesdon't have this ability.


>
> Sorry - good luck finding a solution that works around this limitation.
>
> --
> Pat
>
> On 26/03/2010, at 10:00 PM, Sarniak wrote:
>
> > Hi!
> > I would like to build such query in sphinx:
>
> > (start_date >= date.today AND start_date <= date.today + 23.hours +
> > 59minutes) OR (start_date <= date.today AND end_date >= date.today)
>

> > I found usingrangesin shinx like:

Tiago Franco

unread,
Apr 7, 2010, 7:25:29 AM4/7/10
to Thinking Sphinx
Ok, this is how I've done it.

Create an attribute index based on an SQL snippet (inside define_index
do...end):

has "CASE WHEN run_time IS NULL THEN 0 WHEN run_time < 30 THEN 1 WHEN
run_time > 30 AND run_time < 60 THEN 2 ELSE 3 END", :type
=> :integer, :as => :run_time_mapping


Then just search by that attribute (i.e. Music.search :with =>
{:run_time_mapping => [0,1]} )

Hope it helps.

Tiago Franco

Tiago Franco

unread,
Apr 8, 2010, 6:20:34 PM4/8/10
to Thinking Sphinx
Pat, can you had this tip to the thinking sphinx documentation?

I think it can be useful.

Regards,
Tiago Franco

Pat Allan

unread,
Apr 10, 2010, 12:49:09 AM4/10/10
to thinkin...@googlegroups.com
Good suggestion Tiago - have just done so.
http://freelancing-god.github.com/ts/en/common_issues.html#range_or

Cheers

--
Pat

Tiago Franco

unread,
Apr 13, 2010, 6:11:24 AM4/13/10
to Thinking Sphinx
Thanks :)

On Apr 10, 5:49 am, Pat Allan <p...@freelancing-gods.com> wrote:
> Good suggestionTiago- have just done so.http://freelancing-god.github.com/ts/en/common_issues.html#range_or


>
> Cheers
>
> --
> Pat
>
> On 09/04/2010, at 8:20 AM,TiagoFrancowrote:
>
> > Pat, can you had this tip to the thinking sphinx documentation?
>
> > I think it can be useful.
>
> > Regards,
> >  TiagoFranco
>

> > On Apr 7, 12:25 pm,TiagoFranco<gama.fra...@gmail.com> wrote:
> >> Ok, this is how I've done it.
>
> >> Create an attribute index based on an SQL snippet (inside define_index
> >> do...end):
>
> >> has "CASE WHEN run_time IS NULL THEN 0 WHEN run_time < 30 THEN 1 WHEN
> >> run_time > 30 AND run_time < 60 THEN 2 ELSE 3 END", :type
> >> => :integer, :as => :run_time_mapping
>
> >> Then just search by that attribute (i.e. Music.search :with =>
> >> {:run_time_mapping => [0,1]} )
>
> >> Hope it helps.
>
> >>TiagoFranco
>

Reply all
Reply to author
Forward
0 new messages