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