Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 82199 invoked from network); 16 Dec 2008 10:50:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Dec 2008 10:50:01 -0000 Received: (qmail 94049 invoked by uid 500); 16 Dec 2008 10:50:07 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 94016 invoked by uid 500); 16 Dec 2008 10:50:07 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 94005 invoked by uid 99); 16 Dec 2008 10:50:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Dec 2008 02:50:07 -0800 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [74.125.92.24] (HELO qw-out-2122.google.com) (74.125.92.24) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Dec 2008 10:49:52 +0000 Received: by qw-out-2122.google.com with SMTP id 5so578603qwi.53 for ; Tue, 16 Dec 2008 02:49:28 -0800 (PST) Received: by 10.215.13.12 with SMTP id q12mr9065174qai.283.1229424568400; Tue, 16 Dec 2008 02:49:28 -0800 (PST) Received: from ?10.17.4.4? (pool-173-48-164-75.bstnma.fios.verizon.net [173.48.164.75]) by mx.google.com with ESMTPS id 5sm20229ywl.35.2008.12.16.02.49.26 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 16 Dec 2008 02:49:27 -0800 (PST) Message-Id: <41C23ED5-2BD0-4758-8BA3-9C61E7368F1A@mikemccandless.com> From: Michael McCandless To: java-user@lucene.apache.org In-Reply-To: Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v929.2) Subject: Re: Lucene in Action book. Problems with first example Date: Tue, 16 Dec 2008 05:49:24 -0500 References: X-Mailer: Apple Mail (2.929.2) X-Virus-Checked: Checked by ClamAV on apache.org Lucene in Action is based on the 1.4.x release of Lucene, which is quite old by now and unfortunately some of the APIs have since been removed. We are working on the 2nd edition to fix this, but in the mean-time you need to migrate to the new APIs when you see the errors. Eg, if you look in the 1.9 javadocs for Field, it will tell you what new API to use instead of Field.Keyword, Field.Text, etc: http://lucene.apache.org/java/1_9_1/api/org/apache/lucene/document/Field.html Mike Oleg Oltar wrote: > Hi! > 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 I > really need to compile at least few programs.... before I can solve > problems > myself. So I decided to post here the whole code with my comments. > Please > help me!!! > > > package org.main; > > > import java.io.File; > > import java.io.FileReader; > > import java.io.IOException; > > 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) + > "milliseconds"); > > } > > > @SuppressWarnings("deprecation") > > 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(), true); > // Not sure why eclipse crosses this > > writer.setUseCompoundFile(false); > > > > indexDirectory(writer, dataDir); > > int numIndexed = writer.docCount(); // Not sure why eclipse crosses > this > > writer.optimize(); > > writer.close(); > > > > > > return numIndexed; > > } > > > private static void indexDirectory(IndexWriter writer, File dir) > throwsIOException{ > > File[] files = dir.listFiles(); > > for (int i=0; i< files.length; i++){ > > File f = files[i]; > > if(f.isDirectory()){ > > indexDirectory(writer, f); > > } else if(f.getName().endsWith(".txt")){ > > indexFile(writer, f); > > } > > } > > } > > > private static void indexFile(IndexWriter writer, File f) > throwsIOException{ > > if(f.isHidden() || !f.exists() || !f.canRead()){ > > return; > > } > > 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 > says:The > method Keyword(String, String) is undefined for the type Field > > writer.addDocument(doc); > > } > > > > > > } > > 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 > methods? > 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, > Oleg --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org