hi Ganesh,
the program still gives error in the second line . it says that *cannot
find symbol * .I think that we are initializing the object of Field class
two times, that is why we are getting error.
document.add(new Field("content",textReader));
document.add(new Field("path",textFiles[i].getPath()));
Thanks,
Nitin Gopi
On Fri, Mar 6, 2009 at 11:01 AM, Ganesh <[email protected]> wrote:
> Hello gopi,
>
> My comments.
>
> if(textFiles[i].isFile() > textFiles[i].getName().endsWith(".txt")){
>>
> && should be used.
>
> *document.add(Field.Text("content",textReader));
>>
> document.add(new Field("content", textReader);
>
> document.add(Field.Text("path",textFiles[i].getPath()));*
>>
> document.add(new Field("path", textFiles[i].getPath());
>
> Regards
> Ganesh
>
> ----- Original Message ----- From: "nitin gopi" <[email protected]>
> To: <[email protected]>
> Sent: Friday, March 06, 2009 8:24 AM
> Subject: error in code
>
>
>
> Hi all,
>>
>> I am getting error in running this code. Can somebody please tell me what
>> is the problem? The code is given below. The bold lines were giving error
>> as
>> *cannot find symbol *
>>
>>
>>
>> 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;
>>
>> /**
>> * This class demonstrates the process of creating an index with Lucene
>> * for text files in a directory.
>> */
>> public class TextFileIndexer {
>> public static void main(String[] args) throws Exception{
>> //fileDir is the directory that contains the text files to be indexed
>> File fileDir = new File("C:\\files_to_index ");
>>
>> //indexDir is the directory that hosts Lucene's index files
>> File indexDir = new File("C:\\luceneIndex");
>> Analyzer luceneAnalyzer = new StandardAnalyzer();
>> IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,true);
>> File[] textFiles = fileDir.listFiles();
>> long startTime = new Date().getTime();
>>
>> //Add documents to the index
>> for(int i = 0; i < textFiles.length; i++){
>> if(textFiles[i].isFile() > textFiles[i].getName().endsWith(".txt")){
>> System.out.println("File " + textFiles[i].getCanonicalPath()
>> + " is being indexed");
>> Reader textReader = new FileReader(textFiles[i]);
>> Document document = new Document();
>> *document.add(Field.Text("content",textReader));
>> document.add(Field.Text("path",textFiles[i].getPath()));*
>> indexWriter.addDocument(document);
>> }
>> }
>>
>> indexWriter.optimize();
>> indexWriter.close();
>> long endTime = new Date().getTime();
>>
>> System.out.println("It took " + (endTime - startTime)
>> + " milliseconds to create an index for the files in the
>> directory "
>> + fileDir.getPath());
>> }
>> }
>>
>> Regards ,
>> Nitin Gopi
>>
>>
> Send instant messages to your online friends http://in.messenger.yahoo.com
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>