【问题标题】:preserve association or position in multivalued in solr在 solr 中保留多值的关联或位置
【发布时间】:2020-08-18 16:24:35
【问题描述】:

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

但重点是,当我进行搜索时,我希望 date 2020-05-24 属于 “Publication”日期类型,因为 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>

【问题讨论】:

    标签: solr field multivalue


    【解决方案1】:

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

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

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

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

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

    fecha_referencia: "Publicacion_2020-05-24"
    

    【讨论】:

    • 这是一个很好的答案,我向您展示了有关我的问题的更多详细信息:我通过 DIH 进行索引,因为主要来源是 postgresql,所以我将日期和 data_type 保存在多值字段中,因为它origin 来自 postgresql 的 m 到 m 关系,正如你所提到的,它可以通过连接来索引,但由于我使用日期范围,我发现用这种方法很难做到这一点。所以我不知道它是否可以通过一个场来完成,并用变压器将它们分成辅助场。你能给我一个联系方式来谈谈这个吗?我很绝望!
    • 我不确定您是否可以在字段名称中使用 TemplateTransformer,但它会类似于 field_name_${ti_fecha_evento.fecha_referencia}。您还需要将transformer="TemplateTransformer"` 添加到您的实体定义中。另一种选择是use a script processor to transform the field names(它允许您将任意 Javascript 附加到处理管道)。
    • 有趣的朋友,我会继续研究更多关于脚本转换器来构建动态字段。因为考虑到数据的来源是关系数据库,我看不到另一种选择可以将那些多个值放在单独的值中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    • 2014-07-18
    • 2017-01-23
    相关资源
    最近更新 更多