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?

0

1 Answer 1

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?

3
  • 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 7, 2012 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. stackoverflow.com/questions/7414715/… . Could you explain a little why is it necessary to have the Collator?
    – alvas
    Jan 7, 2012 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 7, 2012 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.