【问题标题】:Solr Encoding/Decoding DataSolr 编码/解码数据
【发布时间】:2012-03-06 06:02:49
【问题描述】:

我正在尝试向 Solr 发送一个编码字符串,然后在检索时对其进行解码。我的编码看起来像:

public static String compress(String inputString) {
    try {
        if (inputString == null || inputString.length() == 0) {
            return null;
        }
        return new String(compress(inputString.getBytes("UTF-8")));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}


private static byte[] compress(byte[] input) {
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        GZIPOutputStream gzip = new GZIPOutputStream(out);
        gzip.write(input);
        gzip.close();
        return out.toByteArray();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

然后我将它发送到 SOLR,当我尝试取回它时(暂时忽略解码,因为它在这里失败)

SolrDocument resultDoc = iter.next();
String content = (String) resultDoc.getFieldValue("source");
System.out.println(content);

如果我发送一个字符串,例如“你好,我的名字是 Chris”,编码后的样子(忽略堆栈溢出的变化);

 ã�������ÛHÕ……W»≠T»KÃMU»,VpŒ( ,�ìùùG���

然而我从 SOLR 得到的是

#31;ã#8;#0;#0;#0;#0;#0;#0;#0;ÛHÕ……W»≠T»KÃMU»,VpŒ( ,#6;#0;ìùùG#22;#0;#0;#0;

这显然会使解码失败。我尝试使用 Jetty 安装和 Tomcat 都遇到同样的问题。

【问题讨论】:

    标签: java encoding solr decode


    【解决方案1】:

    从 Solr 发行版附带的示例 schema.xml 文件中查看此条目。

    <!--Binary data type. The data should be sent/retrieved in as Base64 encoded Strings -->
    <fieldtype name="binary" class="solr.BinaryField"/>
    

    确保您用于在索引中存储编码值的字段使用binary fieldType 并且您使用的是base64 编码字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-09
      • 2019-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多