How to OR two joins in Solr

我的梦境 提交于 2020-01-14 03:12:35

问题


I have the following statement:

({!join from=project_uuid to=id}type:EM_PM_Timerecord AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z]) OR ({!join from=project_uuid to=id}type:EM_CM_Request_Member AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z])

It doesn't return any documents, but if I use only one of the joins e.g.:

{!join from=project_uuid to=id}type:EM_PM_Timerecord AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z]

It returns some documents.

If I remove the date ranges it works as well:

({!join from=project_uuid to=id}type:EM_PM_Timerecord) OR ({!join from=project_uuid to=id}type:EM_CM_Request_Member)

Can someone tell me what I'm missing? And what is wrong with the first statement?

Thanks in advance.

EDIT

In debug the parsed query looks like this:

(+JoinQuery({!join from=project_uuid to=id}type:EM_PM_Timerecord) +created:[1420074000000 TO 1451610000000]) (+JoinQuery({!join from=project_uuid to=id}type:EM_CM_Request_Member) +created:[1420074000000 TO 1451610000000])

And maybe I should mention that I use it as a filter query, but as far as i understand it that should not make a difference in the result.


回答1:


I asked now in the SolrUsers mailing list as recommended and I got an answer.

The query has to be split up in multiple queries like this:

&q={!join from=project_uuid to=id v=$q1} OR {!join from=project_uuid to=id v=$q2} 
&q1=type:EM_PM_Timerecord AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z] 
&q2=type:EM_CM_Request_Member AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z] 

and it works fine.

My problem was that I put the whole thing under &q=... and apparently that was to much.




回答2:


On Solr 5/6 only the following was working on my side:

&fq=_query_:"{!join from=project_uuid to=id v=$j1}" OR {!join from=project_uuid to=id v=$j2} 
&j1=type:EM_PM_Timerecord AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z] 
&j2=type:EM_CM_Request_Member AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z] 

OR

&fq=_query_:"{!join from=project_uuid to=id v=$j1}" {!join from=project_uuid to=id v=$j2} 
&j1=type:EM_PM_Timerecord AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z] 
&j2=type:EM_CM_Request_Member AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z]

I am not able to find any documentation about "_query_", i found the parameter on Solr join "not in" subselect

You dont need the OR it will be ignored, but the joins are in OR.

Important: The first join have to be in _query_:"...join..."

More examples with negation:

&fq=-_query_:"{!join from=project_uuid to=id v=$j1}" {!join from=project_uuid to=id v=$j2} 
&j1=type:EM_PM_Timerecord AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z] 
&j2=type:EM_CM_Request_Member AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z]

&fq=_query_:"{!join from=project_uuid to=id v=$j1}" {!join from=project_uuid to=id v=$j2} -{!join from=project_uuid to=id v=$j3} 
&j1=type:EM_PM_Timerecord AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z] 
&j2=type:EM_CM_Request_Member AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z]
&j3=type:EM_CM_Request_Member AND created:[2015-01-01T01:00:00Z TO 2016-01-01T01:00:00Z]


来源:https://stackoverflow.com/questions/39916297/how-to-or-two-joins-in-solr

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