【发布时间】:2014-12-04 22:45:52
【问题描述】:
我有一个查询,我想用 Think 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 一起使用的正确方法应该是什么?
【问题讨论】: