我正在使用Solr开发搜索引擎,并且我已成功使用DIH(Dataimport Handler)从一个表索引数据。我需要的是从 5个不同的表中获取搜索结果。没有帮助,我无法做到这一点。
如果我们假设x表有x行,那么每个表应该有x * x个文档,如果我总共有5个表,则会产生5个文档。在dataconfig.xml中,我在单个文档中创建了5个单独的实体,如下所示。当我查询*:*
时,索引数据的结果只有6个实体用户,3个来自实体类,即用户总行数为9。
显然,这种方式对我不起作用,那么如何才能使用单核实现这一目标呢?
注意:我关注了DIHQuickStart和DIH tutorial这对我没有帮助。
<document>
<!-- Users -->
<entity dataSource="JdbcDataSource" name=" >
<field column="name" name="name" sourceColName="name" />
<field column="username" name="username" sourceColName="username"/>
<field column="email" name="email" sourceColName="email" />
<field column="country" name="country" sourceColName="country" />
</entity>
<!-- Classes -->
<entity dataSource="JdbcDataSource" name="classes" >
<field column="code" name="code" sourceColName="code" />
<field column="title" name="title" sourceColName="title" />
<field column="description" name="description" sourceColName="description" />
</entity>
<!-- Schools -->
<entity dataSource="JdbcDataSource" name="schools" >
<field column="school_name" name="school_name" sourceColName="school_name" />
<field column="country" name="country" sourceColName="country" />
<field column="city" name="city" sourceColName="city" />
</entity>
<!-- Resources -->
<entity dataSource="JdbcDataSource" name="resources" >
<field column="title" name="title" sourceColName="title" />
<field column="description" name="description" sourceColName="description" />
</entity>
<!-- Tasks -->
<entity dataSource="JdbcDataSource" name="tasks" >
<field column="title" name="title" sourceColName="title" />
<field column="description" name="description" sourceColName="description" />
</entity>
</document>
答案 0 :(得分:1)
您需要查看表的结构,然后创建带有连接的查询或创建嵌套实体,例如
<dataConfig>
<dataSource driver="org.hsqldb.jdbcDriver" url="jdbc:hsqldb:/temp/example/ex" user="sa" />
<document name="schools">
<entity name="school" query="select * from schools s ">
<field column="school_name" name="school_Name" />
<entity name="school_class" query="select * from schools_classes sc where sc.school_name = '${school.school_name}'">
<field column="class_code" name="class_code" />
<entity name="class" query="select class_name from classes c where c.class_name= '${school_class.class_code}'">
<field column="class_name" name="class_name" />
</entity>
</entity>
</entity>
</document>
</dataConfig>