问题
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