我发现了一个来自Cloudera搜索的令人惊叹的小部件,叫做Map。我想使用它来显示国家的记录计数,但它只适用于iso alpha-3国家代码。我的记录中只有iso alpha-2国家代码值(请参阅此处的差异http://www.nationsonline.org/oneworld/country_code_list.htm)。
我想知道如何获得iso alpha-3国家代码?我想提一下,我的原始数据是csv格式的,我有一个名为Country的字段,其中包含完整的国家名称,另一个名为Country_Code的字段存储iso apha-2国家代码。
我尝试修改SOLR schema.xml和Morphline文件,但没有得到积极的结果。任何想法都是值得高度赞赏的。
谢谢!
发布于 2014-11-06 04:34:10
实际上,我也面临着同样的问题。我设法通过创建一个自定义的Morphline命令来解决这个问题,如下所示。
构建自定义Morphline命令。
在Morphline中,您可以很容易地构建自己的命令。(参见Implementing your own Custom Command)。以下是您可以在命令构建器中使用的代码示例:
// Nested class:
private static final class ConvertCountryCode extends AbstractCommand {
private final String fieldName;
public ConvertCountryCode(Command Builder builder, Config config, Command parent, Command child, MorphlineContext context) {
super(builder, config, parent, child, context);
this.fileName = getConfigs().getString(config, "field");
}
@Override
@SuppressWarning("unchecked")
protected boolean doProcess(Record record) {
ListIterator iter = record.get(fieldName).listIterator();
while(iter.hasNext()) {
Locale locale = new Locale ("", iter.next().toString());
String result = locale.getISO3Country();
iter.set(result);
}
return super.doProcess(record);
}
}拥有命令生成器后,可以编辑Morphlines conf文件以添加命令,如下所示:
commands: [{
convertCountryCode {
field: Country_Code
}
}使用此命令时,当您将所有ISO Alpha-2代码添加到索引时,会将它们替换为ISO Alpha-3。我已经测试了这个解决方案,它是有效的!确保将包添加到Morphline的命令导入列表中。
使用Java命令
或者,如果您不想构建自定义命令,则可以使用Java command。
https://stackoverflow.com/questions/26364032
复制相似问题