FilteredTermEnum.Java - The first term in the enumeration is skipped.
---------------------------------------------------------------------

                 Key: LUCENE-2028
                 URL: https://issues.apache.org/jira/browse/LUCENE-2028
             Project: Lucene - Java
          Issue Type: Bug
          Components: Search
    Affects Versions: 2.4.1
         Environment: JDK 1.6 
            Reporter: Danish Contractor


The Filtered Term Enumeration seems to skip the first term present in the 
enumerator. 
The problem lies in the next() function, which moves does not do anything with 
the first value of currentTerm set by the setEnum() method.

The setEnum() function sets a value to the currentTerm and returns. An 
implementation of WildCardTermEnum, for example calls the next() method where 
the currentTerm is set to null and the enumerator moves to the next value. The 
first term is not read.

In my local workspace, I have modified the two methods - setEnum() and next() 
as follows:

protected void setEnum(TermEnum actualEnum) throws IOException {
        this.actualEnum = actualEnum;
        this.startedReading=false;
        // Find the first term that matches
        Term term = actualEnum.term();
        if (term != null && termCompare(term)) 
            currentTerm = term;
        else next();
    }

/** Increments the enumeration to the next element.  True if one exists. */
    public boolean next() throws IOException {
        if (actualEnum == null) return false; // the actual enumerator is not 
initialized!
        if(currentTerm!=null &&!startedReading) //check if first term read
        {
                startedReading=true;
                return true;
        }
        currentTerm = null;
        while (currentTerm == null) {
            if (endEnum()) return false;
            if (actualEnum.next()) {
                Term term = actualEnum.term();
                if (termCompare(term)) {
                    currentTerm = term;
                    return true;
                }
            }
            else return false;
        }
        currentTerm = null;
        return false;
    }

I have added a boolean variable called startedReading that is a member of the 
FilteredTermEnum class and is set to false. Once the currentTerm set by setEnum 
is read, I set this value to true and the code continues as before.

I have run a few of my own test cases and it returns the results  I was looking 
for which were missing earlier as they happened to be the first term in the 
enumerator.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-dev-h...@lucene.apache.org

Reply via email to