lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Oliver" <KOli...@salesforce.com>
Subject RE: IndexWriter.addIndexes(Directory[] dirs)
Date Mon, 12 Dec 2005 22:58:10 GMT
I see it stripped my attachment off. Here's the code:

 

 

import junit.framework.TestCase;

 

import org.apache.lucene.analysis.standard.StandardAnalyzer;

import org.apache.lucene.document.Document;

import org.apache.lucene.document.Field;

import org.apache.lucene.index.IndexWriter;

import org.apache.lucene.index.Term;

import org.apache.lucene.search.*;

import org.apache.lucene.store.Directory;

import org.apache.lucene.store.FSDirectory;

 

public class AddIndexesTest extends TestCase {

 

    public AddIndexesTest(String name) {

        super(name);

    }

 

    public void testAddIndexes() throws Exception {

        {

            Directory dir1 =
FSDirectory.getDirectory("/dev/searchdata/addIndexesTest1", true);

            IndexWriter writer1 = new IndexWriter(dir1, new
StandardAnalyzer(), true);

            

            Document doc1 = new Document();

            doc1.add(Field.UnIndexed("ID", "id1"));

            doc1.add(Field.UnStored("f", "some words"));

            writer1.addDocument(doc1);

            

            writer1.close();

            dir1.close();

            

            IndexSearcher searcher = new
IndexSearcher("/dev/searchdata/addIndexesTest1");

            Hits hits = searcher.search(new TermQuery(new Term("f",
"words")));

            assertEquals(1, hits.length());

            searcher.close();

        }

        

        {

            Directory dir2 =
FSDirectory.getDirectory("/dev/searchdata/addIndexesTest2", true);

            IndexWriter writer2 = new IndexWriter(dir2, new
StandardAnalyzer(), true);

            

            Document doc1 = new Document();

            doc1.add(Field.UnIndexed("ID", "id2"));

            doc1.add(Field.UnStored("f", "some other words"));

            writer2.addDocument(doc1);

            

            writer2.close();

            dir2.close();

 

            IndexSearcher searcher = new
IndexSearcher("/dev/searchdata/addIndexesTest2");

            Hits hits = searcher.search(new TermQuery(new Term("f",
"words")));

            assertEquals(1, hits.length());

            searcher.close();

        }        

        

        Directory dir =
FSDirectory.getDirectory("/dev/searchdata/addIndexesTest1", false);

        IndexWriter writer = new IndexWriter(dir, new
StandardAnalyzer(), false);

        writer.addIndexes(new Directory[] {
FSDirectory.getDirectory("/dev/searchdata/addIndexesTest2", false) });

        writer.close();

        dir.close();

        

        IndexSearcher searcher = new
IndexSearcher("/dev/searchdata/addIndexesTest1");

        Hits hits = searcher.search(new TermQuery(new Term("f",
"words")));

        assertEquals(2, hits.length());

        searcher.close();

    }

    

}

 

 

-----Original Message-----
From: Kevin Oliver 
Sent: Monday, December 12, 2005 2:53 PM
To: java-dev@lucene.apache.org
Subject: RE: IndexWriter.addIndexes(Directory[] dirs)

 

Volodymyr, I tried this patch out, and unfortunately it doesn't appear

to work for me. Is there something I missed?

 

I'll try attaching my Junit test case that works when the code is

unpatched, but fails on the final assertion expecting 2 hits (on line

63) when I used the patched IndexWriter.java. 

 

Thanks, 

Kevin

 

 

-----Original Message-----

From: Volodymyr Bychkoviak [mailto:vbychkoviak@i-hypergrid.com] 

Sent: Monday, December 12, 2005 5:51 AM

To: java-dev@lucene.apache.org

Subject: IndexWriter.addIndexes(Directory[] dirs)

 

IndexWriter in addIndexes(Directory[] dirs) method optimizes index 

before and after operation.

 

Some notes about this:

1). Adding sub indexes to large index can take long because of double 

optimization.

2). This breaks IndexWriter.maxMergeDocs logic, because optimize will 

merge data into single segment index.

 

I suggest add new method with boolean parameter to optionally specify 

whether index should be optimized.

 

There is similar method addIndexes(IndexReader[] readers) in IndexWriter

 

that takes array of IndexReaders but I don't know how it can be modified

 

to provide same optional functionality

 

Patch attached here to discuss it first

(should I post it directly to jira?)

 

 

-- 

regards,

Volodymyr Bychkoviak

 

 

 

 

 


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