but anyway,I've done it.thanks for your help. I did look up your
source code and find it easier to understand. this is the kind of help
that I want.

thank you very much then. :-)

On 10/27/10, Seth Rosen <s...@architexa.com> wrote:
> Yakob the boolean in the constructor should be true if you want to create a
> NEW index in INDEX_DIR and false to append to an existing one as seen here
> [1]
>
> As for adding a directory to an index you will need to validate the
> directory, then loop through it recursively and add each doc to the writer
> you created.
>
> static void indexDocs(IndexWriter writer, File file)
>>>
>>>     throws IOException {
>>>
>>>     // do not try to index files that cannot be read
>>>
>>>     if (file.canRead()) {
>>>
>>>       if (file.isDirectory()) {
>>>
>>>         String[] files = file.list();
>>>
>>>         // an IO error could occur
>>>
>>>         if (files != null) {
>>>
>>>           for (int i = 0; i < files.length; i++) {
>>>
>>>             indexDocs(writer, new File(file, files[i]));
>>>
>>>           }
>>>
>>>         }
>>>
>>>       } else {
>>>
>>>         System.out.println("adding " + file);
>>>
>>>         try {
>>>
>>>           writer.addDocument(FileDocument.Document(file));
>>>
>>>         }
>>>
>>>         // at least on windows, some temporary files raise this exception
>>>> with an "access denied" message
>>>
>>>         // checking if the file can be read doesn't help
>>>
>>>         catch (FileNotFoundException fnfe) {
>>>
>>>           ;
>>>
>>>         }
>>>
>>>       }
>>>
>>>     }
>>>
>>>   }
>>>
>>>
> [1]
> http://lucene.apache.org/java/3_0_0/api/core/org/apache/lucene/index/IndexWriter.html#IndexWriter(org.apache.lucene.store.Directory,
> org.apache.lucene.analysis.Analyzer, boolean,
> org.apache.lucene.index.IndexWriter.MaxFieldLength)
>
> Seth Rosen
> www.architexa.com
> Understand & Document Code In Seconds
> s...@architexa.com <vin...@architexa.com>
>
>
>
> On Wed, Oct 27, 2010 at 9:51 AM, Yakob <jacob...@opensuse-id.org> wrote:
>
>> On 10/27/10, Seth Rosen <s...@architexa.com> wrote:
>> > Yakob,
>> > Here is a snippet of an example of IndexWriter from the lucene source
>> that
>> > you might find helpful.
>> >
>> >
>> >> IndexWriter writer = new IndexWriter(FSDirectory.open(INDEX_DIR), new
>> >> StandardAnalyzer(Version.LUCENE_CURRENT), true,
>> >> IndexWriter.MaxFieldLength.LIMITED);
>>
>> // the above code should change true into false so that the index will
>> still be open right?
>> // I mean surely the index shouldn't be close
>> >
>> > System.out.println("Indexing to directory '" +INDEX_DIR+ "'...");
>> >
>> // what confuse me is how can add a new directory path containing new
>> Documents to a
>> // lucene class. so that lucene will index those new documents and add
>> it to an existing
>> // index.
>> > indexDocs(writer, docDir);
>> >
>> > System.out.println("Optimizing...");
>> >
>> > writer.optimize();
>> >
>> > writer.close();
>> >
>> >
>> > Seth Rosen
>> > www.architexa.com
>> > Understand & Document Code In Seconds
>> > s...@architexa.com <vin...@architexa.com>
>> >
>> >
>> >
>>
>>
>> --


-- 
http://jacobian.web.id

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

Reply via email to