Hi Slava

I think the escaping is just an issue with the Rails logging side of things. 
I’ve tested queries directly with Sphinx, and through Rails, both with quotes, 
and they’re appearing the same in Sphinx’s logs:

# in a MySQL console connected to Sphinx:
mysql> SELECT * FROM spree_product_core WHERE MATCH('"apple"’);
# and in a Rails console:
> Spree::Product.search ‘"apple"'

The result in `log/development.searchd.query.log`:

[Mon May  9 21:11:36.231 2016] 0.001 sec 0.001 sec [ext2/1/ext 673 (0,20)] 
[spree_product_core] "apple"
[Mon May  9 21:13:01.752 2016] 0.001 sec 0.001 sec [ext2/0/ext 673 (0,20)] 
[spree_product_core] "apple"

And if I use NEAR, even though I get the escaping happening in the Rails 
log/console, I still get the expected results:

> Spree::Product.search ‘"granny smith" NEAR/2 "apple"'
  Sphinx Query (1.3ms)  SELECT * FROM `spree_product_core` WHERE 
MATCH('\"granny smith\" NEAR/2 \"apple\"') AND `sphinx_deleted` = 0 LIMIT 0, 20
  Sphinx  Found 61 results

I’m not sure the NEAR operator works like you’re expecting? Are you wanting 
exact matches of “by law”? Or are you looking for “law in law” or “in law law”?

— 
Pat

> On 6 May 2016, at 2:46 AM, Slava Yakobson <[email protected]> wrote:
> 
> 
> I am trying to use NEAR operator with two sentences - which means I need to 
> use double quotes for each sentence. I've tried multiple ways trying to get 
> it to work without luck.
> 
> 
> 1.
> q = '"law" NEAR/1 "by law"'
> Frame::Decision.search(q).count
> 
> Output: Sphinx Query (1.5ms)  SELECT * FROM `frame_decision_core` WHERE 
> MATCH('\"law\" NEAR/1 \"by law\"') AND `sphinx_deleted` = 0 LIMIT 0, 20
> 
> 2.
> q = %q("law" NEAR/1 "by law")
> Frame::Decision.search(Riddle::Query.escape(q)).count
> 
> Output:  Sphinx Query (1.1ms)  SELECT * FROM `frame_decision_core` WHERE 
> MATCH('\\\"law\\\" NEAR\\/1 \\\"by law\\\"') AND `sphinx_deleted` = 0 LIMIT 
> 0, 20
> 
> 3.
> q = '"law" NEAR/1 "by law"'
> Frame::Decision.search(q).count
> 
> Output: Sphinx Query (1.3ms)  SELECT * FROM `frame_decision_core` WHERE 
> MATCH('\"law\" NEAR/1 \"by law\"') AND `sphinx_deleted` = 0 LIMIT 0, 20
> 
> 
> 
> My guess is that using double quotes results in escape back slashes which 
> breaks things. The output probably has to look like this: MATCH('"law" NEAR/1 
> "by law"')
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/thinking-sphinx 
> <https://groups.google.com/group/thinking-sphinx>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.


-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.

Reply via email to