Hi Pat,

On Feb 16, 12:07 am, Pat Allan <[email protected]> wrote:
> Sphinx can't do field-specific queries in any match mode *but* extended. 
> Therefore, if you're using :conditions, then it doesn't make any sense to use 
> anything else.

You're right, of course, but what I'm asking is whether there's
necessarily any reason why a Thinking Sphinx user has to know or care
about this. TS is so wonderful precisely because it already hides a
lot of Sphinx's complexity, and this seems like another area where it
could easily do more to make things "just work" instead of leaking
knowledge about how Sphinx is implemented.

Here's how to search all user fields for an email address: User.search
'[email protected]'

Here's how to search only the user email address field for an email
address: User.search '', :conditions => { :email_address => 'tom
\[email protected]' }

Why do you have to escape the "@" in the second case? Because when you
say :conditions, Thinking Sphinx automatically kicks into extended
match mode, and in that mode you have to escape characters that
otherwise would've worked fine in the match mode you were trying to
use. Why does it automatically force a more sophisticated match mode
than the one you asked for? Because the Thinking Sphinx implementation
needs to give Sphinx an extended mode query string in order to
implement the functionality you're specifying by providing
a :conditions hash.

The alternative would be for Thinking Sphinx to maintain the intended
interpretation of the user's query even if it has to switch to a
different match mode to get the job done. Right now, if the incoming
call is "User.search '', :match_mode => :all, :conditions =>
{ :email_address => '[email protected]' }", Thinking Sphinx will
behave as though the call was actually "User.search '', :match_mode
=> :extended, :conditions => { :email_address =>
'[email protected]' }", which won't work because it's changed the
match mode (from what the caller expected) without accounting for the
effect this will have on the interpretation of the contents
of :conditions.

So why not make Thinking Sphinx handle this case correctly? Why not,
when automatically switching the match mode to :extended, also
automatically rewrite the query so that it still means the same thing?
In this case we could easily arrange for #conditions_as_query to
automatically Riddle.escape each value in the :conditions hash so that
those conditions retain their intended meaning, and the caller would
never know that we're getting the job done by actually using a
different match mode to the one he asked for.

I'm not suggesting that the fix would be this simple in all cases
(e.g. how would we rewrite the contents of :conditions if the user
specified boolean match mode?), I'm just asking whether you agree in
principle that this would be useful (or possible?) behaviour. To me it
feels that it would be consistent with the overall philosophy of
Thinking Sphinx, but perhaps you feel that it's "too much magic" and
that users should just have to deal with the fact that you can't drop
an unescaped search string into :conditions and expect it to work.

Cheers,
-Tom

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

Reply via email to