Solr TextField到Java@Field的映射

Solr TextField到Java@Field的映射,solr,solrj,Solr,Solrj,我正在使用Solr5.2.1(DevPC上的简单独立实例)并在Spring应用程序中运行Solrj 我一切正常(Solrj客户端能够提交和检索已用@Field注解的域模型),但是我想在域模型的一个字段上使用自由文本搜索,所以我将其类型从字符串更改为文本字段,我的理解是,这将允许更自由的文本方式来搜索,而不是键:值对类型的搜索,其中solr返回全部或不返回任何内容 schema.xml代码段 <field name="description" type="text_general" inde

我正在使用Solr5.2.1(DevPC上的简单独立实例)并在Spring应用程序中运行Solrj

我一切正常(Solrj客户端能够提交和检索已用@Field注解的域模型),但是我想在域模型的一个字段上使用自由文本搜索,所以我将其类型从字符串更改为文本字段,我的理解是,这将允许更自由的文本方式来搜索,而不是键:值对类型的搜索,其中solr返回全部或不返回任何内容

schema.xml代码段

<field name="description" type="text_general" indexed="true" stored="true"/>
public String getDescription() {
   return description;
}

@Field
public void setDescription(String description) {
    this.description = description;
}
Save端工作得很好,我能够更新solr vai-javabean-ans-solrj,并且使用http客户机我可以看到数据进入,问题是我在查询时似乎无法将javabean取回来。Solr在尝试填充bean时不喜欢基于字符串的setter。我得到以下错误:

Caused by: org.apache.solr.client.solrj.beans.BindingException: Exception while setting value : [PetShop] on public void search.CompanySummarySolr.setDescription(java.lang.String)

INFO  [stdout] (http-localhost-127.0.0.1-8080-6)    at org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.set(DocumentObjectBinder.java:447)

INFO  [stdout] (http-localhost-127.0.0.1-8080-6)    at org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.inject(DocumentObjectBinder.java:430)

INFO  [stdout] (http-localhost-127.0.0.1-8080-6)    at org.apache.solr.client.solrj.beans.DocumentObjectBinder.getBean(DocumentObjectBinder.java:64)

INFO  [stdout] (http-localhost-127.0.0.1-8080-6)    ... 64 more

INFO  [stdout] (http-localhost-127.0.0.1-8080-6) Caused by: java.lang.IllegalArgumentException: argument type mismatch
我理解这个错误,只是不知道如何映射文本字段。在http客户端Json输出中,它看起来像一个数组,但在SolrAPI中,它扩展了对象而不是数组

我所能看到的就是我需要一个

@Field
public void setDescription(Object description) {
    this.description = (???) description;
}
在这种情况下,如何将其恢复为字符串

或者我可以使用org.apache.solr.schema.TextField

@Field
public void setDescription(TextField description) {
    this.description =  description.getValueSource(???, ???);
}
但我也不太明白如何让字符串返回给初学者,其次,看起来我必须将整个solr库引入到项目中,因为TextField对象不在Solrj库中

我确信我错过了一些东西,所有其他字段映射得如此简单,但我找不到一个示例,说明如何将描述作为字符串返回给客户端,并允许在此字段上进行自由文本搜索,因为据我所知,字符串不允许这种类型的搜索


任何帮助都会非常感激,所以它看起来是一个多值字段。这意味着Solr用数组包装我传入的字符串字段,这会导致Bean Setter中断,因为Solr希望返回一个包含1个字符串而不是字符串的数组

要解决这个问题,只需编辑Schema.xml文件并显式地告诉Solr text_general是一个值,因此在我的例子中,description字段就消失了

来自此:

<field name="description" type="text_general" indexed="true" stored="true"/> 
<field name="description" type="text_general" indexed="true" stored="true" multiValued="false"/>

对此:

<field name="description" type="text_general" indexed="true" stored="true"/> 
<field name="description" type="text_general" indexed="true" stored="true" multiValued="false"/>

现在Solr很高兴地将我的响应转换为它的组件JavaBean