org.neo4j.graphdb.index

Interface IndexHits<T>

  • Type Parameters:
    T - the type of items in the Iterator.
    All Superinterfaces:
    AutoCloseable, Iterable<T>, Iterator<T>, Resource, ResourceIterable<T>, ResourceIterator<T>


    public interface IndexHits<T>
    extends ResourceIterator<T>, ResourceIterable<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<Node> hits = index.get( "key", "value" );
     try
     {
         for ( Node node : hits )
         {
             // do something with the hit
         }
     }
     finally
     {
         hits.close();
     }
     
     
    • 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 (Nodes/Relationships) 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 consecutive call (for convenience).
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Resource
        Specified by:
        close in interface ResourceIterator<T>
      • 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.

Copyright © 2002–2017 The Neo4j Graph Database Project. All rights reserved.