Jump to content


Error: Cannot Find Symbol Method Text


  • Please log in to reply
1 reply to this topic

#1 Hal

Hal

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 19 February 2008 - 08:55 AM

Hi
I want to make an index for txt files by using Lucene, it got an error: cannot find symbol method Text. what is it about? Does it mean the Text is not in Field?

thank you v much

pls look into my code:



package TestLucene;
import java.io.File;
import java.io.FileReader;
import java.io.Reader;
import java.util.Date;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;

import org.apache.lucene.document.Fieldable;
import java.io.Serializable;
/**
* This class demonstrate the process of creating index with Lucene
* for text files
*/
public class Lucene {
public static void main(String[] args) throws Exception{
//indexDir is the directory that hosts Lucene's index files
        File   indexDir = new File("D:\\luceneIndex");
        //dataDir is the directory that hosts the text files that to be indexed
        File   dataDir  = new File("D:\\luceneData");
        Analyzer luceneAnalyzer = new StandardAnalyzer();
        File[] dataFiles  = dataDir.listFiles();
        IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,true);
        long startTime = new Date().getTime();
        for(int i = 0; i < dataFiles.length; i++){
         if(dataFiles[i].isFile() && dataFiles[i].getName().endsWith(".txt")){
         System.out.println("Indexing file " + dataFiles[i].getCanonicalPath());
         Document document = new Document();
         Reader txtReader = new FileReader(dataFiles[i]);
         document.add(Field.Text("path",dataFiles[i].getCanonicalPath()));
         document.add(Field.Text("contents",txtReader));
        
                                indexWriter.addDocument(document);
         }
        }
        indexWriter.optimize();
        indexWriter.close();
        long endTime = new Date().getTime();
        
        System.out.println("It takes " + (endTime - startTime)
                           + " milliseconds to create index for the files in directory "
                    + dataDir.getPath());        
}
}

#2 ham90mack

ham90mack

    Advanced Member

  • Members
  • PipPipPip
  • 937 posts

Posted 19 February 2008 - 11:49 PM

Lucene version 1.4.3 had the static method Text in Field, but version 2.2.0 did not.  Check the Lucene API to find where the substitute for Text is: http://lucene.apache.org/java/2_2_0/api/index.html

It appears that a valid replacement for the second one is:
CODE
document.add(new Field("contents",txtReader));

but the first one does not have a constructor that matches what you have for parameters exactly.  Check out the api for Field: http://lucene.apache.org/java/2_2_0/api/or...ment/Field.html


ham90mack
http://ham90mack.googlepages.com
Resistance may be futile,
But capacitance has potential.
BLAH!