首页 > 解决方案 > 在 solr 中保留多值的关联或位置

问题描述

我的 solr 数据源中有多值字段。样本是

  <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 的数组之间查找至少一个匹配项.

问题是:如何在 solr 中保留多值的排序/映射?

这是我的 data-config.xml 结构:

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

标签: solrfieldmultivalue

解决方案


重要的是要注意,只要存储字段(而不仅仅是启用 docValues),就会保留排序 - 第一个日期将是发送到该字段的第一个日期,然后可以映射到第二场。

但是,您要查找的是从属查询,其中每个字段都相对于另一个字段进行查询。在这种情况下,将每个值作为一个字段单独索引 - 通过显式定义它们或使用动态字段名称。

fecha_referencia_publicacion: "2020-05-24",
fecha_referencia_creacion: "2018-01-18",
...

这样您就可以像往常一样在该字段上执行任何范围查询和分面。

或者,如果您只需要精确命中,您可以索引一个连接值,其中类型和日期都被索引到同一字段中:

fecha_referencia: "Publicacion_2020-05-24"

推荐阅读