lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Otis Gospodnetic <otis_gospodne...@yahoo.com>
Subject RE: IndexSearcher hanging on to old index files in Windows
Date Fri, 29 Apr 2005 02:21:59 GMT
Just tried this on my linux laptop - with IndexSearcher uncommented, I
still get a single .cfs file.  It's one of those problems where Windows
doesn't let you erase the file.  I'd start this SortTest in the
debugger and step through it until you find a spot where you see that
some index file deletion fails.
Do you get 2 .cfs files even if you add isearcher.close() right after
you open the IndexSearcher?

Otis

--- Monsur Hossain <monsur@monsur.com> wrote:
> Ok, I've written up a Java test with Lucene 1.4.3, the code is pasted
> below.
> The code creates a new index, creates an IndexSearcher object, and
> then does
> an incremental index/optimize.  The IndexSearcher line is commented
> out.
> When I run this code, I end up with a single "segments", "deletable"
> and
> ".cfs" file in my Index directory.
> 
> Now, when I uncomment the IndexSearcher line and run the application
> again,
> I end up with two .cfs files.  Notice how all I have to do is create
> an
> IndexSearcher; I don't even have to run a query.  
> 
> Am I doing this correctly?
> 
> Thanks,
> Monsur
> 
> 
> import org.apache.lucene.search.IndexSearcher;
> import org.apache.lucene.index.IndexWriter;
> import org.apache.lucene.analysis.SimpleAnalyzer;
> import org.apache.lucene.document.Document;
> import org.apache.lucene.document.Field;
> 
> 
> public class SearchTest {
>     
>     static String indexDir = "C:\\Temp\\Index"; 
>     static int numDocsAdd = 1000;
>     static int mergeFactor = 2;
>     static int docId = 0;
> 
>     public static void main(String[] args) throws Exception {
>         System.out.println("Running full index");
>         initialIndex();
> //        IndexSearcher isearcher = new IndexSearcher(indexDir);
>         System.out.println("Running incremental index");
>         incrementalIndex();
>     }
>     
>     static void initialIndex() throws Exception {
>         // create a new index with 1000 documents
>         IndexWriter writerMain = new IndexWriter(indexDir, new
> SimpleAnalyzer(), true);
>         writerMain.mergeFactor = mergeFactor;
>         for (docId = 0; docId < numDocsAdd; docId++)
>         {
>             Document doc = new Document();
>             doc.add(Field.Text("Content", "This is for document
> number " +
> docId));
>             doc.add(Field.Keyword("DocID", Integer.toString(docId)));
>             writerMain.addDocument(doc);
>         }
>         writerMain.optimize();
>         writerMain.close();
>     }
>     
>     static void incrementalIndex() throws Exception {
>         // add 1000 new documents to the index
>         IndexWriter writerMain = new IndexWriter(indexDir, new
> SimpleAnalyzer(), false);
>         writerMain.mergeFactor = mergeFactor;
>         int docMax = docId + numDocsAdd;
>         for (; docId < docMax; docId++)
>         {
>             Document doc = new Document();
>             doc.add(Field.Text("Content", "This is for document
> number " +
> docId));
>             doc.add(Field.Keyword("DocID", Integer.toString(docId)));
>             writerMain.addDocument(doc);
>         }
>         writerMain.optimize();
>         writerMain.close();
>     }
> }
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message