LuceneIndexService (Neo4j Apoc 1.1 API)
Keywords: org.neo4j.index.lucene.LuceneIndexService class

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

## org.neo4j.index.lucene
Class LuceneIndexService

    java.lang.Object
      org.neo4j.index.impl.GenericIndexService
          org.neo4j.index.lucene.LuceneIndexService

All Implemented Interfaces:
  IndexService

Direct Known Subclasses:
  LuceneFulltextIndexService

    public class LuceneIndexService

extends org.neo4j.index.impl.GenericIndexService

An implementation of `IndexService` which uses Lucene as backend. Additional features to `IndexService` is:

- `enableCache(String, int)` will enable a LRU cache for the specific key and will boost performance in performance-critical areas.
- `getNodes(String, Object, Sort)` where you can pass in a `Sort` option to control in which order Lucene returns the results
- `setLazySearchResultThreshold(int)` will control the threshold for when a search result is considered big enough to be returned as a lazy iteration, making `getNodes(String, Object)` return very fast, but skips caching

See more information at http://wiki.neo4j.org/content/Indexing_with_IndexService

Field Summary
`static int` | `DEFAULT_LAZY_SEARCH_RESULT_THRESHOLD` The default value for `getLazySearchResultThreshold()`
`protected static String` | `DIR_NAME`
`protected static String` | `DOC_ID_KEY`
`protected static String` | `DOC_INDEX_KEY`

Constructor Summary
`LuceneIndexService(GraphDatabaseService graphDb)`

Method Summary
`void` | `enableCache(String key, int maxNumberOfCachedEntries)` Enables an LRU cache for a specific index (specified by `key`) so that the `maxNumberOfCachedEntries` number of results found with `getNodes(String, Object)` are cached for faster consecutive lookups.
`protected org.apache.lucene.search.Query` | `formQuery(String key, Object value, Object matching)`
`protected Class<? extends LuceneDataSource>` | `getDataSourceClass()`
`protected String` | `getDirName()`
`Integer` | `getEnabledCacheSize(String key)` Returns the enabled LRU cache size for `key`.
`int` | `getLazySearchResultThreshold()` Returns the threshold for when a result is considered big enough to skip cache and be returned as a fully lazy iterator so that `getNodes(String, Object)` will return very fast and all the reading and fetching of nodes is done lazily before each step in the iteration of the returned result.
`IndexHits<Node>` | `getNodes(String key, Object value)` Returns all nodes indexed with `key` and `value`.
`protected IndexHits<Node>` | `getNodes(String key, Object value, Object matching, org.apache.lucene.search.Sort sortingOrNull)` Just like `getNodes(String, Object)`, but with sorted result.
`IndexHits<Node>` | `getNodes(String key, Object value, org.apache.lucene.search.Sort sortingOrNull)` Returns hits from the index (see `getNodes(String, Object)`).
`IndexHits<Node>` | `getNodesExactMatch(String key, Object value)` A method for calling `getNodes(String, Object)` using exact matching.
`Node` | `getSingleNode(String key, Object value)` Returns a single node indexed with associated with `key` and `value`.
`protected Node` | `getSingleNode(String key, Object value, Object matching)`
`Node` | `getSingleNodeExactMatch(String key, Object value)` A method for calling `getSingleNode(String, Object)` using exact matching.
`protected byte[]` | `getXaResourceId()`
`void` | `index(Node node, String key, Object value)` Index `node` with `key` and `value`.
`protected void` | `indexThisTx(Node node, String key, Object value)`
`protected Iterator<Node>` | `instantiateIdToNodeIterator(Iterator<Long> ids)`
`void` | `removeIndex(Node node, String key)` Dissociates a node from all indexed values for the given `key`.
`void` | `removeIndex(String key)` Dissociates all key-value pairs which `key` is part of, i.e.
`protected void` | `removeIndexThisTx(Node node, String key, Object value)`
`void` | `setLazySearchResultThreshold(int numberOfHitsBeforeLazyLoading)` Sets the threshold for when a result is considered big enough to skip cache and be returned as a fully lazy iterator so that `getNodes(String, Object)` will return very fast and all the reading and fetching of nodes is done lazily before each step in the iteration of the returned result.
`void` | `shutdown()` Shuts down the index service.

Methods inherited from class org.neo4j.index.impl.GenericIndexService
`beginTx, getGraphDb, removeIndex`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_LAZY_SEARCH_RESULT_THRESHOLD

    public static final int DEFAULT_LAZY_SEARCH_RESULT_THRESHOLD

  The default value for `getLazySearchResultThreshold()`

  See Also:
    Constant Field Values

### DOC_ID_KEY

    protected static final String DOC_ID_KEY

See Also:
  Constant Field Values

### DOC_INDEX_KEY

    protected static final String DOC_INDEX_KEY

See Also:
  Constant Field Values

### DIR_NAME

    protected static final String DIR_NAME

See Also:
  Constant Field Values

Constructor Detail

### LuceneIndexService

    public LuceneIndexService(GraphDatabaseService graphDb)

Parameters:
  `graphDb` - the `GraphDatabaseService` to use.

Method Detail

### getDataSourceClass

    protected Class<? extends LuceneDataSource> getDataSourceClass()

### getDirName

    protected String getDirName()

### getXaResourceId

    protected byte[] getXaResourceId()

### enableCache

    public void enableCache(String key,
                            int maxNumberOfCachedEntries)

  Enables an LRU cache for a specific index (specified by `key`) so that the `maxNumberOfCachedEntries` number of results found with `getNodes(String, Object)` are cached for faster consecutive lookups. It's preferred to enable cache at construction time.

  Parameters:
    `key` - the index to enable cache for.
    `maxNumberOfCachedEntries` - the max size of the cache before old ones are flushed from the cache.

### getEnabledCacheSize

    public Integer getEnabledCacheSize(String key)

  Returns the enabled LRU cache size for `key`. Cache is enabled using `enableCache(String, int)`. If cache hasn't been enabled for `key` then `null` is returned.

  Parameters:
    `key` - the key to get the enabled cache size for.
  Returns:
    the max cache size for `key` or `null` if not enabled for that key.

### setLazySearchResultThreshold

    public void setLazySearchResultThreshold(int numberOfHitsBeforeLazyLoading)

  Sets the threshold for when a result is considered big enough to skip cache and be returned as a fully lazy iterator so that `getNodes(String, Object)` will return very fast and all the reading and fetching of nodes is done lazily before each step in the iteration of the returned result. The default value is `DEFAULT_LAZY_SEARCH_RESULT_THRESHOLD`.

  Parameters:
    `numberOfHitsBeforeLazyLoading` - the threshold where results which are bigger than that threshold becomes lazy.

### getLazySearchResultThreshold

    public int getLazySearchResultThreshold()

  Returns the threshold for when a result is considered big enough to skip cache and be returned as a fully lazy iterator so that `getNodes(String, Object)` will return very fast and all the reading and fetching of nodes is done lazily before each step in the iteration of the returned result. The default value is `DEFAULT_LAZY_SEARCH_RESULT_THRESHOLD`.

  Returns:
    the threshold for when a result is considered big enough to be returned as a lazy iteration.

### index

    public void index(Node node,
                      String key,
                      Object value)

  Index `node` with `key` and `value`. A node can be associated with any number of key-value pairs.

  Note about updating an index: If you've indexed a value from a property on a `Node` and that value gets updated, you'll have to remove the old value in addition to indexing the new value, else both values (the new and the old) will be indexed for that node.

  When deleting a `Node`, application should remove the index entries for the node as well, to keep the index consistent with the node space.

  Note that this implementation will cast objects given as the value to `String`.

  Specified by:
    `index` in interface `IndexService`
  Overrides:
    `index` in class `org.neo4j.index.impl.GenericIndexService`
  Parameters:
    `node` - node to index
    `key` - the key in the key-value pair to associate with `node`.
    `value` - the value in the key-value pair to associate with `node`.

### indexThisTx

    protected void indexThisTx(Node node,
                               String key,
                               Object value)

  Specified by:
    `indexThisTx` in class `org.neo4j.index.impl.GenericIndexService`

### getNodes

    public IndexHits<Node> getNodes(String key,
                                    Object value)

  Returns all nodes indexed with `key` and `value`.

  Note that this implementation will cast objects given as the value to `String`.

  Parameters:
    `key` - the key for index
    `value` - the value for index
  Returns:
    nodes that have been indexed with key and value

### getNodes

    public IndexHits<Node> getNodes(String key,
                                    Object value,
                                    org.apache.lucene.search.Sort sortingOrNull)

  Returns hits from the index (see `getNodes(String, Object)`). The result is sorted using `sortingOrNull`.

  Parameters:
    `key` - the index to search in.
    `value` - the value to match hits for.
    `sortingOrNull` - how the result should be sorted.
  Returns:
    the (sorted) results from this index lookup.

### getNodesExactMatch

    public IndexHits<Node> getNodesExactMatch(String key,
                                              Object value)

  A method for calling `getNodes(String, Object)` using exact matching. For this class it's equivalent to calling `getNodes(String, Object)`, but for subclasses, such as `LuceneFulltextIndexService` it is useful for it to be able to do queries with exact matching, even though it's a fulltext index.

  Parameters:
    `key` - the index to search in.
    `value` - the value to match hits for.
  Returns:
    nodes that have been indexed with key and value

### getNodes

    protected IndexHits<Node> getNodes(String key,
                                       Object value,
                                       Object matching,
                                       org.apache.lucene.search.Sort sortingOrNull)

  Just like `getNodes(String, Object)`, but with sorted result.

  Parameters:
    `key` - the index to query.
    `value` - the value to query for.
    `sortingOrNull` - lucene sorting behaviour for the result. Ignored if `null`.
  Returns:
    nodes that has been indexed with key and value, optionally sorted with `sortingOrNull`.

### instantiateIdToNodeIterator

    protected Iterator<Node> instantiateIdToNodeIterator(Iterator<Long> ids)

### formQuery

    protected org.apache.lucene.search.Query formQuery(String key,
                                                       Object value,
                                                       Object matching)

  Parameters:
    `key` - the key
    `value` - the value
    `matching` - an object describing what kind of matching to do. The type this object is is solely up to the implementation.
  Returns:
    the `Query` formed from key/value.

### getSingleNodeExactMatch

    public Node getSingleNodeExactMatch(String key,
                                        Object value)

  A method for calling `getSingleNode(String, Object)` using exact matching. For this class it's equivalent to calling `getSingleNode(String, Object)`, but for subclasses, such as `LuceneFulltextIndexService` it is useful for it to be able to do queries with exact matching, even though it's a fulltext index.

  Parameters:
    `key` - the index to search in.
    `value` - the value to match hits for.
  Returns:
    the single node for the query, or `null` if no hit found. If more than one hit was found a `RuntimeException` is thrown.

### getSingleNode

    public Node getSingleNode(String key,
                              Object value)

  Description copied from interface: `IndexService`
  Returns a single node indexed with associated with `key` and `value`. If no such node exist `null` is returned. If more then one node is found a runtime exception is thrown.

  Parameters:
    `key` - the key for index
    `value` - the value for index
  Returns:
    node that has been indexed with key and value or `null`

### getSingleNode

    protected Node getSingleNode(String key,
                                 Object value,
                                 Object matching)

### removeIndexThisTx

    protected void removeIndexThisTx(Node node,
                                     String key,
                                     Object value)

  Specified by:
    `removeIndexThisTx` in class `org.neo4j.index.impl.GenericIndexService`

### shutdown

    public void shutdown()

  Description copied from interface: `IndexService`
  Shuts down the index service. After this method has been invoked any following method invocation on this instance is invalid.

  Specified by:
    `shutdown` in interface `IndexService`
  Overrides:
    `shutdown` in class `org.neo4j.index.impl.GenericIndexService`

### removeIndex

    public void removeIndex(Node node,
                            String key)

  Description copied from interface: `IndexService`
  Dissociates a node from all indexed values for the given `key`. If no such association exists this method silently returns. Implementations may choose to not implement this method and should in such a case throw `UnsupportedOperationException`.

  Parameters:
    `node` - the node to dissociate from all indexed values for the given `key`.
    `key` - the key in the key-value pairs to remove.

### removeIndex

    public void removeIndex(String key)

  Description copied from interface: `IndexService`
  Dissociates all key-value pairs which `key` is part of, i.e. clearing the an entire index `key` is cleared. Implementations may choose to not implement this method and should in such a case throw `UnsupportedOperationException`.

  Parameters:
    `key` - the index to clear.

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

Copyright © 2010 Neo4j. All Rights Reserved.