Package org.apache.solr.common

Examples of org.apache.solr.common.SolrDocumentList


    }

    masterClient.commit();

    NamedList masterQueryRsp = query("*:*", masterClient);
    SolrDocumentList masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
    assertEquals(nDocs, masterQueryResult.getNumFound());

    // Make sure that both the index version and index generation on the slave is
    // higher than that of the master, just to make the test harder.
    Thread.sleep(100);
    index(slaveClient, "id", 551, "name", "name = " + 551);
    slaveClient.commit(true, true);
    index(slaveClient, "id", 552, "name", "name = " + 552);
    slaveClient.commit(true, true);
    index(slaveClient, "id", 553, "name", "name = " + 553);
    slaveClient.commit(true, true);
    index(slaveClient, "id", 554, "name", "name = " + 554);
    slaveClient.commit(true, true);
    index(slaveClient, "id", 555, "name", "name = " + 555);
    slaveClient.commit(true, true);

    //this doc is added to slave so it should show an item w/ that result
    NamedList slaveQueryRsp = query("id:555", slaveClient);
    SolrDocumentList slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
    assertEquals(1, slaveQueryResult.getNumFound());

    masterUrl = "http://localhost:" + masterJetty.getLocalPort() + "/solr/replication?command=enableReplication";
    url = new URL(masterUrl);
    stream = url.openStream();
    try {
      stream.close();
    } catch (IOException e) {
      //e.printStackTrace();
    }

    //sleep for pollinterval time 3s, to let slave pull data.
    Thread.sleep(3000);
    //the slave should have done a full copy of the index so the doc with id:555 should not be there in the slave now
    slaveQueryRsp = query("id:555", slaveClient);
    slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
    assertEquals(0, slaveQueryResult.getNumFound());
  }
View Full Code Here


    }
    return doc;
  }

  public SolrDocumentList readSolrDocumentList(FastInputStream dis) throws IOException {
    SolrDocumentList solrDocs = new SolrDocumentList();
    List list = (List) readVal(dis);
    solrDocs.setNumFound((Long) list.get(0));
    solrDocs.setStart((Long) list.get(1));
    solrDocs.setMaxScore((Float) list.get(2));

    List l = (List) readVal(dis);
    solrDocs.addAll(l);
    return solrDocs;
  }
View Full Code Here

    CommonsHttpSolrServer solrServer = new CommonsHttpSolrServer(url);
    solrServer.request(req);
    ModifiableSolrParams qparams = new ModifiableSolrParams();
    qparams.add("q", "*:*");
    QueryResponse qres = solrServer.query(qparams);
    SolrDocumentList results = qres.getResults();
    assertEquals(2, results.getNumFound());
    SolrDocument doc = results.get(0);
    assertEquals("1", doc.getFieldValue("id"));
    assertEquals("Hello C1", doc.getFieldValue("desc"));
  }
View Full Code Here

      index(masterClient, "id", i, "name", "name = " + i);

    masterClient.commit();

    NamedList masterQueryRsp = query("*:*", masterClient);
    SolrDocumentList masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
    assertEquals(500, masterQueryResult.getNumFound());

    //sleep for pollinterval time 3s, to let slave pull data.
    Thread.sleep(3000);
    //get docs from slave and check if number is equal to master
    NamedList slaveQueryRsp = query("*:*", slaveClient);
    SolrDocumentList slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");

    if (slaveQueryResult.getNumFound() == 0) {
      //try sleeping again in case of slower comp
      Thread.sleep(5000);

      slaveQueryRsp = query("*:*", slaveClient);
      slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
    }

    assertEquals(500, slaveQueryResult.getNumFound());

    //compare results
    String cmp = TestDistributedSearch.compare(masterQueryResult, slaveQueryResult, 0, null);
    assertEquals(null, cmp);

View Full Code Here

    DocList docs = qr.getDocList();
    Set<String> fields = new HashSet<String>();
    fields.add("val_t");


    SolrDocumentList list = SolrPluginUtils.docListToSolrDocumentList(docs, srchr, fields, null);
    assertTrue("list Size: " + list.size() + " is not: " + docs.size(), list.size() == docs.size());
    for (SolrDocument document : list) {
      assertNotNull(document.get("val_t"));
    }

  }
View Full Code Here

    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 );
View Full Code Here

      // 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.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 );
View Full Code Here

    server.add(doc);

    server.commit();

    QueryResponse resp = server.query(new SolrQuery("*:*"));
    SolrDocumentList res = resp.getResults();
    List<Bean> beans = resp.getBeans(Bean.class);
    assertEquals(3, res.size());
    assertEquals(3, beans.size());
    for (SolrDocument d : res) {
      Integer id = (Integer) d.getFieldValue("id");
      byte[] data = (byte[]) d.getFieldValue("data");
      if (id == 1) {
View Full Code Here

  protected void verifyUpdatePass(String solrUserName,
                                  String collectionName,
                                  SolrInputDocument solrInputDoc) throws Exception {
    String originalUser = getAuthenticatedUser();
    try {
      SolrDocumentList orginalSolrDocs = getSolrDocs(collectionName, ALL_DOCS, true);
      setAuthenticationUser(solrUserName);
      CloudSolrServer cloudSolrServer = getCloudSolrServer(collectionName);
      try {
        cloudSolrServer.add(solrInputDoc);
        cloudSolrServer.commit();
      } finally {
        cloudSolrServer.shutdown();
      }

      orginalSolrDocs.add(ClientUtils.toSolrDocument(solrInputDoc));
      SolrDocumentList solrRespDocs = getSolrDocs(collectionName, ALL_DOCS, true);
      // Validate Solr content to check whether the update command went through.
      validateSolrDocCountAndContent(orginalSolrDocs, solrRespDocs);
    }
    finally {
      setAuthenticationUser(originalUser);
View Full Code Here

TOP

Related Classes of org.apache.solr.common.SolrDocumentList

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.