lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yogesh Dabhi" <yda...@asite.com>
Subject Slow ness of IndexWriter.close()
Date Mon, 13 Jun 2011 11:14:43 GMT
 

Hi,

I try to add and update  document in index 

At the start its take only 1 to 2 second but after 50 to 60 document add
and update 

Its take 40 to 50 second or some time its take more then 1 min 

 

Is there any  way to improve performance ?

 

Please help me 

 

Please check my code 

 

if(documents!=null && documents.size()>0){

      IndexWriter writer = null;

      boolean createNewIndexDirectory =
!IndexReader.indexExists(FSDirectory.open(indexDir));

      int createNewIndexReTries = 0;

      Directory directory = FSDirectory.open(indexDir, null);

      while(writer==null) {

            try{

                  directory.setLockFactory(new
NativeFSLockFactory(indexDir));

 

                  if(analyzer == null){


                        analyzer = new
StandardAnalyzer(IAsiteIndexConstants.LUCENE_VERSION,AsiteIndexUtil.getS
topWordSet());

                  }

                  writer = new IndexWriter(directory, analyzer,
createNewIndexDirectory,IndexWriter.MaxFieldLength.UNLIMITED);

                  for(Document document : documents){

 
if(document.get(ICustomFormIndexConstants.INDEX_FIELD_FORM_ID)!=null){

                              formId =
Integer.parseInt(document.get(ICustomFormIndexConstants.INDEX_FIELD_FORM
_ID));

                        }

                        String strValue =
NumericUtils.longToPrefixCoded(Long.parseLong(document.get(ICustomFormIn
dexConstants.INDEX_FIELD_MSG_ID)));

                        term = new
Term(ICustomFormIndexConstants.INDEX_FIELD_MSG_ID,strValue);

                        writer.updateDocument(term, document);

                  }

            }catch (LockObtainFailedException ex){

                  CheckIndex.Status status = new
CheckIndex(directory).checkIndex();

                  if(status!=null && status.numBadSegments>0){

                        log.error("Index found corrupted.
status.numBadSegments ::"+status.numBadSegments);

                        ex.printStackTrace();

                        throw ex;

                  }                              

            }finally{

                  try{

                        if(writer!=null){

                              writer.close();

                        }

 

                  }catch(IOException ex){

                  }

            }

 

      }

 


Thanks & Regards 

Yogesh


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message