lucene-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From benglish <>
Subject Re: Train Lucene with topic-defined files
Date Sun, 22 Jun 2014 16:50:25 GMT
Dear Koji,

I'd deeply appreciate your kind helps.
I have created the index something like below. I was wondering if you would
tell me if this code is correct and also help me for the rest of the code
and how to insert the index into the training part of the Naive Bayes

private static void BuildIndex
        Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
        File myIndex = new File("indexCorpus/");
        Directory index =;
        IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40,
        IndexWriter w = new IndexWriter(index, config);
        File dir = new File("trainCorpus/");
        File[] directoryListing = dir.listFiles();
        int x = directoryListing.length; //#files in a directory
        for(int i = 0; i < x; i++)
            String mypath = directoryListing[i].toString();
            Path wiki_path = Paths.get(mypath); //new file is chosen

            addDoc(w, eachFileContent, eachFileCategory);

private static void addDoc(IndexWriter w, String content, String category)
throws IOException {
        org.apache.lucene.document.Document doc = new
        doc.add(new org.apache.lucene.document.TextField("content", content,

        doc.add(new StringField("category", category, Field.Store.YES));


View this message in context:
Sent from the Lucene - General mailing list archive at

View raw message