lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Piekos" <jpie...@easyask.com>
Subject Re: How to get all field names
Date Tue, 12 Nov 2002 19:20:43 GMT
This is what I used to get all field names in an index...  

     // Returns the union of every document field in the index.
    public String[] getAllFields() throws IOException
    {
        Hashtable fields = new Hashtable();
        Vector v = new Vector();
        
        IndexReader reader = IndexReader.open(m_sIndexPath);
        for (int i=0; i<reader.numDocs(); i++)
        {
            Document doc = reader.document(i);
            Enumeration enum = doc.fields();
            while (enum.hasMoreElements())
            {
                Field f = (Field)enum.nextElement();
                String name = f.name();
                
                if (fields.get(name) != null)  // already recorded it
                    continue;
                else
                {
                    // new field, add it to the list
                    fields.put(name, name);
                    insertSorted(v, name);
                }
            }
        }

John Piekos


--
To unsubscribe, e-mail:   <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>


Mime
View raw message