问题描述
我的solr数据源中有多值字段.样品是
I have multivalued fields in my solr datasource. sample is
<doc>
<str name="id">23606</str>
<arr name="fecha_referencia">
<str>2020-05-24</str>
<str>2018-01-18</str>
<str>1997-07-22</str>
</arr>
<arr name="tipo_de_fecha">
<str>Publicacion</str>
<str>Creación</str>
<str>Edicion</str>
</arr>
</doc>
但是要点是,当我进行搜索时,我希望日期2020-05-24 属于出版物"日期类型,因为solr不处理位置,而是在reference_date和date_type数组之间查找至少一个匹配项.
But the point is that when I do a search I want the date 2020-05-24 to belong to the "Publication" date type, because solr does not handle positions but rather looks for at least one match between the Arrays of reference_date and date_type.
问题是:如何在solr中保留多值排序/映射?
这是我的data-config.xml结构:
This is my data-config.xml structure:
<dataConfig>
<dataSource type="JdbcDataSource" driver="org.postgresql.Driver" url="jdbc:postgresql://10.152.11.47:5433/metadatos" user="us_me" password="ntm" URIEncoding="UTF-8" />
<document >
<entity name="tr_ident" query="SELECT id_ident, titulo,proposito,descripcion,palabra_cve
FROM ntm_p.tr_ident">
<field column="id_ident" name="id_ident" />
<field column="titulo" name="titulo" />
<field column="proposito" name="proposito" />
<entity name="ti_fecha_evento"
query="select tipo_fecha,fecha_referencia from ntm_p.ti_fecha_evento where id_fecha_evento='${tr_ident.id_ident}'">
<field column="fecha_referencia" name="fecha_referencia" />
<entity name="tc_tipo_fecha" query="select des_tipo_fecha,id_tipo_fecha from ntm_p.tc_tipo_fecha where id_tipo_fecha='${ti_fecha_evento.tipo_fecha}'">
<field column="id_tipo_fecha" name="id_tipo_fecha" />
</entity>
</entity>
</entity>
</document>
</dataConfig>
推荐答案
请务必注意,只要存储了字段即可保留顺序(不仅仅启用了docValues)-第一个日期将是第一个日期已发送到该字段,然后可以将该字段映射到第二个字段中的第一个字段.
It's important to note that ordering is preserved as long as the field is stored (and not just have docValues enabled) - the first date will be the first date that was sent to the field, which can then be mapped to the first field in the second field.
但是,您要查找的是一个相关查询,其中每个字段都相对于另一个查询.在这种情况下,可以通过显式定义每个值或使用动态字段名将每个值本身索引为字段.
However, what you're looking for is a dependent query, where each field is queried in relation to the other. In that case, index each value as a field by itself - either by explicitly defining them, or by using a dynamic field name.
fecha_referencia_publicacion: "2020-05-24",
fecha_referencia_creacion: "2018-01-18",
...
通过这种方式,您可以像往常一样在字段上执行任何范围查询和构面.
That way you can perform any range queries and faceting on the field as usual.
或者,如果您只需要精确匹配,则可以将一个连接的值编入索引,其中类型和日期都被编入同一字段:
Alternatively, if you only need exact hits, you can index a concatenated value where both the type and the date is indexed into the same field:
fecha_referencia: "Publicacion_2020-05-24"
这篇关于在solr中保留多值的关联或位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!