我有一个查询,我想用思考sphinx来运行同样的事情,但我遇到HAVING
子句的问题。相关代码如下:
#technology_index.rb
has taggings.tag_id, :as => :tag_id
has id, :as => :technology_id
#technology.rb
search(params[:query],
with: { tag_id: params[:filter].values.flatten },
group_by: :technology_id,
having: "COUNT(`technology_id`)=#{params[:filter].size}"
)
这会引发以下错误(错误消息中的新行是我的):
sphinxql: syntax error, unexpected IDENT, expecting '*' near '`technology_id`)=1 LIMIT 0, 20;
SHOW META' - SELECT *, groupby() AS sphinx_internal_group, id AS sphinx_document_id,
count(DISTINCT sphinx_document_id) AS sphinx_internal_count
FROM `technology_core` WHERE MATCH('fibrosis') AND `tag_id` IN (2)
AND `sphinx_deleted` = 0 GROUP BY `technology_id` HAVING COUNT(`technology_id`)=1
LIMIT 0, 20; SHOW META
问题在于having:
子句,因为如果删除它,至少查询有效。
从2.2.1 beta HAVING
is supported(使用2.2.6),the same for TS 3.1(使用3.1.2)开始。我无法在文档中找到任何信息about use of HAVING,但如果我尝试having: "COUNT(*)>1"
之类的内容,我猜错了,我只是错误地调用了它。将having:
与TS一起使用的正确方法是什么?
答案 0 :(得分:0)
狮身人面像仍然不支持像having: "COUNT('technology_id')=#{params[:filter].size}"
这样的东西
无论如何,当我按having: "COUNT(*)=#{params[:filter].size}
进行分组时,我的查询与technology_id
一起使用。