Handling one to many relationship in solr

吃可爱长大的小学妹 提交于 2019-12-25 04:29:13

问题


I have a requirement where I have to handle one to many relationship in SOLR. Say , an entity Person can have multiple names(first name, last name, name type). Now the problem with this is that if I make first name , last name & name type as multi- valued field in my schema.xml it won't help.Because I will not be able figure out which first name will be associated to which last name and which name type. What I want is if I have a person say P1 with 2 names [name_type1,firstName1,lastName1] & [name_type2,firstName2,lastName2]. Now if I do a full text search firstName1 then I should get back P1. Is there any way to handling this use case in SOLR?


回答1:


If your documents looked like the following:

name.first.[type] = John
name.last.[type] = Smith

which can be defined as dynamic fields:

<dynamicField name="name.first.*" type="text" indexed="true"  stored="true" />
<dynamicField name="name.last.*" type="text" indexed="true" stored="true" />

and have copy field definitions in your config:

<copyField source="name.first.*" dest="text" maxChars="256" />
<copyField source="name.last.*" dest="text" maxChars="256" />

which will copy all your names into a 'text' field which can be searched on.

With this structure, if the field values are stored (versus just indexed) then it'll be possible to reconstruct all the names from a person document.



来源:https://stackoverflow.com/questions/29482222/handling-one-to-many-relationship-in-solr

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