Class LuceneIndex
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndex
-
- All Implemented Interfaces:
QueryIndex,QueryIndex.AdvancedQueryIndex,QueryIndex.AdvanceFulltextQueryIndex,QueryIndex.FulltextQueryIndex,QueryIndex.NativeQueryIndex
public class LuceneIndex extends java.lang.Object implements QueryIndex.AdvanceFulltextQueryIndex
Used to query old (compatVersion 1) Lucene indexes. Provides a QueryIndex that does lookups against a Lucene-based indexTo define a lucene index on a subtree you have to add an
oak:indexnode. Under it follows the index definition node that:- must be of type
oak:QueryIndexDefinition - must have the
typeproperty set tolucene - must have the
asyncproperty set toasync
Optionally you can add
- what subset of property types to be included in the index via the
includePropertyTypesproperty - a blacklist of property names: what property to be excluded from the index via the
excludePropertyNamesproperty - the
reindexflag which when set totrue, triggers a full content re-index.
{ NodeBuilder index = root.child("oak:index"); index.child("lucene") .setProperty("jcr:primaryType", "oak:QueryIndexDefinition", Type.NAME) .setProperty("type", "lucene") .setProperty("async", "async") .setProperty("reindex", "true"); }- See Also:
QueryIndex
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.jackrabbit.oak.spi.query.QueryIndex
QueryIndex.AdvancedQueryIndex, QueryIndex.AdvanceFulltextQueryIndex, QueryIndex.FulltextQueryIndex, QueryIndex.IndexPlan, QueryIndex.NativeQueryIndex, QueryIndex.NodeAggregator, QueryIndex.OrderEntry
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringNATIVE_QUERY_FUNCTION
-
Constructor Summary
Constructors Constructor Description LuceneIndex(IndexTracker tracker, QueryIndex.NodeAggregator aggregator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetCost(Filter filter, NodeState root)Estimate the worst-case cost to query with the given filter.java.lang.StringgetIndexName()Get the generic index name (normally the index type).doublegetMinimumCost()Returns the minimum cost whichQueryIndex.getCost(Filter, NodeState)would return in the best possible case.QueryIndex.NodeAggregatorgetNodeAggregator()Returns the NodeAggregator responsible for providing the aggregation settings or null if aggregation is not available/desired.java.lang.StringgetPlan(Filter filter, NodeState root)Get the query plan for the given filter.java.lang.StringgetPlanDescription(QueryIndex.IndexPlan plan, NodeState root)Get the query plan description (for logging purposes).java.util.List<QueryIndex.IndexPlan>getPlans(Filter filter, java.util.List<QueryIndex.OrderEntry> sortOrder, NodeState rootState)Return the possible index plans for the given filter and sort order.Cursorquery(Filter filter, NodeState root)Query the index.Cursorquery(QueryIndex.IndexPlan plan, NodeState rootState)Start a query.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.jackrabbit.oak.spi.query.QueryIndex
getIndexName
-
-
-
-
Field Detail
-
NATIVE_QUERY_FUNCTION
public static final java.lang.String NATIVE_QUERY_FUNCTION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LuceneIndex
public LuceneIndex(IndexTracker tracker, QueryIndex.NodeAggregator aggregator)
-
-
Method Detail
-
getMinimumCost
public double getMinimumCost()
Description copied from interface:QueryIndexReturns the minimum cost whichQueryIndex.getCost(Filter, NodeState)would return in the best possible case.The implementation should return a static/cached value because it is called very often.
- Specified by:
getMinimumCostin interfaceQueryIndex- Returns:
- the minimum cost for the index
-
getIndexName
public java.lang.String getIndexName()
Description copied from interface:QueryIndexGet the generic index name (normally the index type).- Specified by:
getIndexNamein interfaceQueryIndex- Returns:
- the index name
-
getPlans
public java.util.List<QueryIndex.IndexPlan> getPlans(Filter filter, java.util.List<QueryIndex.OrderEntry> sortOrder, NodeState rootState)
Description copied from interface:QueryIndex.AdvancedQueryIndexReturn the possible index plans for the given filter and sort order. Please note this method is supposed to run quickly. That means it should usually not read any data from the storage.- Specified by:
getPlansin interfaceQueryIndex.AdvancedQueryIndex- Parameters:
filter- the filtersortOrder- the sort order or null if no sorting is requiredrootState- root state of the current repository snapshot- Returns:
- the list of index plans (null if none)
-
getCost
public double getCost(Filter filter, NodeState root)
Description copied from interface:QueryIndexEstimate the worst-case cost to query with the given filter. The returned cost is a value between 1 (very fast; lookup of a unique node) and the estimated number of entries to traverse, if the cursor would be fully read, and if there could in theory be one network roundtrip or disk read operation per node (this method may return a lower number if the data is known to be fully in memory).The returned value is supposed to be an estimate and doesn't have to be very accurate. Please note this method is called on each index whenever a query is run, so the method should be reasonably fast (not read any data itself, or at least not read too much data).
If an index implementation can not query the data, it has to return
Double.MAX_VALUE.- Specified by:
getCostin interfaceQueryIndex- Parameters:
filter- the filterroot- root state of the current repository snapshot- Returns:
- the estimated cost in number of read nodes
-
getPlan
public java.lang.String getPlan(Filter filter, NodeState root)
Description copied from interface:QueryIndexGet the query plan for the given filter. This method is called when running anEXPLAIN SELECTquery, or for logging purposes. The result should be human readable.- Specified by:
getPlanin interfaceQueryIndex- Parameters:
filter- the filterroot- root state of the current repository snapshot- Returns:
- the query plan
-
getPlanDescription
public java.lang.String getPlanDescription(QueryIndex.IndexPlan plan, NodeState root)
Description copied from interface:QueryIndex.AdvancedQueryIndexGet the query plan description (for logging purposes).The index plan is one of the plans that the index returned in the getPlans call.
- Specified by:
getPlanDescriptionin interfaceQueryIndex.AdvancedQueryIndex- Parameters:
plan- the index planroot- root state of the current repository snapshot- Returns:
- the query plan description
-
query
public Cursor query(Filter filter, NodeState root)
Description copied from interface:QueryIndexQuery the index. The returned cursor is supposed to return as few nodes as possible, but may return more nodes than necessary.An implementation should only filter the result if it can do so easily and efficiently; the query engine will verify the data again (in memory) and check for access rights.
The method is only called if this index is used for the given query and selector, which is only the case if the given index implementation returned the lowest cost for the given filter. If the implementation returned
Double.MAX_VALUEin the getCost method for the given filter, then this method is not called. If it is still called, then it is supposed to throw an exception (as it would be an internal error of the query engine).- Specified by:
queryin interfaceQueryIndex- Parameters:
filter- the filterroot- root state of the current repository snapshot- Returns:
- a cursor to iterate over the result
-
query
public Cursor query(QueryIndex.IndexPlan plan, NodeState rootState)
Description copied from interface:QueryIndex.AdvancedQueryIndexStart a query. The filter and sort order of the index plan is to be used.The index plan is one of the plans that the index returned in the getPlans call.
- Specified by:
queryin interfaceQueryIndex.AdvancedQueryIndex- Parameters:
plan- the index plan to userootState- root state of the current repository snapshot- Returns:
- a cursor to iterate over the result
-
getNodeAggregator
public QueryIndex.NodeAggregator getNodeAggregator()
Description copied from interface:QueryIndex.FulltextQueryIndexReturns the NodeAggregator responsible for providing the aggregation settings or null if aggregation is not available/desired.- Specified by:
getNodeAggregatorin interfaceQueryIndex.FulltextQueryIndex- Returns:
- the node aggregator or null
-
-