lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nader S. Henein" <>
Subject Indexing multiple equiv fieldnames (revisited)
Date Sun, 19 May 2002 06:31:38 GMT

I've seen a few entries concerning this, so here's my two cents,
in the index I'm creating we have fairly large XML files with multiple equiv
for example if the XML file represents book information you might have
multiple <co-author> tags.

Since the .get("co-author") function in org.apache.lucene.document only
retrieves one entry, if you've
stored others you can't get to them. So I've written the following function
that retrieves n ( equivalently
named) entries, from what I can tell the order of retrieval is like popping
elements from a stack (LIFO).

The function takes in the field name (name) and maxCount witch is the
maximum number of entries you want
retrieved, it returns an array of string (trimmed) meaning if you asked it
to return 20 entries and
there are only 6, you'll get an array of length 6.

I put it in the file, because it made sense to be there, as
always use it at your own risk, and
keep me posted if you  have any questions.

Note: This is the first time I submit code to the forum, so if I'm doing
this wrong, I'd like to apologize to
the Jakarta people in advance.

    /** Returns an Array of String variables representing the Text Values of
a specific <i>name</i>
      * name: the name of the field
      * maxCount : the number of elemets you want to retreive (also helps
initialize the size of the array)*/
  public final String[] getArray(String name , int maxCount) {
    int counter = 0 ;
    String[] tempArray = new String[maxCount] ;
    for (DocumentFieldList list = fieldList; list != null; list =
        if ( && counter < maxCount &&
list.field.stringValue() != null ) {
            tempArray[counter] = list.field.stringValue() ;
            counter++ ;

    // triming the output to the relevant size
    String[] outputArray = new String[counter] ;
    System.arraycopy(tempArray, 0, outputArray, 0, counter);

    return outputArray;

May the Force be with you "Episode II rocks"

Nader S. Henein , Dubai Internet City
Tel. +9714 3911900
Fax. +9714 3911915
GSM. +9715 05659557

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message