我正在用solr为Mysql数据库建立索引,我的用户表和订单表之间存在一对多的关系:一个用户可以有很多订单。
订单表具有许多列(id,orderDate,caseNumber)。
我的目标是在solr中为这些表建立索引,并具有USR_ID
字段来存储用户ID,ORDERS
feild type =多维数组来将该用户的每个订单存储为关联数组。
所需的结果是:
{
"USR_ID":"10",
"ORDERS":[
{"ID":"1" ,"ORDER_DATE":"12-03-2018", "CASE_NUMBER":"554"}, //FIRST FIELD
{"ID":"9","ORDER_DATE":"15-03-2018", "CASE_NUMBER":"569"} //SECOND FIELD
]
}
我得到的是带有所有订单列的一维数组
{
"USR_ID":"10",
"ORDERS":[
"1", "12-03-2018", "554", //FIRST FIELD
"9", "15-03-2018", "569" //SECOND FIELD
]
}
这是我尝试过的。 data-config.xml
中的实体配置<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/mydb1"
user=""
password=""/>
<document>
<entity name="USERS"
pk="USR_ID"
query="SELECT USR_UID, FROM USERS"
deltaImportQuery="SELECT USR_UID, FROM USERS WHERE USR_UID='${dih.delta.USR_UID}'"
deltaQuery="SELECT USR_UID FROM USERS WHERE USERS.USR_UPDATE_DATE > '${dih.last_index_time}'">
<entity name="ORDER" pk="ID"
query="SELECT ID AS ORDERID, ORDER_DATE, CASE_NUMBER FROM ORDER WHERE USR_ID = '${USERS.USR_UID}'"
deltaQuery="select ID from ORDER where UPDATED_AT > '${dih.last_index_time}'"
parentDeltaQuery="SELECT USR_UID FROM USERS WHERE USR_UID = ${ORDER.USR_UID}">
<field column="ORDERID" name="ORDERS" />
<field column="CREATION_DATE" name="ORDERS" />
<field column="CASE_NUMBER" name="ORDERS" />
</entity>
</entity>
</document>
</dataConfig>
这是schema.xml文件中的字段定义
<field name="USR_ID" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="ORDERS" type="text_general" indexed="true" stored="true" required="false" multiValued="true"/>
答案 0 :(得分:1)
您将必须使用子文档,或者至少要按顺序拥有一个文档,因为您仅在根级别具有ID:
std::vector<std::vector<cv::Point>> contours;
testfunction(contours);
std::cout << contours.size() << std::endl;
for (size_t i = 0; i < contours.size(); i++) {
std::vector<cv::Point>& cont = contours[i];
std::cout << cont.size() << std::endl;
for (size_t j = 0; j < cont.size(); j++) {
std::cout << cont[j] << std::endl;
}
}
请参阅嵌套文档的这种良好用法: http://yonik.com/solr-nested-objects/
答案 1 :(得分:0)
答案是,当您定义data-config.xml文件时,请在child="true"
字段中使用以下属性
就我而言
<entity child="true" name="ORDER" pk="ID"
query="SELECT ID AS ORDERID, ORDER_DATE, CASE_NUMBER FROM ORDER WHERE USR_ID = '${USERS.USR_UID}'"
deltaQuery="select ID from ORDER where UPDATED_AT > '${dih.last_index_time}'"
parentDeltaQuery="SELECT USR_UID FROM USERS WHERE USR_UID = ${ORDER.USR_UID}">
<field column="ORDERID" name="ORDERS" />
<field column="CREATION_DATE" name="ORDERS" />
<field column="CASE_NUMBER" name="ORDERS" />
</entity>