Excluding an indexed field from search; logic between :with filters

10 views
Skip to first unread message

Phantom

unread,
Nov 24, 2009, 5:04:56 PM11/24/09
to Thinking Sphinx
Hi.

Please help! I am at my wits end here, trying to do a simpliest
thing :)

Here it goes.

index:

...
indexes name
indexes note.description, :as => :note_description

has note.created_at, :as => :note_created_at
has note.author_id, :as => :note_author_id
...

1)
Is there no other way to exclude an indexed field from search, besides
switching to :extended2 mode, and prepending a "@(fields,to,search)"
to the search string?

btw this method does not work with the ":star => true", because that
prepended "@(fields,to,search)" also gets affected. But that is not a
problem, and in no way a feature request ;)

2)
When doing a search like:

Model.search "blah blah", :with => { :note_author_id =>
[10], :note_created_at => some_range }

I get records with :note_author_id = 10 OR :note_created_at within
certain range. Is there no way to force AND logic between filter
hashes? I somehow thought that AND logic was the default behaviour.

Pat Allan

unread,
Nov 25, 2009, 3:28:27 AM11/25/09
to thinkin...@googlegroups.com
On 25/11/2009, at 9:04 AM, Phantom wrote:

> Here it goes.
>
> index:
>
> ...
> indexes name
> indexes note.description, :as => :note_description
>
> has note.created_at, :as => :note_created_at
> has note.author_id, :as => :note_author_id
> ...
>
> 1)
> Is there no other way to exclude an indexed field from search, besides
> switching to :extended2 mode, and prepending a "@(fields,to,search)"
> to the search string?

Unfortunately, the @(all,fields,but,one) option is the only way I know
of to exclude a specific field from your searching.

> btw this method does not work with the ":star => true", because that
> prepended "@(fields,to,search)" also gets affected. But that is not a
> problem, and in no way a feature request ;)
>
> 2)
> When doing a search like:
>
> Model.search "blah blah", :with => { :note_author_id =>
> [10], :note_created_at => some_range }
>
> I get records with :note_author_id = 10 OR :note_created_at within
> certain range. Is there no way to force AND logic between filter
> hashes? I somehow thought that AND logic was the default behaviour.

It should definitely be using AND - there's no way for multiple
filters to be done with OR logic. Can you provide some examples of the
data you're using in the filters?

Cheers

--
Pat

Phantom

unread,
Nov 25, 2009, 8:33:01 AM11/25/09
to Thinking Sphinx
Model.search_for_ids :conditions => {:name => '@
(name,note_description) *blah*'},
:match_mode => :extended2,
:per_page => 100, :max_matches => 100,
:with => {:note_person_id => 1234, :note_created_at =>
1.week.ago..Time.now},
:group_by => 'id',
:group_function => :attr,
:group_clause => '@relevance desc'

The AND logic between filters works unless i try to filter by date
range on an association.
In the case above the results will all contain 'blah' in them, will
all have 'note' with person_id = 1234 AND will have a 'note' with
create_at inside a range, bot NOT necessarily with id 1234.

Speaking sql language:

I expect the simple
... LEFT JOIN notes WHERE notes.person_id = 1234 AND notes.created_at
> week_ago AND notes.created_at < now

I get
... LEFT JOIN notes a LEFT JOIN notes b WHERE a.person_id = 1234 AND
b.created_at > week_ago AND b.created_at < now

I very much hope you get the idea. This is the best example i can
think of.

Pat Allan

unread,
Nov 25, 2009, 6:02:32 PM11/25/09
to thinkin...@googlegroups.com
Ah, the issue here is that you're expecting Sphinx to have some
knowledge about which created_at value in your notes association is
tied to which person_id value.

Unfortunately, all Sphinx is doing is storing arrays of integers -
attributes can only be single values, or arrays, nothing more
intelligent than that.

An alternative could be to store the note ids as an attribute on your
main model, and do a normal find for notes with that person_id and
within the date range, and then filter by the ids of those Notes. I
realise it's not as neat, but it should work within Sphinx's
constraints.

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

Reply all
Reply to author
Forward
0 new messages