首页 > 解决方案 > SOLR 嵌套实体查询 (Oracle SQL DIH)

问题描述

我想以这样一种方式设置我的 SOLR (8.5.2) 架构,以便我可以查询父实体并在相同的结果中获取与其关联的子实体。例如:

{
  entityId: 1,
  entityName: "something"
  locations: [ ( <- nested entity)
   {
     locationId: 1,
     locationName: "something"
   },
   {
     locationId: 2,
     locationName "something"
   }
  ]
}

我已经设法从带有嵌套实体的 Oracle 数据库中导入数据,这是我的 dataconfig.xml

  <document name="entities">
    <entity name="entity"
            query="select * from LIC_ENTITIES" >
        <field column="ENT_ID" name="entityId"/>
        <field column="NOMBRE" name="entityName"/>
        
        <entity name="entity_locations" 
                child="true"
                query="select * from LIC_ENTITIES_LOCATIONS where ent_ent_id ='${entity.ENT_ID}'">
            <field column="LOC_ID" name="locationId"/>
            <field column="NOMBRE" name="locationName"/>        
        </entity>
        
    </entity>
        
  </document>

这是 schema.xml 字段配置:

    <!-- If you don't use child/nested documents, then you should remove the next two fields:  -->
    <!-- for nested documents (minimal; points to root document) -->
    <field name="_root_" type="string" indexed="true" stored="true" docValues="false" />
    
    <!-- for nested documents (relationship tracking) -->
    <field name="_nest_path_" type="_nest_path_" indexed="true" stored="true"/>
    <fieldType name="_nest_path_" class="solr.NestPathField" />

    <field name="_text_" type="text_general" indexed="true" stored="false" multiValued="true"/>
    
    <field name="entityId" type="pint" docValues="false" indexed="true" stored="true"/>
    <field name="entityName" type="string" docValues="false" indexed="true" stored="true"/>

    <field name="locationId" type="pint" docValues="false" indexed="true" stored="true"/>
    <field name="locationName" type="string" docValues="false" indexed="true" stored="true"/>

所有数据都导入了,我可以查询它就好了,但是我不能同时查询父实体和获取子实体。

我尝试使用子变压器(例如 [child parentFilter=entityId:274939]),但出现以下错误:

嵌套模式时不应发送父过滤器

我尝试过使用块连接查询(例如 q={!parent which="entityId:274939"}),但它只返回父记录或子记录。

我尝试使用多值字段来存储子元素,但它创建了一个平面数组,使得选择子元素变得更加困难。

我必须创建单独的实体,然后通过单独查询它们在 Node 中建立它们之间的关系,但我想通过让 SOLR 交付已经按照我想要的方式格式化的数据来简化它。

有什么办法可以达到这种效果吗?

标签: solrdataimporthandler

解决方案


不幸的是,当前可用的 DIH 不支持该字段,并且 solr 放弃了对 dih 的支持。目前它正在进行备用项目,几乎没有社区支持。


推荐阅读