Package org.apache.solr.common

Examples of org.apache.solr.common.SolrInputDocument


        server.deleteByQuery("*:*");// delete everything!
       
        List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
        for (int i = 0; i < numDocs; i++) {
          // Now add something...
          SolrInputDocument doc = new SolrInputDocument();
          doc.addField("id", "" + i);
          doc.addField("unicode_s", randomTestString(30));
          docs.add(doc);
        }
       
        server.add(docs);
        server.commit();
View Full Code Here


    server.commit();
    QueryResponse rsp = server.query( new SolrQuery( "*:*") );
    Assert.assertEquals( 0, rsp.getResults().getNumFound() );

    // Now try a timed commit...
    SolrInputDocument doc3 = new SolrInputDocument();
    doc3.addField( "id", "id3", 1.0f );
    doc3.addField( "name", "doc3", 1.0f );
    doc3.addField( "price", 10 );
    UpdateRequest up = new UpdateRequest();
    up.add( doc3 );
    up.setCommitWithin( 500 )// a smaller commitWithin caused failures on the following assert
    up.process( server );
   
View Full Code Here

  static String field = "name";

  @Test
  public void testSpellCheckResponse() throws Exception {
    getSolrServer();
    SolrInputDocument doc = new SolrInputDocument();
    doc.setField("id", "111");
    doc.setField(field, "Samsung");
    server.add(doc);
    server.commit(true, true);

    SolrQuery query = new SolrQuery("*:*");
    query.set(CommonParams.QT, "/spell");
View Full Code Here

    // Empty the database...
    server.deleteByQuery( "*:*" );// delete everything!
   
    SolrInputDocument[] doc = new SolrInputDocument[3];
    for( int i=0; i<3; i++ ) {
      doc[i] = new SolrInputDocument();
      doc[i].setField( "id", i + " & 222", 1.0f );
    }
    String id = (String) doc[0].getField( "id" ).getFirstValue();
   
    server.add( doc[0] );
View Full Code Here

  }

  @Test
  public void testSpellCheckResponse_Extended() throws Exception {
    getSolrServer();
    SolrInputDocument doc = new SolrInputDocument();
    doc.setField("id", "111");
    doc.setField(field, "Samsung");
    server.add(doc);
    server.commit(true, true);

    SolrQuery query = new SolrQuery("*:*");
    query.set(CommonParams.QT, "/spell");
View Full Code Here

    // Empty the database...
    server.deleteByQuery( "*:*" );// delete everything!
   
    SolrInputDocument[] doc = new SolrInputDocument[5];
    for( int i=0; i<doc.length; i++ ) {
      doc[i] = new SolrInputDocument();
      doc[i].setField( "id", "ID"+i, 1.0f );
      server.add( doc[i] );
    }
    server.commit();
    assertNumFound( "*:*", doc.length ); // make sure it got in
View Full Code Here

    String f = "val_pi";
   
    int i=0;               // 0   1   2   3   4   5   6   7   8   9
    int[] nums = new int[] { 23, 26, 38, 46, 55, 63, 77, 84, 92, 94 };
    for( int num : nums ) {
      SolrInputDocument doc = new SolrInputDocument();
      doc.setField( "id", "doc"+i++ );
      doc.setField( "name", "doc: "+num );
      doc.setField( f, num );
      server.add( doc );
    }
    server.commit();
    assertNumFound( "*:*", nums.length ); // make sure they all got in
   
    SolrQuery query = new SolrQuery( "*:*" );
    query.setRows( 0 );
    query.setGetFieldStatistics( f );
   
    QueryResponse rsp = server.query( query );
    FieldStatsInfo stats = rsp.getFieldStatsInfo().get( f );
    assertNotNull( stats );
   
    assertEquals( 23.0, stats.getMin().doubleValue(), 0 );
    assertEquals( 94.0, stats.getMax().doubleValue(), 0 );
    assertEquals( new Long(nums.length), stats.getCount() );
    assertEquals( new Long(0), stats.getMissing() );
    assertEquals( "26.4", stats.getStddev().toString().substring(0,4) );
   
    // now lets try again with a new set...  (odd median)
    //----------------------------------------------------
    server.deleteByQuery( "*:*" );// delete everything!
    server.commit();
    assertNumFound( "*:*", 0 ); // make sure it got in
    nums = new int[] { 5, 7, 10, 19, 20 };
    for( int num : nums ) {
      SolrInputDocument doc = new SolrInputDocument();
      doc.setField( "id", "doc"+i++ );
      doc.setField( "name", "doc: "+num );
      doc.setField( f, num );
      server.add( doc );
    }
    server.commit();
    assertNumFound( "*:*", nums.length ); // make sure they all got in
   
    rsp = server.query( query );
    stats = rsp.getFieldStatsInfo().get( f );
    assertNotNull( stats );
   
    assertEquals( 5.0, stats.getMin().doubleValue(), 0 );
    assertEquals( 20.0, stats.getMax().doubleValue(), 0 );
    assertEquals( new Long(nums.length), stats.getCount() );
    assertEquals( new Long(0), stats.getMissing() );
   
    // Now try again with faceting
    //---------------------------------
    server.deleteByQuery( "*:*" );// delete everything!
    server.commit();
    assertNumFound( "*:*", 0 ); // make sure it got in
    nums = new int[] { 1, 2, 3, 4, 5, 10, 11, 12, 13, 14 };
    for( i=0; i<nums.length; i++ ) {
      int num = nums[i];
      SolrInputDocument doc = new SolrInputDocument();
      doc.setField( "id", "doc"+i );
      doc.setField( "name", "doc: "+num );
      doc.setField( f, num );
      doc.setField( "inStock", i < 5 );
      server.add( doc );
    }
    server.commit();
    assertNumFound( "inStock:true"5 ); // make sure they all got in
    assertNumFound( "inStock:false", 5 ); // make sure they all got in
View Full Code Here

  }
 
  @Test
  public void testSpellCheckCollationResponse() throws Exception {
    getSolrServer();
    SolrInputDocument doc = new SolrInputDocument();
    doc.setField("id", "0");
    doc.setField("name", "faith hope and love");
    server.add(doc);
    doc = new SolrInputDocument();
    doc.setField("id", "1");
    doc.setField("name", "faith hope and loaves");
    server.add(doc);
    doc = new SolrInputDocument();
    doc.setField("id", "2");
    doc.setField("name", "fat hops and loaves");
    server.add(doc);
    doc = new SolrInputDocument();
    doc.setField("id", "3");
    doc.setField("name", "faith of homer");
    server.add(doc);
    doc = new SolrInputDocument();
    doc.setField("id", "4");
    doc.setField("name", "fat of homer");
    server.add(doc);   
    server.commit(true, true);
    
    //Test Backwards Compatibility
    SolrQuery query = new SolrQuery("name:(+fauth +home +loane)");
View Full Code Here

  }

  @Override
  void addDoc(int line, String[] vals) throws IOException {
    templateAdd.indexedId = null;
    SolrInputDocument doc = new SolrInputDocument();
    doAdd(line, vals, doc, templateAdd);
  }
View Full Code Here

    loader.load(req, rsp, new ContentStreamBase.StringStream(input));

    assertEquals( 2, p.addCommands.size() );
   
    AddUpdateCommand add = p.addCommands.get(0);
    SolrInputDocument d = add.solrDoc;
    SolrInputField f = d.getField( "boosted" );
    assertEquals(6.7f, f.getBoost());
    assertEquals(2, f.getValues().size());

    //
    add = p.addCommands.get(1);
    d = add.solrDoc;
    f = d.getField( "f1" );
    assertEquals(2, f.getValues().size());
    assertEquals(3.45f, d.getDocumentBoost());
    assertEquals(false, !add.allowDups);
   

    // parse the commit commands
    assertEquals( 2, p.commitCommands.size() );
View Full Code Here

TOP

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

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.