How do Solrj pojo Java types map to Solr types?

百般思念 提交于 2019-12-02 00:08:48

You can map pojo with solr types using @Field annotation of solrj

below is the example code

import org.apache.solr.client.solrj.beans.Field;

public class Person {

    @Field
    private int id;

    @Field("first_name")
    private String firstName;

    @Field("last_name")
    private String lastName;

    @Field
    private String age;

    // Getters & setters


}

your schema.xml should contain the fields id, first_name, last_name, age.

The answer to this question appears to be that for Solrj beans (using @Field) the Java type of the field is a Java OBJECT that corresponds to the solr.*Field type.

For instance solr.BoolField maps to java.lang.Boolean.

Same follows for Long, Integer, Float, ...

I hope this helps the next poor soul :-)

Solrj can stream the document as XML or Binary using the RequestWriter. The document.addField method does take an object, so it is ok to pass Java datatypes, but I have not seen a mapping. If there is one it probably assumes the basic data types. If you look at the example code it is so.

If I remember correctly (this was from a while back), we just had an issue with dates, and wrote our own formatter for it. This was from the Solr 1.2 days and that code worked fine and is still in production

http://lucene.apache.org/solr/api-4_0_0-BETA/org/apache/solr/common/SolrInputDocument.html

Here is the JavaDoc for the InputType. http://lucene.apache.org/solr/api-4_0_0-BETA/org/apache/solr/common/SolrInputField.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!