Solr,响应中不存在空值

时间:2019-10-01 08:33:52

标签: database solr

我正在使用DataImportHandler将数据从SQL Server加载到Solr(版本7.7.2)。我有2个表包含不同的列。

<document>
<entity name="users"
query="SELECT * FROM Users">
 <field column="IndexId" name="IndexId" />  
 <field column="Id" name="IdUsers"/>
 <field column="name" name="name"/>
 <field column="location" name="location"/>   
</entity>

<entity name="products" query="SELECT Id,ISNULL(name, 'default') as name,ISNULL(size, 'default') as size FROM products">
 <field column="IndexId" name="IndexId" />  
 <field column="Id" name="IdProducts"/>   
 <field column="name" name="name"/>   
 <field column="size" name="size"/>   
</entity>
</document>

我数据库上的某些记录为空,并且在solr查询响应中不存在。我想显示列名称及其值,即使它在solr响应中为null。

我尝试在字段上使用default=""。但是它将返回schema.xml上的所有字段。我只希望基于查询返回特定表字段上的字段。如何做到这一点?

谢谢

1 个答案:

答案 0 :(得分:1)

在sql查询中,可以使用ISNULL函数返回该列的备用值。

public  String FailureScreenshotAndroid(String name) {
            try {
                Date d = new Date();
                String date = d.toString().replace(":", "_").replace(" ", "_");
                TakesScreenshot t = (TakesScreenshot)driver;
                File f1 = t.getScreenshotAs(OutputType.FILE);//Temporary Location
                String permanentLocation =System.getProperty("user.dir")+ "\\Screenshots\\"+name+date+".png";
                File f2 = new File(permanentLocation);
                FileUtils.copyFile(f1, f2);
                return permanentLocation;
            }catch (Exception e) {
                String msg = e.getMessage();
                return msg;
            }
        }

上面的查询将返回一个空字符串,其中的值为null,并且该空字符串将被索引到Solr中。