package voyager.quads.demo;

import java.io.File;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.StreamingUpdateSolrServer;
import org.apache.solr.common.SolrInputDocument;

import voyager.quads.utils.geonames.Geoname;
import voyager.quads.utils.geonames.GeonamesReader;

public class SampleDataLoader
{
  public static void main( String[] args ) throws Exception
  {
    File file = null;
    SolrServer solr = new StreamingUpdateSolrServer( "http://localhost:8080/solr", 50, 3 );
    //SolrServer solr = new CommonsHttpSolrServer( "http://localhost:8080/solr" );

//    file = new File( "../data/ikonos_2011/ikonos_2011.shp" );
//    if( file.exists() ) {
//      GeoeyeReader.indexItems( solr, file );
//      solr.commit( true, true );
//    }
//
//    file = new File( "../data/countries/cntry06.shp" );
//    if( file.exists() ) {
//      CountryReader.indexCountries( solr, file );
//      solr.commit( true, true );
//    }

    // Geonames
    file = new File( "../data/geonames/US.txt" );
    if( file.exists() ) {
      GeonamesReader reader = new GeonamesReader( file );
      while( reader.hasNext() ) {
        Geoname name = reader.next();
        SolrInputDocument doc = new SolrInputDocument();
        doc.setField( "id", name.id+"" );
        doc.setField( "name", name.name+"" );
        doc.setField( "geo", name.longitude + " " + name.latitude );
        solr.add( doc );

        if( (reader.getCount() % 1000) == 0 ) {
          System.out.println( "geonames: "+reader.getCount() + " :: " + name.name );
        }
      }
      solr.commit( true, true );
    }

    System.out.println( "done." );
  }
}

@@ -210,16 +210,116 @@
 ument;%0A%0A
+import voyager.quads.utils.countries.CountryReader;%0Aimport voyager.quads.utils.geoeye.GeoeyeReader;%0A
 import v
@@ -355,16 +355,16 @@
 eoname;%0A
-
 import v
@@ -702,18 +702,16 @@
 lr%22 );%0A%0A
-//
     file
@@ -756,34 +756,32 @@
 os_2011.shp%22 );%0A
-//
     if( file.exi
@@ -786,26 +786,24 @@
 xists() ) %7B%0A
-//
       Geoeye
@@ -827,34 +827,32 @@
 ( solr, file );%0A
-//
       solr.commi
@@ -872,21 +872,15 @@
  );%0A
-//
     %7D%0A
-//%0A//
+%0A
     
@@ -927,26 +927,24 @@
 y06.shp%22 );%0A
-//
     if( file
@@ -957,18 +957,16 @@
 s() ) %7B%0A
-//
       Co
@@ -1003,26 +1003,24 @@
 lr, file );%0A
-//
       solr.c
@@ -1040,18 +1040,16 @@
 true );%0A
-//
     %7D%0A%0A 

load data