Hi Pat,
It's slightly surprising that :conditions kicks Sphinx into extended match
mode, given that this is largely an implementation detail of the way that
:conditions does its job internally (i.e.
ThinkingSphinx::Search#conditions_as_query). For example, I'm using the :all
match mode, which works fine when the query contains a character that would
have special meaning in extended mode (e.g. "[email protected]"), but if I
decide to restrict this query to a specific field by supplying :conditions => {
:email_address => '[email protected]' } it doesn't work because extended
mode kicks in and the "@" is given a meaning I didn't intend. It's possible to
work around this by explicitly escaping the values I provide in :conditions but
that doesn't feel very natural.
The most superficial fix would be to automatically use Riddle.escape when
building the underlying query in #conditions_as_query if the match mode isn't
:extended, although that seems slightly circular given that #match_mode
automatically enables extended mode whenever :conditions is supplied. (We'd
have to look directly at options[:match_mode] to see what the user intended.)
So, being more sophisticated about it, is there any fundamental reason why
:conditions can't preserve the user's intended match mode by simulating it
within extended mode, so that they don't need to care about how :conditions is
implemented? This would mean using Riddle.escape when the user has specified
:all (or allowed the default to kick in), doing nothing when they have
specified :extended, and doing something more clever when :any, :phrase or
:boolean has been used. Similarly it would seem logical to apply the same
transformation to the general query string, so that both "@" signs would be
escaped in User.search('[email protected]', :conditions => { :email_address =>
'[email protected]' }) rather than just the one in :conditions.
What do you think about all this?
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.