Return-Path: Delivered-To: apmail-jakarta-lucene-dev-archive@apache.org Received: (qmail 36591 invoked from network); 26 Apr 2002 18:27:08 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 26 Apr 2002 18:27:08 -0000 Received: (qmail 26615 invoked by uid 97); 26 Apr 2002 18:27:11 -0000 Delivered-To: qmlist-jakarta-archive-lucene-dev@jakarta.apache.org Received: (qmail 26589 invoked by uid 97); 26 Apr 2002 18:27:09 -0000 Mailing-List: contact lucene-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Lucene Developers List" Reply-To: "Lucene Developers List" Delivered-To: mailing list lucene-dev@jakarta.apache.org Received: (qmail 26575 invoked by uid 50); 26 Apr 2002 18:27:08 -0000 Date: 26 Apr 2002 18:27:08 -0000 Message-ID: <20020426182708.26574.qmail@nagoya.betaversion.org> From: bugzilla@apache.org To: lucene-dev@jakarta.apache.org Cc: Subject: DO NOT REPLY [Bug 7912] - Field.isIndexed() returns false for UnStored fields X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT . ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE. http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7912 Field.isIndexed() returns false for UnStored fields ------- Additional Comments From fix@idiom.com 2002-04-26 18:27 ------- Hi. I wrote a class that'll check a lucene index and tell you all the searchable fields in it. The code is pasted below. Save it as 'CheckIsIndexed.java' Run the class using java from the command line and pass it one argument, the name of an index to check. If you the index does not exist, a one-document index will be created in the current directory with 4 fields, and the analysis will be based on that. In my experience, UnStored fields are not returned. It may be that I'm doing something wrong, in which case I hope to learn something. The getSearchableFields(Directory directory) method may also be of interest to other lucene users. best, eric -------------------- CODE BEGINS AFTER THIS LINE ---------------- /** CheckIsIndexed.java Test to see if isIndexed() works April 2002 Eric Fixler */ import java.util.*; import java.io.*; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.index.*; import org.apache.lucene.document.*; import org.apache.lucene.store.*; public class CheckIsIndexed { private Directory directory = null; private int documentCount = 0; public static final boolean DEBUG = true; public boolean printAllDocuments = false; public CheckIsIndexed (String indexName) throws IOException { boolean makeIt = this.initializeIndex(indexName); if (makeIt) this.makeIndex(); } private boolean initializeIndex(String indexName) throws IOException { File idir = new File(indexName); boolean isNew = ! idir.exists(); if (isNew) idir.mkdirs(); if (! idir.isDirectory()) throw new IOException("Directory " + indexName + " does not exist (may be a file?)"); System.out.println("Getting an index at " + idir.getAbsolutePath()); if (isNew) System.out.println("(created it)"); this.directory = FSDirectory.getDirectory(idir, false); return isNew; } public void makeIndex() throws IOException { System.out.println("Opening index..."); IndexWriter writer = new IndexWriter(directory,new StandardAnalyzer(), true); this.addDocument(writer); writer.optimize(); writer.close(); directory.close(); System.out.println("Done, index closed.\n"); } private void addDocument(IndexWriter writer) throws IOException { System.out.println("Adding document " + this.documentCount + "..."); Document doc = new Document(); doc.add(Field.UnIndexed("unindexed", "UnIndexed Field")); doc.add(Field.UnStored("unstored", "Unstored Field: should, however, be indexed, no?")); doc.add(Field.Text("text", "Text field: should return true for isIndexed()")); doc.add(Field.Text("keyword", "Keyword field: should return true for isIndexed()")); writer.addDocument(doc); this.documentCount++; } public void checkIndex() throws IOException { String[] fields = this.getSearchableFields(this.directory); System.out.println("Searchable field names in directory: "); for (int i = 0; i < fields.length; i++) System.out.println("\t" + fields[i]); System.out.print("\n"); } //I suspect there's probably a better way to iterate over the index, but I'm not sure how... /** This method looks at every document in the index and compiles all the searchable fields it finds. */ public String[] getSearchableFields(Directory dir) throws IOException { IndexReader reader = IndexReader.open(dir); int count = 0; Set fieldNames = new HashSet(); for (int i = 0; i < reader.maxDoc(); i++) { try { if (DEBUG && (reader.isDeleted(i))) { System.out.println("deleted doc " + i); continue; } Document doc = reader.document(i); if (DEBUG && (doc == null)) { System.out.println("null doc " + i); continue; } if (this.printAllDocuments) System.out.println("Analyzing document " + i + "..."); Enumeration en = doc.fields(); while (en.hasMoreElements()) { Field field = (Field) en.nextElement(); boolean indexed = field.isIndexed(); if (this.printAllDocuments) System.out.println("\t" + field.name() + ", isIndexed? : " + indexed); if (indexed) fieldNames.add(field.name()); } if (this.printAllDocuments) System.out.println("----------------------------------------"); } catch (Exception e) { System.err.println("Error reading documents for field info: " + e + "\n\t" + e.getMessage()); e.printStackTrace(System.err); reader.close(); if (e instanceof IOException) throw (IOException) e; if (e instanceof RuntimeException) throw (RuntimeException) e; return new String[0]; } } reader.close(); if (DEBUG) System.out.println("Done checking index"); String[] rval = (String[]) fieldNames.toArray(new String[fieldNames.size()]); Arrays.sort(rval); return rval; } public static void main (String[] args) throws Exception { CheckIsIndexed ces = new CheckIsIndexed(args[0]); ces.checkIndex(); } } // _END_ -- To unsubscribe, e-mail: For additional commands, e-mail: