You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Christoph Kiehl <ki...@subshell.com> on 2002/11/12 10:10:35 UTC

How to get all field names

Hi,

I was wondering if there is a possibility to get a list of all field names
that have ever been used to index a document? This way I could filter out
some special fields, like identity and such, and do a search over the
remaining. That would give me total freedom to choose any document structure
and have all fields searched. Is this possible? Or do anyone of you have a
better way achieving that?

Regards
Christoph


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to get all field names

Posted by John Piekos <jp...@easyask.com>.
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to get all field names

Posted by Peter Mularien <pm...@deploy.com>.
I will volunteer. It might take me a bit of time as I'm not familiar 
with that part of the code yet.

Peter

Doug Cutting wrote:

> This would not be hard to implement.
>
> It would take something like:
>
> public abstract String[] IndexReader.getFieldNames();
>
> This would need to be implemented in two classes, SegmentReader and 
> SegmentsReader.  The former would just access its fieldInfos field to 
> list fields.  The latter would iterate through its readers field, 
> collecting all of the field names, and finally return them as an array.
>
> Would someone like to contribute diffs for this?
>
> Doug
>
> Ype Kingma wrote:
>
>> On Tuesday 12 November 2002 18:58, Rob Outar wrote:
>>
>>> Enumeration fields()
>>>          Returns an Enumeration of all the fields in a document.
>>
>>
>>
>> Yes, but it seems there is no such enumerator for a complete index.
>>
>> Regards,
>> Ype
>>
>>
>>> Thanks,
>>>
>>> Rob
>>>
>>>
>>> -----Original Message-----
>>> From: Christoph Kiehl [mailto:kiehl@subshell.com]
>>> Sent: Tuesday, November 12, 2002 4:11 AM
>>> To: lucene-user@jakarta.apache.org
>>> Subject: How to get all field names
>>>
>>>
>>> Hi,
>>>
>>> I was wondering if there is a possibility to get a list of all field 
>>> names
>>> that have ever been used to index a document? This way I could 
>>> filter out
>>> some special fields, like identity and such, and do a search over the
>>> remaining. That would give me total freedom to choose any document
>>> structure and have all fields searched. Is this possible? Or do 
>>> anyone of
>>> you have a better way achieving that?
>>>
>>> Regards
>>> Christoph
>>
>>
>>
>> -- 
>> To unsubscribe, e-mail:   
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail: 
>> <ma...@jakarta.apache.org>
>>
>
>
> -- 
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to get all field names

Posted by Doug Cutting <cu...@lucene.com>.
This would not be hard to implement.

It would take something like:

public abstract String[] IndexReader.getFieldNames();

This would need to be implemented in two classes, SegmentReader and 
SegmentsReader.  The former would just access its fieldInfos field to 
list fields.  The latter would iterate through its readers field, 
collecting all of the field names, and finally return them as an array.

Would someone like to contribute diffs for this?

Doug

Ype Kingma wrote:
> On Tuesday 12 November 2002 18:58, Rob Outar wrote:
> 
>>Enumeration fields()
>>          Returns an Enumeration of all the fields in a document.
> 
> 
> Yes, but it seems there is no such enumerator for a complete index.
> 
> Regards,
> Ype
> 
> 
>>Thanks,
>>
>>Rob
>>
>>
>>-----Original Message-----
>>From: Christoph Kiehl [mailto:kiehl@subshell.com]
>>Sent: Tuesday, November 12, 2002 4:11 AM
>>To: lucene-user@jakarta.apache.org
>>Subject: How to get all field names
>>
>>
>>Hi,
>>
>>I was wondering if there is a possibility to get a list of all field names
>>that have ever been used to index a document? This way I could filter out
>>some special fields, like identity and such, and do a search over the
>>remaining. That would give me total freedom to choose any document
>>structure and have all fields searched. Is this possible? Or do anyone of
>>you have a better way achieving that?
>>
>>Regards
>>Christoph
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to get all field names

Posted by Ype Kingma <yk...@xs4all.nl>.
On Tuesday 12 November 2002 18:58, Rob Outar wrote:
> Enumeration fields()
>           Returns an Enumeration of all the fields in a document.

Yes, but it seems there is no such enumerator for a complete index.

Regards,
Ype

> Thanks,
>
> Rob
>
>
> -----Original Message-----
> From: Christoph Kiehl [mailto:kiehl@subshell.com]
> Sent: Tuesday, November 12, 2002 4:11 AM
> To: lucene-user@jakarta.apache.org
> Subject: How to get all field names
>
>
> Hi,
>
> I was wondering if there is a possibility to get a list of all field names
> that have ever been used to index a document? This way I could filter out
> some special fields, like identity and such, and do a search over the
> remaining. That would give me total freedom to choose any document
> structure and have all fields searched. Is this possible? Or do anyone of
> you have a better way achieving that?
>
> Regards
> Christoph

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: How to get all field names

Posted by Rob Outar <ro...@ideorlando.org>.
Enumeration fields()
          Returns an Enumeration of all the fields in a document.

Thanks,

Rob


-----Original Message-----
From: Christoph Kiehl [mailto:kiehl@subshell.com]
Sent: Tuesday, November 12, 2002 4:11 AM
To: lucene-user@jakarta.apache.org
Subject: How to get all field names


Hi,

I was wondering if there is a possibility to get a list of all field names
that have ever been used to index a document? This way I could filter out
some special fields, like identity and such, and do a search over the
remaining. That would give me total freedom to choose any document structure
and have all fields searched. Is this possible? Or do anyone of you have a
better way achieving that?

Regards
Christoph


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>