0

Any idea how to create a lucene Document from Strings or Textfiles or Directories in the new version of Lucene? Where can i find the API in the current lucene version??

previously in 2_9_4, i could:

IndexWriter = writer = new IndexWriter(indexDir, config);
add(writer, "Lucene");

or even in 3_0_2:

IndexWriter = writer = new IndexWriter(indexDir, config);
writer.addDocument(createDocument("lucene");

But now i'm clueless how the add document goes. How do i add textfile as a lucene Document? or even a Directory of textfiles?

alvas
  • 115,346
  • 109
  • 446
  • 738

1 Answers1

1

Hm, among the 3.5 examples I find this (http://lucene.apache.org/java/3_5_0/api/contrib-icu/index.html):

        Collator collator = Collator.getInstance(new Locale("ar"));  
        ICUCollationKeyAnalyzer analyzer = new
        ICUCollationKeyAnalyzer(collator);
        RAMDirectory ramDir = new RAMDirectory();   
        IndexWriter writer = new IndexWriter(ramDir, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);   
        Document doc = new Document();   
        doc.add(new Field("content","\u0633\u0627\u0628", Field.Store.YES,Field.Index.ANALYZED));   
        writer.addDocument(doc);   
        writer.close();

The IndexWriter is there (http://lucene.apache.org/java/3_5_0/api/core/index.html)...

Are you sure you imported all necessary libraries?

ynka
  • 1,457
  • 1
  • 11
  • 27
  • yep, no worries about the libraries import because as long as I get the class name correct, the IDE helps me import them. – alvas Jan 07 '12 at 11:40
  • if i need to add a new String to the Index, i would need to create a new doc right? I tried around and came up with something like this. http://stackoverflow.com/questions/7414715/lucene-phrase-query-not-working/8720927#8720927 . Could you explain a little why is it necessary to have the Collator? – alvas Jan 07 '12 at 11:41
  • @2er0 sorry, I don't think it's necessary, I wanted to show you an example of creating a document from a String in 3.5, and this example seemed sufficient. I should have cut this piece of probably. – ynka Jan 07 '12 at 11:54