2013-02-14 56 views
0

我使用DIH导入数据,并需要解析一个字符串,捕获两个数字,然后填充type = location(它接受一个“纬度,长“坐标对)。合乎逻辑的事情是:Solr DIH regexTransformer似乎只知道一个捕获括号组

<field column="latLong" 
     regex="Latitude is ([-\d.]+)\s+ Longitude is ([-\d.]+)\s+" 
     replaceWith="$1,$2" /> 

看来DIH只知道一个捕获组。所以2美元永远不会被使用。

有没有人曾用regexTransformer使用多个捕获?搜索文档没有提供任何2美元或3美元的例子。索尔的祭司啊,你们给了什么?

+0

注意:Solr ver。 4.1。 – 2013-02-14 11:45:26

回答

0

这是不正确的,Solr的谛不明白$2$3等,

我只是尝试这样做。在DIH数据-config.xml中加入这样的:

<entity name="foo" 
     transformer="RegexTransformer" 
     query="SELECT list_id FROM lists WHERE list_id = ${Lists.id}"> 
    <field column="firstLastNum" 
      regex="^(\d).*?(\d)$" 
      replaceWith="$1:$2" 
      sourceColName="list_id"/> 
</entity> 

,然后加入领域在我schema.xml中

<field name="firstLastNum" type="string" indexed="true" stored="true"/> 

当我索引与LIST_ID = 390的文件,firstLastNum物3:0其中确实是正确的。

我怀疑这个问题可能是由于一个不正确的正则表达式只匹配第一部分而不是第二部分。也许尝试此正则表达式:

regex="Latitude is ([-\d.]+)\s*Longitude is ([-\d.]+)" 

另一个原因可能是,经纬度是location型和$1,$2是字符串类型的,但我不知道这一点。

+0

谢谢阿伦。澄清上面的问题。 – 2013-02-26 17:44:34

+0

您是否尝试过替代正则表达式,或者您的正则表达式正常工作? – arun 2013-02-26 19:26:49