Return-Path: Delivered-To: apmail-lucene-general-archive@www.apache.org Received: (qmail 7283 invoked from network); 20 Sep 2005 02:49:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 Sep 2005 02:49:16 -0000 Received: (qmail 41647 invoked by uid 500); 20 Sep 2005 02:49:16 -0000 Delivered-To: apmail-lucene-general-archive@lucene.apache.org Received: (qmail 41631 invoked by uid 500); 20 Sep 2005 02:49:15 -0000 Mailing-List: contact general-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: general@lucene.apache.org Delivered-To: mailing list general@lucene.apache.org Received: (qmail 41617 invoked by uid 99); 20 Sep 2005 02:49:15 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Sep 2005 19:49:15 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [69.55.225.129] (HELO ehatchersolutions.com) (69.55.225.129) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Sep 2005 19:49:24 -0700 Received: by ehatchersolutions.com (Postfix, from userid 504) id 5987813E2008; Mon, 19 Sep 2005 22:48:41 -0400 (EDT) Received: from [172.16.1.101] (va-71-48-138-146.dhcp.sprint-hsd.net [71.48.138.146]) by ehatchersolutions.com (Postfix) with ESMTP id E5CBA13E2006 for ; Mon, 19 Sep 2005 22:48:13 -0400 (EDT) Mime-Version: 1.0 (Apple Message framework v734) In-Reply-To: <20050920023449.33123.qmail@web53710.mail.yahoo.com> References: <20050920023449.33123.qmail@web53710.mail.yahoo.com> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <9AD4249D-8A06-46D2-AD6A-5536B19E9826@ehatchersolutions.com> Content-Transfer-Encoding: 7bit From: Erik Hatcher Subject: Re: How to create Index ? Date: Mon, 19 Sep 2005 22:48:10 -0400 To: general@lucene.apache.org X-Mailer: Apple Mail (2.734) X-Spam-Checker-Version: SpamAssassin 3.0.1 (2004-10-22) on javelina X-Spam-Level: X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Status: No, score=-5.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.0.1 X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Arpit, It looks like you've omitted the import statements from Indexer.java. The book omits import statements to conserve space, but they are important. The code is provided in its entirety at http://www.lucenebook.com In fact, you could build an index by running the code directly (read the README file and follow the instructions first) by typing "ant Indexer" and following the prompts. One of the prompts asks you where to put the index itself, and the next prompt asks for the directory of text files to index. Erik On Sep 19, 2005, at 10:34 PM, Arpit Sharma wrote: > I have put the .jar file in C:\lucene and I have also > unzip it and have also put all the directories(like > analysis,index,store) in C:\ lucene. > > Now how to create a index ? > all the text files are in C:\text directory. I have > "lucene in action" book and with the help of it I made > a Indexer.java program in C:\lucene and when I tried > to compile it it is giving lot's of errors. > The code is fine(it is copy paste from the book). > > I am sure that there is some path problem. What should > I do ? > > Thanks > > Here is the code of the Indexer.java:- > ---------------- > > /** * This code was originally written for > ** Erik's Lucene intro java.net article */ > > public class Indexer { > > public static void main(String[] args) throws > Exception { > > if (args.length != 2) { > throw new Exception("Usage: java " + > Indexer.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 + " > files took " > + (end - start) + " milliseconds"); > > } > > // open an index and start file directory traversal > > > public static int index(File indexDir, File dataDir) > > throws IOException { > if (!dataDir.exists() || !dataDir.isDirectory()) { > > throw new IOException(dataDir > + " does not exist or is not a directory"); > } > > IndexWriter writer = new IndexWriter(indexDir, > > new StandardAnalyzer(), true); > writer.setUseCompoundFile(false); > > indexDirectory(writer, dataDir); > > int numIndexed = writer.docCount(); > > writer.optimize(); > writer.close(); > > return numIndexed; > } > > // recursive method that calls itself when it finds > a directory > > private static void indexDirectory(IndexWriter > writer, File dir) > throws IOException { > > 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); > } > } > } > > // method to actually index a file using Lucene > > private static void indexFile(IndexWriter writer, > File f) > throws IOException { > > 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))); > > doc.add(Field.Keyword("filename", > f.getCanonicalPath())); > writer.addDocument(doc); > } > } > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com >