对于字段类型text_general,getbeans()方法将该字段值作为ArrayList()返回,但是pojo中的字段是String(使用索引相同的pojo时)。还有multiValued属性为false。
管理型模式:
<field name="description" type="text_general" indexed="true" stored="true"/>
pojo-field:
@Field("description")
private String description;
//getter-setter method
Java的代码:
SolrClient client = new HttpSolrClient.Builder("http://localhost:8983/solr/audiovideo").build();
Scanner sc = new Scanner(System.in);
System.out.println("Enter Serach : ");
String search = sc.nextLine();
SolrQuery query = new SolrQuery();
query.setQuery("description:" + search);
query.setStart(0);
QueryResponse response = client.query(query);
List<AudioVideoPojo> results = response.getBeans(AudioVideoPojo.class);
例外:
Exception in thread "main" org.apache.solr.client.solrj.beans.BindingException: Could not instantiate object of class com.mycompany.solrdemo1.AudioVideoPojo
at org.apache.solr.client.solrj.beans.DocumentObjectBinder.getBean(DocumentObjectBinder.java:71)
at org.apache.solr.client.solrj.beans.DocumentObjectBinder.getBeans(DocumentObjectBinder.java:50)
at org.apache.solr.client.solrj.response.QueryResponse.getBeans(QueryResponse.java:618)
at com.mycompany.solrdemo1.Main.getDataSolrFromDatabase(Main.java:155)
at com.mycompany.solrdemo1.Main.main(Main.java:131)
Caused by: org.apache.solr.client.solrj.beans.BindingException: Exception while setting value : [India International Music Festival] on private java.lang.String com.mycompany.solrdemo1.AudioVideoPojo.description
at org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.set(DocumentObjectBinder.java:455)
at org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.inject(DocumentObjectBinder.java:438)
at org.apache.solr.client.solrj.beans.DocumentObjectBinder.getBean(DocumentObjectBinder.java:67)
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field com.mycompany.solrdemo1.AudioVideoPojo.description to java.util.ArrayList
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:764)
at org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.set(DocumentObjectBinder.java:449)
答案 0 :(得分:0)
将cache
属性设置为multiValued
。根据参考指南,false
默认为false
。但它没有兑现默认值。