You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by ashwin kumar <gv...@gmail.com> on 2007/02/13 06:34:49 UTC

hi compile error

hi all my name is ashwin i am trying to compile this program but its not
getting compiled the error msg follows the code which is below

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
 {

      File   fileDir  = new File("C:\\files_to_index ");//fileDir is the
directory that contains the text files to be indexed

      File   indexDir = new File("C:\\luceneIndex"); //indexDir is the
directory that hosts Lucene's index files

      Analyzer luceneAnalyzer = new StandardAnalyzer();

      IndexWriter indexWriter = new
IndexWriter(indexDir,luceneAnalyzer,true);

       File[] textFiles  = fileDir.listFiles();

       long startTime = new Date().getTime();

       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());
  }
}

error msg:

--------------------Configuration: <Default>--------------------
D:\ASHWIN\testing\searching\TextFileIndexer.java:40: cannot find symbol
symbol  : variable Field
location: class TextFileIndexer
       document.add(Field.Text("content",textReader));
                    ^
D:\ASHWIN\testing\searching\TextFileIndexer.java:41: cannot find symbol
symbol  : variable Field
location: class TextFileIndexer
       document.add(Field.Text("path",textFiles[i].getPath()));
                    ^
2 errors

Process completed.

Re: hi compile error

Posted by Kapil Chhabra <ka...@naukri.com>.
Hi,
replace

/import org.apache.lucene.document.Field.*; /

with

/import org.apache.lucene.document.Field; /

and you are done.

Regards,
kapilChhabra

ashwin kumar wrote:
> hi all my name is ashwin i am trying to compile this program but its not
> getting compiled the error msg follows the code which is below
>
> 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
> {
>
>      File   fileDir  = new File("C:\\files_to_index ");//fileDir is the
> directory that contains the text files to be indexed
>
>      File   indexDir = new File("C:\\luceneIndex"); //indexDir is the
> directory that hosts Lucene's index files
>
>      Analyzer luceneAnalyzer = new StandardAnalyzer();
>
>      IndexWriter indexWriter = new
> IndexWriter(indexDir,luceneAnalyzer,true);
>
>       File[] textFiles  = fileDir.listFiles();
>
>       long startTime = new Date().getTime();
>
>       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());
>  }
> }
>
> error msg:
>
> --------------------Configuration: <Default>--------------------
> D:\ASHWIN\testing\searching\TextFileIndexer.java:40: cannot find symbol
> symbol  : variable Field
> location: class TextFileIndexer
>       document.add(Field.Text("content",textReader));
>                    ^
> D:\ASHWIN\testing\searching\TextFileIndexer.java:41: cannot find symbol
> symbol  : variable Field
> location: class TextFileIndexer
>       document.add(Field.Text("path",textFiles[i].getPath()));
>                    ^
> 2 errors
>
> Process completed.
>


Re: hi compile error

Posted by Bhavin Pandya <bh...@rediff.co.in>.
Hi ashwin,

I think there is error in your import statement...

import org.apache.lucene.document.Field;

Thanks.
Bhavin pandya

----- Original Message ----- 
From: "ashwin kumar" <gv...@gmail.com>
To: <ja...@lucene.apache.org>
Sent: Tuesday, February 13, 2007 11:04 AM
Subject: hi compile error


> hi all my name is ashwin i am trying to compile this program but its not
> getting compiled the error msg follows the code which is below
>
> 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
> {
>
>      File   fileDir  = new File("C:\\files_to_index ");//fileDir is the
> directory that contains the text files to be indexed
>
>      File   indexDir = new File("C:\\luceneIndex"); //indexDir is the
> directory that hosts Lucene's index files
>
>      Analyzer luceneAnalyzer = new StandardAnalyzer();
>
>      IndexWriter indexWriter = new
> IndexWriter(indexDir,luceneAnalyzer,true);
>
>       File[] textFiles  = fileDir.listFiles();
>
>       long startTime = new Date().getTime();
>
>       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());
>  }
> }
>
> error msg:
>
> --------------------Configuration: <Default>--------------------
> D:\ASHWIN\testing\searching\TextFileIndexer.java:40: cannot find symbol
> symbol  : variable Field
> location: class TextFileIndexer
>       document.add(Field.Text("content",textReader));
>                    ^
> D:\ASHWIN\testing\searching\TextFileIndexer.java:41: cannot find symbol
> symbol  : variable Field
> location: class TextFileIndexer
>       document.add(Field.Text("path",textFiles[i].getPath()));
>                    ^
> 2 errors
>
> Process completed.
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: hi compile error

Posted by Saroja Kanta Maharana <sa...@gmail.com>.
Hi,

   I also new to lucene. As see your error, It may be the Lucene version
problem. Which version
 r u using? means which which jar file ? Will you say me the Lucene Jar file
name ??



Regards

Saroj

On 2/13/07, Doron Cohen <DO...@il.ibm.com> wrote:
>
> Hi ashwin,
>
> ashwin kumar wrote:
>
> >       File   fileDir  = new File("C:\\files_to_index ");//fileDir is the
>
> Notice a redundant trailing space here.
>
> >                     document.add(Field.Text("content",textReader));
>
> > D:\ASHWIN\testing\searching\TextFileIndexer.java:40: cannot find symbol
> > symbol  : variable Field
> > location: class TextFileIndexer
> >        document.add(Field.Text("content",textReader));
> >                     ^
>
> Field.Text was deprecated in Lucene 1.9.1 and removed in Lucene 2.0.
> So if Lucene 2.0 is used this explains the compilation error.
>
> See also FAQ Entry "How do I get code written for Lucene 1.4.x to work
> with
> Lucene 2.x?"
>
> http://wiki.apache.org/jakarta-lucene/LuceneFAQ#head-86d479476c63a2579e867b75d4faa9664ef6cf4d
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>


-- 
Regards
Saroja kanta Maharana
+919886750538

Re: hi compile error

Posted by Doron Cohen <DO...@il.ibm.com>.
Hi ashwin,

ashwin kumar wrote:

>       File   fileDir  = new File("C:\\files_to_index ");//fileDir is the

Notice a redundant trailing space here.

>                     document.add(Field.Text("content",textReader));

> D:\ASHWIN\testing\searching\TextFileIndexer.java:40: cannot find symbol
> symbol  : variable Field
> location: class TextFileIndexer
>        document.add(Field.Text("content",textReader));
>                     ^

Field.Text was deprecated in Lucene 1.9.1 and removed in Lucene 2.0.
So if Lucene 2.0 is used this explains the compilation error.

See also FAQ Entry "How do I get code written for Lucene 1.4.x to work with
Lucene 2.x?"
http://wiki.apache.org/jakarta-lucene/LuceneFAQ#head-86d479476c63a2579e867b75d4faa9664ef6cf4d



---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org