lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject Re: Lucene in Action book. Problems with first example
Date Tue, 16 Dec 2008 10:44:35 GMT
What were the errors?
Just a guess ... it may be possible that you are using the wrong lucene 
version - the one in the book is not the most updated one avbl today

"XP is making a bet. It is betting that it is better to do a simple thing 
today and pay a little more tomorrow to change it if it needs it, than to 
do a more complicated thing today that may never be used anyway" - Extreme 
Programming Explained, Embrace Change

Best Regards, 

Joseph F. Syjuco 
Team Lead 
M3 Alpha - e-Commerce 
Lawson PSSC, Inc. 
4th Floor, One World Square Building 
Upper McKinley Road, Taguig City 1634 

Work: +63 (2) 976-3600 loc 79396
Mobile: +63 (917) 855-3436

-------------------- Internet e-Mail Disclaimer --------------------
This e-mail and any files transmitted with it are confidential and 
intended solely for the use of the individual or entity to which they are 
addressed. If you are not the intended recipient you are notified that any 
use, disclosure, copying or distribution of the information is prohibited. 
In such case, you should destroy this message and kindly notify the sender 
by reply e-mail. The views expressed in this e-mail and any attachments 
are personal and, unless stated explicitly, do not represent the views of 
Lawson Software, Inc. 

"Oleg Oltar" <> 
12/16/2008 06:41 PM
Please respond to


Lucene in Action book. Problems with first example

I am starting to learn Lucene.
I am using Lucene in Action book for startup (It was recommended to me). I
tried to compile first example from that book, but my ide (I use eclipse,
shows there are some errors in my code). I am just the beginner here, and 
really need to compile at least few programs.... before I can solve 
myself. So I decided to post here the whole code with my comments. Please
help me!!!

package org.main;




import java.util.Date;

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;

public class SimpleIndexer {


 * @param args


public static void main(String[] args) throws Exception{

if (args.length !=2){

throw new Exception("Usage: java" + SimpleIndexer.class.getName() + 


 File indexDir = new File(args[0]);

File dataDir = new File(args[1]);

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

int numIndexed = index(indexDir, dataDir);

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

System.out.println("Indexing " + numIndexed +" took " + (end - start) +



public static int index(File indexDir, File dataDir) throws IOException {

 if (!dataDir.exists() || !dataDir.isDirectory()){

 throw new IOException(dataDir + " doesn't exist or not a directory");


 IndexWriter writer = new IndexWriter(indexDir, new StandardAnalyzer(), 
// Not sure why eclipse crosses this


 indexDirectory(writer, dataDir);

 int numIndexed = writer.docCount(); // Not sure why eclipse crosses this



 return numIndexed;


 private static void indexDirectory(IndexWriter writer, File dir)

File[] files = dir.listFiles();

for (int i=0; i< files.length; i++){

File f = files[i];


indexDirectory(writer, f);

 } else if(f.getName().endsWith(".txt")){

indexFile(writer, f);




 private static void indexFile(IndexWriter writer, File f) 

if(f.isHidden() || !f.exists() || !f.canRead()){



System.out.println("Indexing " + f.getCanonicalPath());

 Document doc = new Document();

doc.add(Field.Text("contents", new FileReader(f))); // Eclipse says: The
method Text(String, FileReader) is undefined for the type Field

 doc.add(Field.Keyword("filename", f.getCanonicalPath())); // Eclipse 
method Keyword(String, String) is undefined for the type Field




Please explain me why these errors are shown, and how to fix them. Maybe,
the version of lucene used by author of the book, contained needed 
So may it be that the book is outdated and can't be used for learning. If
so, please recommend me something that can help me to start with lucene.

Thanks in advance,

  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message