Example usage for org.apache.solr.client.solrj.beans DocumentObjectBinder toSolrInputDocument

List of usage examples for org.apache.solr.client.solrj.beans DocumentObjectBinder toSolrInputDocument

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.beans DocumentObjectBinder toSolrInputDocument.

Prototype

public SolrInputDocument toSolrInputDocument(Object obj) 

Source Link

Usage

From source file:alba.solr.searchcomponents.AlbaRequestHandler.java

License:Apache License

public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    // TODO Auto-generated method stub

    /* List<SearchComponent> components = new ArrayList<SearchComponent>();
            /*from www.java 2 s  . c o  m*/
    MySearchComponent msc = new MySearchComponent();
            
    ResponseBuilder rb = new ResponseBuilder(req, rsp, components);
            
    msc.process(rb);*/

    //rsp.add("hello", rb.rsp.getValues());

    req.getContext().put(Loader.FUNCTIONS, functions);

    Object params[] = new Object[2];

    params[0] = req;
    params[1] = rsp;

    // what if this method calls rsp.add( .. ) ????
    Object result = this.function.getMethod().invoke(this.function.getInstance(), params);

    if (Map.class.isAssignableFrom(result.getClass())) {
        // if we got a Map, just return it as-is
        rsp.add(this.sectionName, result);
    } else // if we got anything else, try to serialize it!
    if (List.class.isAssignableFrom(result.getClass())) {
        for (Object o : (List) result) {
            DocumentObjectBinder dob = new DocumentObjectBinder();
            SolrInputDocument sd = dob.toSolrInputDocument(o);
            SolrDocument dest = ClientUtils.toSolrDocument(sd);

            HashMap<Object, Object> nl = (HashMap<Object, Object>) dest.get("functionDescriptor");

            //rsp.add(nl.get("name").toString(), dest2);

            rsp.add(null, dest);
        }
    }
    if (StaticResource.class.isAssignableFrom(result.getClass())) {
        FilteredShowFileRequestHandler file = new FilteredShowFileRequestHandler();

        file.init(new NamedList()); //to initialize internal variables - but in this way it will NOT get the proper configuration from SolrConfig!

        ModifiableSolrParams solrParams = new ModifiableSolrParams(req.getParams());

        StaticResource resource = ((StaticResource) result);
        solrParams.set("file", resource.getName());
        //TODO Proper mapping here!!
        //solrParams.set("contentType", "text/xml;charset=utf-8");

        solrParams.set("contentType", resource.getContentType());
        req.setParams(solrParams);

        file.handleRequest(req, rsp);
        //   logger.error("returning the content of " + );
    } else {
        // unable to do any kind of serialization.. just add the result and let the ResponseWriter handle it
        rsp.add(null, result);
    }

}

From source file:edu.unc.lib.dl.data.ingest.solr.test.AtomicUpdateTest.java

License:Apache License

@Test
public void atomicUpdate() throws IOException {
    IndexDocumentBean idb = new IndexDocumentBean();
    idb.setId("id");
    idb.setStatus(Arrays.asList("Unpublished", "Parent Unpublished"));

    DocumentObjectBinder binder = new DocumentObjectBinder();
    SolrInputDocument sid = binder.toSolrInputDocument(idb);

    String operation = "set";

    for (String fieldName : sid.getFieldNames()) {
        if (!ID_FIELD.equals(fieldName)) {
            SolrInputField inputField = sid.getField(fieldName);
            // Adding in each non-null field value, except the timestamp field which gets cleared if not specified so
            // that it always gets updated as part of a partial update
            // TODO enable timestamp updating when fix for SOLR-4133 is released, which enables setting null fields
            if (inputField != null && (inputField.getValue() != null || UPDATE_TIMESTAMP.equals(fieldName))) {
                Map<String, Object> partialUpdate = new HashMap<String, Object>();
                partialUpdate.put(operation, inputField.getValue());
                sid.setField(fieldName, partialUpdate);
            }//  www. ja  v  a2 s .co  m
        }
    }

    /*   Map<String,String> mapField = new HashMap<String,String>();
       mapField.put("", arg1)
       Map<String, Object> partialUpdate = new HashMap<String, Object>();
       partialUpdate.put("set", inputField.getFirstValue());
       sid.setField(fieldName, partialUpdate);*/

    StringWriter writer = new StringWriter();
    ClientUtils.writeXML(sid, writer);

    System.out.println(writer.toString());

    System.out.println(sid.toString());
}