If `advanceExact(docid)` returns false it means that the field does
not have a value for the given doc, or it could mean that you
attempted to iterate backwards. `advance(docid)` is there to assist
with iterating over values in forward order - it's more efficient than
callig advanceExact multiple times just to find out there are no
values

On Fri, Feb 28, 2020 at 1:42 PM Sergio Bilello
<lapostadiser...@gmail.com> wrote:
>
> Given a docId if I call advanceExact(docId) and if this will return true.
>
> Can I call
> https://github.com/apache/lucene-solr/blob/releases/lucene-solr/8.4.1/lucene/core/src/java/org/apache/lucene/index/NumericDocValues.java#L32-L35
> to retrieve the value?
>
> If YES I am fine with it if NO what should I do to retrieve the value for the 
> docId specified in case it exists?
> I didn't get the meaning of the comment on top of the method advanceExact.
>
> Separate question:
> What's the purpose to call advance(doc) and eventually get a docId greater 
> than doc?
>
> Thanks,
> Sergio
>
> On 2020/02/28 11:04:45, Alan Woodward <romseyg...@gmail.com> wrote:
> > You’re dealing with cases where the document in question doesn’t have a 
> > value in the iterator.  So `advance(doc)` will return a docId greater than 
> > doc, as it moves to the next doc that does have a value, and 
> > `advanceExact(doc)` returns `false` because you can’t do an exact advance 
> > to a value that doesn’t exist.
> >
> > > On 28 Feb 2020, at 01:05, Sergio Bilello <lapostadiser...@gmail.com> 
> > > wrote:
> > >
> > > I changed the code to return a default value instead of an exception. In 
> > > case the doc will not be found.
> > > I would like really to understand better why we have such comment in that 
> > > iterator
> > >
> > > * Returns the numeric value for the current document ID.  * It is illegal
> > >> to call this method after {@link #advanceExact(int)}   * returned {@code
> > >> false}.   * @return numeric value*
> > >
> > > and if I use advance method instead of advanceExact  the subsequent call 
> > > to retrieve the value would be legit?
> > >
> > > Thanks
> > > Sergio
> > > On 2020/02/27 22:27:09, Sergio <lapostadiser...@gmail.com> wrote:
> > >> Hi guys!
> > >>
> > >> I am a newbie and I am trying to upgrade from Lucene 6.2.1 to 8.4.1
> > >> The previous code was leveraging this
> > >> https://github.com/apache/lucene-solr/blob/releases/lucene-solr/6.2.1/lucene/core/src/java/org/apache/lucene/index/NumericDocValues.java#L34
> > >>
> > >> now
> > >>
> > >> https://github.com/apache/lucene-solr/blob/releases/lucene-solr/8.4.1/lucene/core/src/java/org/apache/lucene/index/NumericDocValues.java#L32-L35
> > >>
> > >> Previously there was no need to deal with the iterator and I found in the
> > >> code a comment regarding
> > >>
> > >>
> > >>
> > >> ** Returns the numeric value for the current document ID.  * It is 
> > >> illegal
> > >> to call this method after {@link #advanceExact(int)}   * returned {@code
> > >> false}.   * @return numeric value*
> > >> If the below snippet is not correct how should I proceed?
> > >>
> > >> public static float
> > >> getFloatValueFromNumericDocValuesAndDocId(NumericDocValues
> > >> numericDocValues, int docId) throws IOException {
> > >>  if (numericDocValues.advanceExact(docId)) {
> > >>    return Float.intBitsToFloat((int)numericDocValues.longValue());
> > >>  } else {
> > >>    throw new RuntimeException("It has not been possible to
> > >> advanceExact for " + docId) ;
> > >>  }
> > >> }
> > >>
> > >> public static int
> > >> getIntValueFromNumericDocValuesAndDocId(NumericDocValues
> > >> numericDocValues, int docId) throws IOException {
> > >>  if (numericDocValues.advanceExact(docId)) {
> > >>    return (int) numericDocValues.longValue();
> > >>  } else {
> > >>    throw new RuntimeException("It has not been possible to
> > >> advanceExact for " + docId) ;
> > >>  }
> > >> }
> > >>
> > >> public static long
> > >> getLongValueFromNumericDocValuesAndDocId(NumericDocValues
> > >> numericDocValues, int docId) throws IOException {
> > >>  if (numericDocValues.advanceExact(docId)) {
> > >>    return numericDocValues.longValue();
> > >>  } else {
> > >>    throw new RuntimeException("It has not been possible to
> > >> advanceExact for " + docId) ;
> > >>  }
> > >> }
> > >>
> > >> public static BytesRef
> > >> getBytesRefValueFromSortedDocValuesAndDocId(SortedDocValues
> > >> numericDocValues, int docId) throws IOException {
> > >>  if (numericDocValues.advanceExact(docId)) {
> > >>    return numericDocValues.binaryValue();
> > >>  } else {
> > >>    throw new RuntimeException("It has not been possible to
> > >> advanceExact for " + docId) ;
> > >>  }
> > >> }
> > >>
> > >>
> > >>
> > >>
> > >> Thanks to everyone!
> > >>
> > >> Sergio
> > >>
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
> > > For additional commands, e-mail: dev-h...@lucene.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
> > For additional commands, e-mail: dev-h...@lucene.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
> For additional commands, e-mail: dev-h...@lucene.apache.org
>

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

Reply via email to