apache / lucene

Apache Lucene open-source search software
https://lucene.apache.org/
Apache License 2.0
2.39k stars 949 forks source link

Return multiple fields in Document [LUCENE-77] #1155

Closed asfimport closed 17 years ago

asfimport commented 21 years ago

Currently there is no quick way to retrieve multiple fields with the same name, other than retrieving Enumeration of all fields. A useful shortcut would be to provide a method on Document:

public Field[] getFields(String name)


Migrated from LUCENE-77 by Andrzej Bialecki, resolved May 27 2006 Environment:

Operating System: other
Platform: Other
asfimport commented 21 years ago

Otis Gospodnetic (migrated from JIRA)

This method exists in the nightly build. This is an excerpt from the CHANGES.txt:

  1. Added getFields(String) and getValues(String) methods. Contributed by Rasik Pandey on 2002-10-09 (Rasik Pandey via otis)

Please reopen if this doesn't work for you.

asfimport commented 21 years ago

Andrzej Bialecki (migrated from JIRA)

Sorry, I missed that in my copy... However, the implementation uses Collections framework. Below is the code rewritten using JDK1.1.x Vector:

public final Field[] getFields(String name) { Vector tempFieldList = new Vector(); for (DocumentFieldList list = fieldList; list != null; list = list.next) { if (list.field.name().equals(name)) { tempFieldList.add(list.field); } } int fieldCount = tempFieldList.size(); if (fieldCount == 0) return null; else { Field[] fields = new Field[fieldCount]; tempFieldList.copyInto(fields); return fields; } }

asfimport commented 21 years ago

Otis Gospodnetic (migrated from JIRA)

Thank you for the code, but like I mentioned in the direct email to you a few days ago, I believe Lucene developers reached the consensus that any new code that gets written does not need to support JDK 1.1.x. On the whole I think we agreed that we don't need to make sure to support JDK 1.1.x.

Lucene Developers - please reopen, or better yet, modify the code, if this is not true.

asfimport commented 21 years ago

Andrzej Bialecki (migrated from JIRA)

Ok, I can accept that - although it's a pity, since most mobile platforms support only 1.1. However, please bear with me - the version in CVS uses inefficient for() loop, whereas the code above uses copyInto(), which in turn uses System.arraycopy(), implemented as native, so it appears to me there is still some benefit in making this change...

Best regards Andrzej