solr join查询
CROSS-DOCUMENT JOINS
solr 的join相当于SQL的nested join;solr join query的语法如下:
/select?fl=RETURN_FIELD_1, RETURN_FIELD_2&q={!join from=FROM_FIELD
to=TO_FIELD}CONSTRAINT_FIELD:CONSTRAINT_VALUE
对比SQL表达式为:
Select RETURN_FIELD_1, RETURN_FIELD_2 FROM join-data
WHERE TO_FIELD IN (
SELECT FROM_FIELD from join-data
WHERE CONSTRAINT_FIELD= 'CONSTRAINT_VALUE'
)
但是solr的这种join query并不是真正的传统SQL join query,因为solr 的这种join不能返回子查询的内容,子查询只用来限制主查询的返回内容。
但是上面这种join都是在一个core里面query的。
CROSS-CORE JOINS
只要join query的core都在一个solr instance 上,那么就可以cross-core join。
例如:
Restaurant core’s schema.xml
<field name="id" indexed="true" stored="true" />
<field name="restaurantname" indexed="true" stored="true" />
<field name="description" indexed="true" stored="false" />
User actions core’s schema.xml
<field name="id" type="string" indexed="true" stored="true" />
<field name="userid" type="string" indexed="true" stored="true" />
<field name="restaurantid" type="string" indexed="true" stored="true" />
<field name="actiontype" type="string" indexed="true" stored="false" />
<field name="actiondate" indexed="true" stored="false" />
我么可以使用如下查询
http://localhost:8983/solr/join_restaurants/select?
fl=restaurantname,text&
q="Indian"&
fq={!join fromIndex=join_useractions
toIndex=join_restaurants
from=restaurantid
to=id}userid:user123 AND actiontype:clicked
AND actiondate:[NOW-14DAYS TO *]
转自:http://blog.csdn.net/acmilanvanbasten/article/details/35804883