Package org.apache.solr.client.solrj.beans

Examples of org.apache.solr.client.solrj.beans.DocumentObjectBinder


   * @throws SolrServerException
   * @throws IOException
   * @since solr 3.5
   */
  public UpdateResponse addBeans(Collection<?> beans, int commitWithinMs) throws SolrServerException, IOException {
    DocumentObjectBinder binder = this.getBinder();
    ArrayList<SolrInputDocument> docs =  new ArrayList<SolrInputDocument>(beans.size());
    for (Object bean : beans) {
      docs.add(binder.toSolrInputDocument(bean));
    }
    return add(docs, commitWithinMs);
  }
View Full Code Here


   */
  public abstract NamedList<Object> request( final SolrRequest request ) throws SolrServerException, IOException;

  public DocumentObjectBinder getBinder() {
    if(binder == null){
      binder = new DocumentObjectBinder();
    }
    return binder;
  }
View Full Code Here

    return _limitingFacets;
  }
 
  public <T> List<T> getBeans(Class<T> type){
    return solrServer == null ?
      new DocumentObjectBinder().getBeans(type,_results):
      solrServer.getBinder().getBeans(type, _results);
  }
View Full Code Here

    return _limitingFacets;
  }
 
  public <T> List<T> getBeans(Class<T> type){
    return solrServer == null ?
      new DocumentObjectBinder().getBeans(type,_results):
      solrServer.getBinder().getBeans(type, _results);
  }
View Full Code Here

    req.add(docs);
    return req.process(this);
  }

  public UpdateResponse addBeans(Collection<?> beans ) throws SolrServerException, IOException {
    DocumentObjectBinder binder = this.getBinder();
    ArrayList<SolrInputDocument> docs =  new ArrayList<SolrInputDocument>(beans.size());
    for (Object bean : beans) {
      docs.add(binder.toSolrInputDocument(bean));
    }
    return add(docs);
  }
View Full Code Here

   */
  public abstract NamedList<Object> request( final SolrRequest request ) throws SolrServerException, IOException;

  public DocumentObjectBinder getBinder() {
    if(binder == null){
      binder = new DocumentObjectBinder();
    }
    return binder;
  }
View Full Code Here

    return _limitingFacets;
  }
 
  public <T> List<T> getBeans(Class<T> type){
    return solrServer == null ?
      new DocumentObjectBinder().getBeans(type,_results):
      solrServer.getBinder().getBeans(type, _results);
  }
View Full Code Here

import java.util.List;

public class TestDocumentObjectBinder extends TestCase
{
  public void testSimple() throws Exception {
    DocumentObjectBinder binder = new DocumentObjectBinder();
    XMLResponseParser parser = new XMLResponseParser();
    NamedList<Object> nl = null;
    nl = parser.processResponse(new StringReader(xml));
    QueryResponse res = new QueryResponse(nl, null);
    SolrDocumentList solDocList = res.getResults();
    List<Item> l = binder.getBeans(Item.class,res.getResults());
    Assert.assertEquals(solDocList.size(), l.size());
    Assert.assertEquals(solDocList.get(0).getFieldValue("features"), l.get(0).features);

    Item item = new Item();
    item.id = "aaa";
    item.categories = new String[] { "aaa", "bbb", "ccc" };
    SolrInputDocument out = binder.toSolrInputDocument( item );

    Assert.assertEquals( item.id, out.getFieldValue( "id" ) );
    SolrInputField catfield = out.getField( "cat" );
    Assert.assertEquals( 3, catfield.getValueCount() );
    Assert.assertEquals( "[aaa, bbb, ccc]", catfield.getValue().toString() );
 
    // Test the error on not settable stuff...
    NotGettableItem ng = new NotGettableItem();
    ng.setInStock( false );
    try {
      out = binder.toSolrInputDocument( ng );
      Assert.fail( "Should throw an error" );
    }
    catch( RuntimeException ex ) {
      // ok -- this should happen...
    }
View Full Code Here

    catch( RuntimeException ex ) {
      // ok -- this should happen...
    }
  }
  public void testSingleVal4Array(){
    DocumentObjectBinder binder = new DocumentObjectBinder();
    SolrDocumentList solDocList = new SolrDocumentList();
    SolrDocument d = new SolrDocument();
    solDocList.add(d);
    d.setField("cat","hello");
    List<Item> l = binder.getBeans(Item.class,solDocList);
    Assert.assertEquals("hello", l.get(0).categories[0]);

  }
View Full Code Here

    item.id = "one";
    item.inStock = false;
    item.categories =  new String[] { "aaa", "bbb", "ccc" };
    item.features = Arrays.asList( item.categories );
   
    DocumentObjectBinder binder = new DocumentObjectBinder();
    SolrInputDocument doc = binder.toSolrInputDocument( item );
    SolrDocumentList docs = new SolrDocumentList();
    docs.add( ClientUtils.toSolrDocument(doc) );
    Item out = binder.getBeans( Item.class, docs ).get( 0 );

    // make sure it came out the same
    Assert.assertEquals( item.id, out.id );
    Assert.assertEquals( item.inStock, out.inStock );
    Assert.assertEquals( item.categories.length, out.categories.length );
View Full Code Here

TOP

Related Classes of org.apache.solr.client.solrj.beans.DocumentObjectBinder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.