SphinxQL比较json属性

时间:2019-02-08 02:46:07

标签: sphinx

我有一个像这样的json字符串:

{"mo":[{"from":800,"to":1100},{"from":1400,"to":1700}],"di":[{"from":800,"to":1100},{"from":1400,"to":1700}],"do":[{"from":800,"to":1100},{"from":1400,"to":1700}],"mi":[{"from":800,"to":1100}],"fr":[{"from":800,"to":1300}],"so":[],"sa":[]}

包含json字符串的mysql字段在配置中声明为sql_attr_json

以下WHERE条件可以正常工作:

WHERE json.mo[0].from < 1100

但是,以下内容却没有:

WHERE json.mo[0].from < json.mo[0].to

它导致:

sphinxql: syntax error, unexpected IDENT near 'json.mo[0].to

那是为什么?我正在尝试对开放时间进行检查,但不幸的是我这样做非常困难,我尝试了十二种不同的方法,但似乎没有任何效果。

更新

我也在尝试:

WHERE (DATE_FORMAT(NOW(),'%H%i') between json.mo[0].from and json.mo[0].to) 

导致

sphinxql: syntax error, unexpected '(' near '(NOW(),'%H%i')) between json.mo[0].from and json.mo[0].to)

即使是基本的

SELECT DATE_FORMAT(NOW(),'%H%i') < 1050

导致相同的错误

 Sphinx expr: syntax error, unexpected '(', expecting $end near '(NOW(),'%H%i') < 1050'

作为一种解决方法,我也尝试过

SELECT CONCAT(HOUR(NOW()), MINUTE(NOW())) currentTime;

但这会导致

sphinxql: syntax error, unexpected $end, expecting FROM or ',' near 'currentTime'

在MySQL中它可以正常工作

1 个答案:

答案 0 :(得分:0)

尚未实施。请尝试以下解决方法:

mysql> select *, INTEGER(j.mo[0].to) - INTEGER(j.mo[0].from) diff from rt where diff > 0\G
*************************** 1. row ***************************
  id: 1
   s:
   j: {"mo":[{"from":800,"to":1100},{"from":1400,"to":1700}],"di":[{"from":800,"to":1100},{"from":1400,"to":1700}],"do":[{"from":800,"to":1100},{"from":1400,"to":1700}],"mi":[{"from":800,"to":1100}],"fr":[{"from":800,"to":1300}],"so":[],"sa":[]}
diff: 300
1 row in set (0.00 sec)

在Manticore Search(Sphinx的分叉)中对我来说工作正常,在Sphinx中也应该工作正常。