You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by 장용석 <ne...@gmail.com> on 2008/08/08 04:12:40 UTC

merge Index

hi,
I am using RamDirectory and FSDirectory for indexing documents.
I use RamDirectory as Buffer.

For example,
-----------------------------------
String indexDir = "d:/lucene_data/merge_test_index";
Analyzer analyzer  = new StopAnalyzer();

RAMDirectory ramDir    = new RAMDirectory();
IndexWriter  ramWriter = new IndexWriter(ramDir, analyzer, true);

for (int i = 0; i < 10000; i++) {
           Document doc = new Document();
           doc.add(new Field("id", "test id"+i, Field.Store.YES,
Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
            writer.addDocument(doc);
}


IndexWriter fsWriter   = new IndexWriter(indexDir, analyzer, true);
fsWriter.addIndexes(new Directory[] { ramDir });
ramWriter.close();
fsWriter.close();
------------------------------------

I know IndexWriter.addIndexes(Directory[] dir) method can merge other
indexes.

But, when I execute my program, just 2 files are created in index directory.
(segments.gen and segments_4)
And when I open with LUKE the index then meet error , It's bad index file.

What's wrong about that code..?
It's almost same as sample source code on book. I can't find any reason.

Please let me know what is wrong.

Thank you.


-- 
DEV용식
http://devyongsik.tistory.com

Re: merge Index

Posted by 장용석 <ne...@gmail.com>.
Thank you for your reply. :)
You are correct.

I did run addIndexes method after the ramWriter colse.
And It is good working and create correct index file.

Thank you very much.

Jang.


08. 8. 8, Grant Ingersoll <gs...@apache.org>님이 작성:
>
> Lucene does this RAM/FS stuff seamlessly for you in the background.  Just
> open the FSDirectory and do your indexing.  If I had to guess, though, from
> a quick glance, I think you should do the addIndexes after the ramWriter
> close, but that's just a guess, as I haven't tried it.
>
> -Grant
>
> On Aug 7, 2008, at 10:12 PM, 장용석 wrote:
>
> hi,
>> I am using RamDirectory and FSDirectory for indexing documents.
>> I use RamDirectory as Buffer.
>>
>> For example,
>> -----------------------------------
>> String indexDir = "d:/lucene_data/merge_test_index";
>> Analyzer analyzer  = new StopAnalyzer();
>>
>> RAMDirectory ramDir    = new RAMDirectory();
>> IndexWriter  ramWriter = new IndexWriter(ramDir, analyzer, true);
>>
>> for (int i = 0; i < 10000; i++) {
>>          Document doc = new Document();
>>          doc.add(new Field("id", "test id"+i, Field.Store.YES,
>> Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
>>           writer.addDocument(doc);
>> }
>>
>>
>> IndexWriter fsWriter   = new IndexWriter(indexDir, analyzer, true);
>> fsWriter.addIndexes(new Directory[] { ramDir });
>> ramWriter.close();
>> fsWriter.close();
>> ------------------------------------
>>
>> I know IndexWriter.addIndexes(Directory[] dir) method can merge other
>> indexes.
>>
>> But, when I execute my program, just 2 files are created in index
>> directory.
>> (segments.gen and segments_4)
>> And when I open with LUKE the index then meet error , It's bad index file.
>>
>> What's wrong about that code..?
>> It's almost same as sample source code on book. I can't find any reason.
>>
>> Please let me know what is wrong.
>>
>> Thank you.
>>
>>
>> --
>> DEV용식
>> http://devyongsik.tistory.com
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>


-- 
DEV용식
http://devyongsik.tistory.com

Re: merge Index

Posted by Grant Ingersoll <gs...@apache.org>.
Lucene does this RAM/FS stuff seamlessly for you in the background.   
Just open the FSDirectory and do your indexing.  If I had to guess,  
though, from a quick glance, I think you should do the addIndexes  
after the ramWriter close, but that's just a guess, as I haven't tried  
it.

-Grant

On Aug 7, 2008, at 10:12 PM, 장용석 wrote:

> hi,
> I am using RamDirectory and FSDirectory for indexing documents.
> I use RamDirectory as Buffer.
>
> For example,
> -----------------------------------
> String indexDir = "d:/lucene_data/merge_test_index";
> Analyzer analyzer  = new StopAnalyzer();
>
> RAMDirectory ramDir    = new RAMDirectory();
> IndexWriter  ramWriter = new IndexWriter(ramDir, analyzer, true);
>
> for (int i = 0; i < 10000; i++) {
>           Document doc = new Document();
>           doc.add(new Field("id", "test id"+i, Field.Store.YES,
> Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
>            writer.addDocument(doc);
> }
>
>
> IndexWriter fsWriter   = new IndexWriter(indexDir, analyzer, true);
> fsWriter.addIndexes(new Directory[] { ramDir });
> ramWriter.close();
> fsWriter.close();
> ------------------------------------
>
> I know IndexWriter.addIndexes(Directory[] dir) method can merge other
> indexes.
>
> But, when I execute my program, just 2 files are created in index  
> directory.
> (segments.gen and segments_4)
> And when I open with LUKE the index then meet error , It's bad index  
> file.
>
> What's wrong about that code..?
> It's almost same as sample source code on book. I can't find any  
> reason.
>
> Please let me know what is wrong.
>
> Thank you.
>
>
> -- 
> DEV용식
> http://devyongsik.tistory.com



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