org.neo4j.index.impl.lucene
Class LuceneIndex<T extends PropertyContainer>

java.lang.Object
  extended by org.neo4j.index.impl.lucene.LuceneIndex<T>
All Implemented Interfaces:
Index<T>, ReadableIndex<T>

public abstract class LuceneIndex<T extends PropertyContainer>
extends Object
implements Index<T>


Method Summary
 void add(T entity, String key, Object value)
          See Index.add(PropertyContainer, String, Object) for more generic documentation.
 void delete()
          Clears the index and deletes the configuration associated with it.
 IndexHits<T> get(String key, Object value)
          Returns exact matches from this index, given the key/value pair.
protected abstract  T getById(long id)
           
 Integer getCacheCapacity(String key)
           
protected abstract  long getEntityId(T entity)
           
 GraphDatabaseService getGraphDatabase()
          Get the graph database that owns this index.
 String getName()
           
 boolean isWriteable()
          A ReadableIndex is possible to support mutating operations as well.
protected abstract  org.neo4j.index.impl.lucene.LuceneCommand newAddCommand(PropertyContainer entity, String key, Object value)
           
protected abstract  org.neo4j.index.impl.lucene.LuceneCommand newRemoveCommand(PropertyContainer entity, String key, Object value)
           
 T putIfAbsent(T entity, String key, Object value)
          Add the entity to this index for the given key/value pair if this particular key/value pair doesn't already exist.
 IndexHits<T> query(Object queryOrQueryObject)
          Returns matches from this index based on the supplied query object, which can be a query string or an implementation-specific query object.
protected  IndexHits<T> query(org.apache.lucene.search.Query query, String keyForDirectLookup, Object valueForDirectLookup, QueryContext additionalParametersOrNull)
           
 IndexHits<T> query(String key, Object queryOrQueryObject)
          Returns matches from this index based on the supplied key and query object, which can be a query string or an implementation-specific query object.
 void remove(T entity)
          Removes an entity from the index and all its key/value pairs which has been previously associated using Index.add(PropertyContainer, String, Object).
 void remove(T entity, String key)
          Removes key/value pairs for entity where key is key from the index.
 void remove(T entity, String key, Object value)
          See Index.remove(PropertyContainer, String, Object) for more generic documentation.
 void setCacheCapacity(String key, int capacity)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.neo4j.graphdb.index.ReadableIndex
getEntityType
 

Method Detail

getGraphDatabase

public GraphDatabaseService getGraphDatabase()
Description copied from interface: ReadableIndex
Get the graph database that owns this index.

Specified by:
getGraphDatabase in interface ReadableIndex<T extends PropertyContainer>
Returns:
the graph database that owns this index.

getName

public String getName()
Specified by:
getName in interface ReadableIndex<T extends PropertyContainer>
Returns:
the name of the index, i.e. the name this index was created with.

add

public void add(T entity,
                String key,
                Object value)
See Index.add(PropertyContainer, String, Object) for more generic documentation. Adds key/value to the entity in this index. Added values are searchable within the transaction, but composite AND queries aren't guaranteed to return added values correctly within that transaction. When the transaction has been committed all such queries are guaranteed to return correct results.

Specified by:
add in interface Index<T extends PropertyContainer>
Parameters:
entity - the entity (i.e Node or Relationship) to associate the key/value pair with.
key - the key in the key/value pair to associate with the entity.
value - the value in the key/value pair to associate with the entity.

putIfAbsent

public T putIfAbsent(T entity,
                     String key,
                     Object value)
Description copied from interface: Index
Add the entity to this index for the given key/value pair if this particular key/value pair doesn't already exist. This ensures that only one entity will be associated with the key/value pair even if multiple transactions are trying to add it at the same time. One of those transactions will win and add it while the others will block, waiting for the winning transaction to finish. If the winning transaction was successful these other transactions will return the associated entity instead of adding it. If it wasn't successful the waiting transactions will begin a new race to add it.

Specified by:
putIfAbsent in interface Index<T extends PropertyContainer>
Parameters:
entity - the entity (i.e Node or Relationship) to associate the key/value pair with.
key - the key in the key/value pair to associate with the entity.
value - the value in the key/value pair to associate with the entity.
Returns:
the previously indexed entity, or null if no entity was indexed before (and the specified entity was added to the index).

remove

public void remove(T entity,
                   String key,
                   Object value)
See Index.remove(PropertyContainer, String, Object) for more generic documentation. Removes key/value to the entity in this index. Removed values are excluded within the transaction, but composite AND queries aren't guaranteed to exclude removed values correctly within that transaction. When the transaction has been committed all such queries are guaranteed to return correct results.

Specified by:
remove in interface Index<T extends PropertyContainer>
Parameters:
entity - the entity (i.e Node or Relationship) to dissociate the key/value pair from.
key - the key in the key/value pair to dissociate from the entity.
value - the value in the key/value pair to dissociate from the entity.

remove

public void remove(T entity,
                   String key)
Description copied from interface: Index
Removes key/value pairs for entity where key is key from the index. Implementations can choose to not implement this method and should in that case throw UnsupportedOperationException.

Specified by:
remove in interface Index<T extends PropertyContainer>
Parameters:
entity - the entity (Node or Relationship) to remove the this index.

remove

public void remove(T entity)
Description copied from interface: Index
Removes an entity from the index and all its key/value pairs which has been previously associated using Index.add(PropertyContainer, String, Object). Implementations can choose to not implement this method and should in that case throw UnsupportedOperationException.

Specified by:
remove in interface Index<T extends PropertyContainer>
Parameters:
entity - the entity (Node or Relationship) to remove the this index.

delete

public void delete()
Description copied from interface: Index
Clears the index and deletes the configuration associated with it. After this it's invalid to call any other method on this index. However if the transaction which the delete operation was called in gets rolled back it again becomes ok to use this index.

Specified by:
delete in interface Index<T extends PropertyContainer>

get

public IndexHits<T> get(String key,
                        Object value)
Description copied from interface: ReadableIndex
Returns exact matches from this index, given the key/value pair. Matches will be for key/value pairs just as they were added by the #add(PropertyContainer, String, Object) method.

Specified by:
get in interface ReadableIndex<T extends PropertyContainer>
Parameters:
key - the key in the key/value pair to match.
value - the value in the key/value pair to match.
Returns:
the result wrapped in an IndexHits object. If the entire result set isn't looped through, IndexHits.close() must be called before disposing of the result.

query

public IndexHits<T> query(String key,
                          Object queryOrQueryObject)
Returns matches from this index based on the supplied key and query object, which can be a query string or an implementation-specific query object. queryOrQueryObject can be a String containing the query in Lucene syntax format, http://lucene.apache.org/java/3_0_2/queryparsersyntax.html. Or it can be a Query object. If can even be a QueryContext object which can contain a query (String or Query) and additional parameters, such as Sort. Because of performance issues, including uncommitted transaction modifications in the result is disabled by default, but can be enabled using QueryContext.tradeCorrectnessForSpeed().

Specified by:
query in interface ReadableIndex<T extends PropertyContainer>
Parameters:
key - the key in this query.
queryOrQueryObject - the query for the key to match.
Returns:
the result wrapped in an IndexHits object. If the entire result set isn't looped through, IndexHits.close() must be called before disposing of the result.

query

public IndexHits<T> query(Object queryOrQueryObject)
Returns matches from this index based on the supplied query object, which can be a query string or an implementation-specific query object.

Specified by:
query in interface ReadableIndex<T extends PropertyContainer>
Parameters:
queryOrQueryObject - the query to match.
Returns:
the result wrapped in an IndexHits object. If the entire result set isn't looped through, IndexHits.close() must be called before disposing of the result.
See Also:
query(String, Object)

query

protected IndexHits<T> query(org.apache.lucene.search.Query query,
                             String keyForDirectLookup,
                             Object valueForDirectLookup,
                             QueryContext additionalParametersOrNull)

isWriteable

public boolean isWriteable()
Description copied from interface: ReadableIndex
A ReadableIndex is possible to support mutating operations as well. This method returns true iff such operations are supported by the implementation.

Specified by:
isWriteable in interface ReadableIndex<T extends PropertyContainer>
Returns:
true iff mutating operations are supported.

setCacheCapacity

public void setCacheCapacity(String key,
                             int capacity)

getCacheCapacity

public Integer getCacheCapacity(String key)

getById

protected abstract T getById(long id)

getEntityId

protected abstract long getEntityId(T entity)

newAddCommand

protected abstract org.neo4j.index.impl.lucene.LuceneCommand newAddCommand(PropertyContainer entity,
                                                                           String key,
                                                                           Object value)

newRemoveCommand

protected abstract org.neo4j.index.impl.lucene.LuceneCommand newRemoveCommand(PropertyContainer entity,
                                                                              String key,
                                                                              Object value)


Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.