Solr join “not in” subselect

*爱你&永不变心* 提交于 2019-12-17 19:54:32

问题


In the Solr join documentation Solr Join they say that:

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

is equivalent to:

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

How do I write in Solr (see the NOT):

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

Lets consider the following example:
People Records:

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'

Now I want to select all students which their teacherId points to non teacher ID (record #3).
In SQL:

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

回答1:


Please try put "-" outside of the whole join filter, like below:

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




回答2:


I'm faced with this problem too and that's how I resolved it:

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

You can add this nested query to fq too.

Hope that helps!)




回答3:


If

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

is equivalent to

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

where NOT IN becomes IN and zzz = "vvv" becomes zzz != "vvv", then negating the actual query should work.

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

Note the -zzz:vvv.



来源:https://stackoverflow.com/questions/24651759/solr-join-not-in-subselect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!