Interface Index<K,V>
- All Known Subinterfaces:
AccountIndex
,ChangeIndex
,GroupIndex
Documents are inserted into the index and are queried by converting special Predicate
instances into index-aware predicates that use the index
search results as a source.
Implementations must be thread-safe and should batch inserts/updates where appropriate.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this index.void
Delete a document from the index by key.void
Delete all documents from the index.void
deleteByValue
(V value) Delete a document from the index by valueget
(K key, QueryOptions opts) Get a single document from the index.An Optional filter that is invoked right after the results are returned from the index, but before any post-filter predicates.default Optional<FieldBundle>
getRaw
(K key, QueryOptions opts) Get a single raw document from the index.Returns the schema version used by this index.getSource
(Predicate<V> p, QueryOptions opts) Convert the given operator predicate into a source searching the index and returning only the documents matching that predicate.void
Insert a document into the index.default boolean
Returns whether the index is enabled.keyPredicate
(K key) Get a predicate that looks up a single document by key.void
markReady
(boolean ready) Mark whether this index is up-to-date and ready to serve reads.void
Update a document in the index.
-
Method Details
-
getSchema
Returns the schema version used by this index. -
close
void close()Close this index. -
insert
Insert a document into the index.Results may not be immediately visible to searchers, but should be visible within a reasonable amount of time.
- Parameters:
obj
- document object
-
replace
Update a document in the index.Semantically equivalent to deleting the document and reinserting it with new field values. A document that does not already exist is created. Results may not be immediately visible to searchers, but should be visible within a reasonable amount of time.
- Parameters:
obj
- document object
-
deleteByValue
Delete a document from the index by value -
delete
Delete a document from the index by key.- Parameters:
key
- document key
-
deleteAll
void deleteAll()Delete all documents from the index. -
getSource
Convert the given operator predicate into a source searching the index and returning only the documents matching that predicate.This method may be called multiple times for variations on the same predicate or multiple predicate subtrees in the course of processing a single query, so it should not have any side effects (e.g. starting a search in the background).
- Parameters:
p
- the predicate to match. Must be a tree containing only AND, OR, or NOT predicates as internal nodes, andIndexPredicate
s as leaves.opts
- query options not implied by the predicate, such as start and limit.- Returns:
- a source of documents matching the predicate, returned in a defined order depending on the type of documents.
- Throws:
QueryParseException
- if the predicate could not be converted to an indexed data source.
-
get
Get a single document from the index.- Parameters:
key
- document key.opts
- query options. Options that do not make sense in the context of a single document, such as start, will be ignored.- Returns:
- a single document if present.
-
getRaw
Get a single raw document from the index.- Parameters:
key
- document key.opts
- query options. Options that do not make sense in the context of a single document, such as start, will be ignored.- Returns:
- an abstraction of a raw index document to retrieve fields from.
-
keyPredicate
Get a predicate that looks up a single document by key.- Parameters:
key
- document key.- Returns:
- a single predicate.
-
markReady
void markReady(boolean ready) Mark whether this index is up-to-date and ready to serve reads.- Parameters:
ready
- whether the index is ready
-
isEnabled
default boolean isEnabled()Returns whether the index is enabled.true
by default, but could be overridden by implementations. -
getIndexFilter
An Optional filter that is invoked right after the results are returned from the index, but before any post-filter predicates.The filter is invoked before any other index predicates. If the filter returns 'true', then other index predicates are evaluated. Otherwise, the result from the index is not returned to the DataSource.
-