java - Populating the Lucene 3.6 File Directory Index -


i integrating lucene 3.6 search api java desktop application. lucene system uses file system directory store index. code create index directory , indexwriter , adding documents index.

data index collected derby database. fields of database table added fields lucene document.so each row in database table represented single lucene document.

my question that, there way check index directory , if not populated lucene documents populate it. or skip repopulating index when population.

code creating index file.

public file createindexdir() throws ioexception, sqlexception     {            //check if directory exist        if(!userdir.exists())       { userdir.mkdir();       system.out.println(" index directory created @  " + userdir.getabsolutepath());            }         return userdir.getabsolutefile();     } 

code creating index writer

public void createindexwriter() throws ioexception, sqlexception     {      indexdir =  createindexdir();        if(iw == null)           {             try {                 // create index               standardanalyzer analyzer = new standardanalyzer(version.lucene_36);              indexwriterconfig iwconfig = new indexwriterconfig(version.lucene_36, analyzer);               iw = new indexwriter(fsdirectory.open(indexdir), iwconfig);              }             catch (corruptindexexception ex) {                 logger.getlogger(indexer.class.getname()).log(level.severe, null, ex);             } catch (lockobtainfailedexception ex) {                 logger.getlogger(indexer.class.getname()).log(level.severe, null, ex);             } catch (ioexception ex) {                 logger.getlogger(indexer.class.getname()).log(level.severe, null, ex);             }           }         } 

this code populated index file data database

     public void buildindex () throws sqlexception, corruptindexexception, ioexception      {          /* connecting database */     connection  con = drivermanager.getconnection(host, uname, upass);     statement stmt = con.createstatement(resultset.type_scroll_sensitive, resultset.concur_updatable);     string sql = "select * app.registry";     resultset rs = stmt.executequery(sql);        rs.beforefirst();  //set poinyrt begining of result set      while(rs.next())      {      document doc = new document();       doc.add(new field("id",rs.getstring("id"),field.store.yes,field.index.no));       if(rs.getstring("subject")== null)      { doc.add(new field("subject","",field.store.yes,field.index.analyzed)); }      else {      doc.add(new field("subject",rs.getstring("subject"),field.store.yes,field.index.analyzed));      }       if(rs.getstring("letter_from")== null)      { doc.add(new field("letter_from"," ",field.store.yes,field.index.analyzed)); }      else {      doc.add(new field("letter_from",rs.getstring("letter_from"),field.store.yes,field.index.analyzed));      }      doc.add(new field("date_of_letter",datetools.datetostring(rs.getdate("date_of_letter"),             datetools.resolution.day),field.store.yes,field.index.analyzed));         doc.add(new field("date_received",datetools.datetostring(rs.getdate("date_received"),             datetools.resolution.day),field.store.yes,field.index.no));                    if(rs.getstring("remarks")== null)      { doc.add(new field("remarks"," ",field.store.yes,field.index.analyzed)); }      else {      doc.add(new field("remarks",rs.getstring("remarks"),field.store.yes,field.index.analyzed));  }        if(rs.getdate("date_dispatched")== null)      { doc.add(new field("date_dispatched",datetools.datetostring(new date(0l),datetools.resolution.day),field.store.yes,field.index.analyzed)); }      else {     doc.add(new field("date_dispatched",datetools.datetostring(rs.getdate("date_dispatched"),             datetools.resolution.minute),field.store.yes,field.index.analyzed));                 }            if(rs.getstring("office_dispatched_to")== null)      { doc.add(new field("office_dispatched_to"," ",field.store.yes,field.index.analyzed));}      else {      doc.add(new field("office_dispatched_to",rs.getstring("office_dispatched_to"),field.store.yes,field.index.analyzed));         }      iw.adddocument(doc);      }       iw.commit();         closeindexwriter();    stmt.close();    rs.close();    con.close();      } 

any idea solution. cheers all.

you query index data know on derby db, either sample entries or total number of records. if that's there don't need repopulate index.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -