Solr加入"不在"子查询

时间:2014-07-09 10:53:12

标签: solr

在Solr联接文档Solr Join中,他们说:

/solr/collection1/select ? fl=xxx,yyy & q={!join from=inner_id to=outer_id}zzz:vvv

相当于:

SELECT xxx, yyy
FROM collection1
WHERE outer_id IN (SELECT inner_id FROM collection1 where zzz = "vvv")

如何在Solr中书写(参见NOT):

SELECT xxx, yyy
FROM collection1
WHERE outer_id NOT IN (SELECT inner_id FROM collection1 where zzz = "vvv")

让我们考虑以下例子:
人事记录:

1. name='a', id=1, teacherId=4
2. name='b', id=2, teacherId=4
3. name='c', id=3, teacherId=1
4. name='d', id=4, isTeacher='true'

现在我想选择他们的老师指向非教师ID的所有学生(记录#3) 在SQL中:

select * from people where teacherId not in (select id where isTeacher='true').

3 个答案:

答案 0 :(得分:1)

请尝试将“ - ”放在整个联接过滤器之外,如下所示:

/ solr / collection1 / select? fl = xxx,yyy& q = - ({!join from = inner_id to = outer_id} zzz:vvv)

答案 1 :(得分:1)

我也遇到过这个问题而且我是如何解决的:

q=-_query_:"{!join from=inner_id to=outer_id}zzz:vvv"

您也可以将此nested query添加到fq

希望有所帮助!)

答案 2 :(得分:0)

如果

SELECT xxx, yyy
FROM collection1
WHERE outer_id NOT IN (SELECT inner_id FROM collection1 where zzz = "vvv")

相当于

SELECT xxx, yyy
FROM collection1
WHERE outer_id IN (SELECT inner_id FROM collection1 where zzz != "vvv")

其中NOT IN变为INzzz = "vvv"变为zzz != "vvv",则否定实际查询应该有效。

/solr/collection1/select ? fl=xxx,yyy & q={!join from=inner_id to=outer_id}-zzz:vvv

请注意-zzz:vvv