Apache Solr:如何在子实体中执行查询,该子实体依赖于主实体

时间:2018-03-15 17:14:19

标签: sql solr dataimporthandler

如何在依赖于字段的子实体中执行查询 来自主要实体的价值?

因此,您可以在下面的(简化)数据配置中看到,有一个实体 categories_lvl_0包含昂贵的查询。我只想执行 此查询if:searchobject.objecttype = 115

我尝试使categories_lvl_0依赖于if语句:IF (${searchobject.objecttype}=115),我尝试使用和不使用BEGIN...END包装查询,但所有这些选项都会抛出错误:< / p>

  

处理文件#1 at   org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:266)   在   org.apache.solr.handler.dataimport.DataImporter.doFullImport(DataImporter.java:422)   在   org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:487)   在   org.apache.solr.handler.dataimport.DataImporter $ 1.run(DataImporter.java:468)   引起:java.lang.RuntimeException:   org.apache.solr.handler.dataimport.DataImportHandlerException:无法使用   执行查询:IF(1 = 115)SELECT slug_nl as slug_nl_0,slug_en   as slug_en_0,label_nl as label_nl_0,label_en as label_en_0 FROM   articlegroups ga WITH(NOLOCK)INNER JOIN products_category_mapping   pcm在pcm.articlegroup_id = ga.id INNER JOIN产品gp on   gp.id = pcm.artikelid WHERE gp.artikelnummer ='1000'AND ga.catlevel = 0

我该如何配置?

<dataConfig> 
<dataSource name="ds-sql" driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://localhost:1433;databaseName=mydb" user="myuser" password="mypwd" /> 

<document name="searchobjects"> 
    <entity name="searchobject" pk="id" dataSource="ds-sql" query="SELECT c.objecttype,c.id,c.title FROM locations c UNION SELECT 115 as objecttype,c.id,c.title FROM products c">  
        <field name="id" column="id" /> 
        <field name="objecttype" column="objecttype" /> 
        <field name="title" column="title" /> 

        <entity name="categories_lvl_0" dataSource="ds-sql" query="SELECT slug_nl as slug_nl_0,slug_en as slug_en_0,label_nl as label_nl_0,label_en as label_en_0 
        FROM articlegroups ga WITH (NOLOCK) 
        INNER JOIN products_category_mapping pcm on pcm.articlegroup_id=ga.id 
        INNER JOIN products gp on gp.id=pcm.artikelid 
        WHERE gp.artikelnummer='${searchobject.id}' AND ga.catlevel=0"> 
        </entity>   
    </entity> 
</document> 
</dataConfig> 

1 个答案:

答案 0 :(得分:1)

似乎无法在data-config中编写更复杂的SQL,因此我最终调用了带参数的存储过程。在存储过程中,我可以编写更复杂的逻辑。数据配置示例:

<entity name="categories_lvl_0" dataSource="ds-sql" query="[_getSolrProductCategoriesLvl0] '${searchobject.objecttype}', '${searchobject.id}'"> 
</entity>

此处有更多详情:calling stored procedure from solr