Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Neo4j Community
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.neo4j.graphdb.index
Interface IndexHits<T>

Type Parameters:
  `T` - the type of items in the Iterator.

All Superinterfaces:
  Iterable<T>, Iterator<T>

    public interface IndexHits<T>

extends Iterator<T>, Iterable<T>

An `Iterator` with additional `size()` and `close()` methods on it, used for iterating over index query results. It is first and foremost an `Iterator`, but also an `Iterable` JUST so that it can be used in a for-each loop. The `iterator()` method always returns `this`. The size is calculated before-hand so that calling it is always fast. When you're done with the result and haven't reached the end of the iteration `close()` must be called. Results which are looped through entirely closes automatically. Typical use:

     IndexHits hits = index.get( "key", "value" );
     try
     {
         for ( Node node : hits )
         {
             // do something with the hit
         }
     }
     finally
     {
         hits.close();
     }

Method Summary
`void` | `close()` Closes the underlying search result.
`float` | `currentScore()` Returns the score of the most recently fetched item from this iterator (from `Iterator.next()`).
`T` | `getSingle()` Returns the first and only item from the result iterator, or `null` if there was none.
`int` | `size()` Returns the size of this iterable, in most scenarios this value is accurate while in some scenarios near-accurate.

Methods inherited from interface java.util.Iterator
`hasNext, next, remove`

Methods inherited from interface java.lang.Iterable
`iterator`

Method Detail

### size

    int size()

  Returns the size of this iterable, in most scenarios this value is accurate while in some scenarios near-accurate. There's no cost in calling this method. It's considered near-accurate if this `IndexHits` object has been returned when inside a `Transaction` which has index modifications, of a certain nature. Also entities (`Node`s/`Relationship`s) which have been deleted from the graph, but are still in the index will also affect the accuracy of the returned size.

  Returns:
    the near-accurate size if this iterable.

### close

    void close()

  Closes the underlying search result. This method should be called whenever you've got what you wanted from the result and won't use it anymore. It's necessary to call it so that underlying indexes can dispose of allocated resources for this search result. You can however skip to call this method if you loop through the whole result, then close() will be called automatically. Even if you loop through the entire result and then call this method it will silently ignore any consequtive call (for convenience).

### getSingle

    T getSingle()

  Returns the first and only item from the result iterator, or `null` if there was none. If there were more than one item in the result a `NoSuchElementException` will be thrown. This method must be called first in the iteration and will grab the first item from the iteration, so the result is considered broken after this call.

  Returns:
    the first and only item, or `null` if none.

### currentScore

    float currentScore()

  Returns the score of the most recently fetched item from this iterator (from `Iterator.next()`). The range of the returned values is up to the `Index` implementation to dictate.

  Returns:
    the score of the most recently fetched item from this iterator.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Neo4j Community
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2011 The Neo4j Graph Database Project. All Rights Reserved.