Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-593

Spellchecker's dictionary iterator misbehaves

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: None
    • Component/s: core/search
    • Labels:
      None
    • Environment:

      Any (mine is Fedora Core 4 - Linux pc983 2.6.16-1.2111_FC4 #1 Sat May 20 19:59:40 EDT 2006 i686 i686 i386 GNU/Linux)

      Description

      In LuceneDictionary, the LuceneIterator.hasNext() method has two issues that makes it misbehave:

      1) If hasNext is called more than once, items are skipped
      2) Much more seriously, when comparing fieldnames it is done with != rather than .equals() with the potential result that nothing is indexed

      1. LuceneDictionary.java.diff
        0.5 kB
        Kåre Fiedler Christiansen
      2. LuceneDictionary.java.diff
        0.4 kB
        Karl Wettin

        Activity

        Hide
        karl.wettin Karl Wettin added a comment -

        > 1) If hasNext is called more than once, items are skipped

        Why do you call this method manually?

        > 2) Much more seriously, when comparing fieldnames it is done with != rather than .equals() with the potential result that nothing is indexed

        True, but also false. The field passed on to the constructor should be internald. And then all is good.

        public LuceneDictionary(IndexReader reader, String field)

        { this.reader = reader; this.field = field; this.field.intern(); }
        Show
        karl.wettin Karl Wettin added a comment - > 1) If hasNext is called more than once, items are skipped Why do you call this method manually? > 2) Much more seriously, when comparing fieldnames it is done with != rather than .equals() with the potential result that nothing is indexed True, but also false. The field passed on to the constructor should be internald. And then all is good. public LuceneDictionary(IndexReader reader, String field) { this.reader = reader; this.field = field; this.field.intern(); }
        Hide
        karl.wettin Karl Wettin added a comment -

        Oups, I ment:

        public LuceneDictionary(IndexReader reader, String field)

        { this.reader = reader; this.field = field.intern(); }
        Show
        karl.wettin Karl Wettin added a comment - Oups, I ment: public LuceneDictionary(IndexReader reader, String field) { this.reader = reader; this.field = field.intern(); }
        Hide
        karl.wettin Karl Wettin added a comment -

        patch for the internaling of field name passed to constructor

        Show
        karl.wettin Karl Wettin added a comment - patch for the internaling of field name passed to constructor
        Hide
        kfc Kåre Fiedler Christiansen added a comment -

        Ad 1)

        • I don't. I just noticed it when looking at the code. However, if the iterator is only supposed to be used internally by the spell-checking code, why is it public at all?
          Ad 2)
        • GREAT! That also provides the workaround until this patch can be applied: simply call the constructor with an interned string.
        Show
        kfc Kåre Fiedler Christiansen added a comment - Ad 1) I don't. I just noticed it when looking at the code. However, if the iterator is only supposed to be used internally by the spell-checking code, why is it public at all? Ad 2) GREAT! That also provides the workaround until this patch can be applied: simply call the constructor with an interned string.
        Hide
        otis Otis Gospodnetic added a comment -

        Kåre & Karl - thanks, good catch, the field is interned in the ctor now.
        If you have a patch for hasNext() problem, please attach it.

        Show
        otis Otis Gospodnetic added a comment - Kåre & Karl - thanks, good catch, the field is interned in the ctor now. If you have a patch for hasNext() problem, please attach it.
        Hide
        kfc Kåre Fiedler Christiansen added a comment -

        Patch to make LuceneDictionery's Iterator conform with the Iterator contract

        Show
        kfc Kåre Fiedler Christiansen added a comment - Patch to make LuceneDictionery's Iterator conform with the Iterator contract
        Hide
        otis Otis Gospodnetic added a comment -

        Patch applied, thanks Kåre.

        Show
        otis Otis Gospodnetic added a comment - Patch applied, thanks Kåre.

          People

          • Assignee:
            Unassigned
            Reporter:
            kfc Kåre Fiedler Christiansen
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development