Lucene - Core
  1. Lucene - Core
  2. LUCENE-102

[PATCH] Reader getFieldNames returns an extra blank field name

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core/store
    • Labels:
      None
    • Environment:

      Operating System: Windows XP
      Platform: PC

      Description

      This class demonstrates the problem....

      import org.apache.lucene.store.*;
      import org.apache.lucene.document.*;
      import org.apache.lucene.analysis.*;
      import org.apache.lucene.analysis.standard.*;
      import org.apache.lucene.index.*;
      import org.apache.lucene.search.*;
      import org.apache.lucene.queryParser.*;

      import java.util.*;
      public class FieldsTest
      {
      public static void main (String args[]) throws Exception
      {
      Analyzer analyzer=new StandardAnalyzer();
      Directory dir= new RAMDirectory();
      IndexWriter writer = new IndexWriter(dir, analyzer, true);
      Document doc=new Document();
      doc.add (new Field("field1", "value 1", true, true, true));
      doc.add (new Field("field2", "value 2", true, true, true));
      writer.addDocument(doc);
      writer.close();
      IndexReader reader=IndexReader.open(dir);
      Collection fields=reader.getFieldNames();

      //should contain only two fields but returns 3 (last fieldname
      is blank)
      Iterator i=fields.iterator();
      while(i.hasNext())

      { System.out.println("fieldname=["+i.next()+"]"); }

      }
      }

      1. ASF.LICENSE.NOT.GRANTED--TestSegmentReader.diff
        1 kB
        Bernhard Messer
      2. ASF.LICENSE.NOT.GRANTED--TestIndexReader.diff
        1 kB
        Bernhard Messer
      3. ASF.LICENSE.NOT.GRANTED--TestFieldInfos.diff
        0.8 kB
        Bernhard Messer
      4. ASF.LICENSE.NOT.GRANTED--FieldInfos.diff
        2 kB
        Bernhard Messer

        Activity

        Hide
        Bernhard Messer added a comment -

        thanks to Mark and Eric showing up the problem. It is fixed in CVS head now.

        Show
        Bernhard Messer added a comment - thanks to Mark and Eric showing up the problem. It is fixed in CVS head now.
        Hide
        Bernhard Messer added a comment -

        hi,

        there is another patch which should fix the problem of creating an empty field
        in the index. In the attachments there is the diff for FieldInfos class and
        difss for all dependend junit test cases. All junit tests pass fine. The only
        problem coming along with the patch is "luke". "luke" will not be able to open
        an index which was created with the patched lucene version. So these guys have
        to update their website and upgrade the new lucene version if committed.

        Maybe one of the lucene gurus can check if the provided change fits their needs
        or if i missed something. Nobody is perfect, but we are getting better day by
        day

        thx
        Bernhard

        Show
        Bernhard Messer added a comment - hi, there is another patch which should fix the problem of creating an empty field in the index. In the attachments there is the diff for FieldInfos class and difss for all dependend junit test cases. All junit tests pass fine. The only problem coming along with the patch is "luke". "luke" will not be able to open an index which was created with the patched lucene version. So these guys have to update their website and upgrade the new lucene version if committed. Maybe one of the lucene gurus can check if the provided change fits their needs or if i missed something. Nobody is perfect, but we are getting better day by day thx Bernhard
        Hide
        Bernhard Messer added a comment -

        Created an attachment (id=12382)
        [PATCH} modified test case to run with FieldInfos patch.

        Show
        Bernhard Messer added a comment - Created an attachment (id=12382) [PATCH} modified test case to run with FieldInfos patch.
        Hide
        Bernhard Messer added a comment -

        Created an attachment (id=12381)
        [PATCH} modified test case to run with FieldInfos patch.

        Show
        Bernhard Messer added a comment - Created an attachment (id=12381) [PATCH} modified test case to run with FieldInfos patch.
        Hide
        Bernhard Messer added a comment -

        Created an attachment (id=12380)
        [PATCH} modified test case to run with FieldInfos patch.

        Show
        Bernhard Messer added a comment - Created an attachment (id=12380) [PATCH} modified test case to run with FieldInfos patch.
        Hide
        Bernhard Messer added a comment -

        Created an attachment (id=12379)
        [PATCH} updated version of FieldInfos class to avoid an empty field in index.

        Show
        Bernhard Messer added a comment - Created an attachment (id=12379) [PATCH} updated version of FieldInfos class to avoid an empty field in index.
        Hide
        Eric Isakson added a comment -

        The culprit is here in org.apache.lucene.index.FieldInfos

        FieldInfos()

        { add("", false); }

        I don't understand the code well enough to see why this is required, but it
        definitely causes failures if you remove it.

        Show
        Eric Isakson added a comment - The culprit is here in org.apache.lucene.index.FieldInfos FieldInfos() { add("", false); } I don't understand the code well enough to see why this is required, but it definitely causes failures if you remove it.

          People

          • Assignee:
            Lucene Developers
            Reporter:
            Mark Harwood
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development