Solrj和动态字段 [英] Solrj and Dynamic Fields

查看:63
本文介绍了Solrj和动态字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Solr架构,其中包含不同类型的动态字段.例如,schema.xml中有:

I'm have a solr schema with dynamic field of different types in. Eg in the schema.xml there are:

<dynamicField name="*_s" type="string" indexed="true"  stored="true"/>
<dynamicField name="*_i" type="int"    indexed="true"  stored="true"/>
<dynamicField name="*_l" type="long"   indexed="true"  stored="true"/>
<dynamicField name="*_f" type="float"  indexed="true"  stored="true"/>
<dynamicField name="*_d" type="double" indexed="true"  stored="true"/>

我想使用SolrJ注释的POJO访问这些字段.我知道我可以像这样在POJO中为每种数据类型使用不同的Map引用:

And I want to access these field using a SolrJ annotated POJO. I know I can have different Map references for each data type in the POJO like this:

...
@Field("*_s")
public Map<String, String> strings;

@Field("*_i")
public Map<String, Integer> integers;
...

但是是否可以将所有动态字段存储在同一张地图中?我在想类似的东西:

But is it possible to have all dynamic fields stored in the same map? I was thinking something like:

...
@Field("*_s")
@Field("*_i")
public Map<String, Object> dynamicFields;
...

我可以找到的有关SolrJ,POJO和动态字段的唯一文档是一个旧的功能请求: https://issues.apache.org/jira/browse/SOLR-1129

The only documentation I can find about SolrJ, POJOs and dynamic fields is an old feature request: https://issues.apache.org/jira/browse/SOLR-1129

推荐答案

我计算出@Field批注中'pattern'值的匹配不必与schema.xml中的匹配.因此,我在doc类中定义了一个地图:

I worked out the matching of the 'pattern' value in the @Field annotation doesn't have to match what's in your schema.xml. So, I defined a map in my doc class:

@Field("*DF")
private Map<String, Object> dynamicFields;

,然后在schema.xml中,dynamicField具有以'DF'为后缀的模式:

and then in the schema.xml the dynamicFields have patterns postfixed by 'DF':

<dynamicField name="*_sDF" type="string" indexed="true" stored="true"/>
<dynamicField name="*_siDF" type="sint" indexed="true" stored="true"/>
<dynamicField name="*_tDF" type="date" indexed="true" stored="true"/>

现在,使用solrServer.addBean(doc)和solrResponse.getBeans(Doc.class)来存储和检索具有不同值类型的所有dynamicField.这是在Solr 3.2.0中使用的,而在1.4中不起作用.

Now all the dynamicField with different value types get stored and retrieved using solrServer.addBean(doc) and solrResponse.getBeans(Doc.class). This is with Solr 3.2.0 It wasn't working with 1.4..

这篇关于Solrj和动态字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆