public interface Index<K,V>
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.
Modifier and Type | Method and Description |
---|---|
void |
close()
Close this index.
|
void |
delete(K key)
Delete a document from the index by key.
|
void |
deleteAll()
Delete all documents from the index.
|
default java.util.Optional<V> |
get(K key,
QueryOptions opts)
Get a single document from the index.
|
default java.util.Optional<FieldBundle> |
getRaw(K key,
QueryOptions opts)
Get a single raw document from the index.
|
Schema<V> |
getSchema() |
DataSource<V> |
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.
|
Predicate<V> |
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 |
replace(V obj)
Update a document in the index.
|
void close()
void replace(V obj)
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.
obj
- document objectvoid delete(K key)
key
- document keyvoid deleteAll()
DataSource<V> getSource(Predicate<V> p, QueryOptions opts) throws QueryParseException
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).
p
- the predicate to match. Must be a tree containing only AND, OR, or NOT predicates as
internal nodes, and IndexPredicate
s as leaves.opts
- query options not implied by the predicate, such as start and limit.QueryParseException
- if the predicate could not be converted to an indexed data source.default java.util.Optional<V> get(K key, QueryOptions opts)
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.default java.util.Optional<FieldBundle> getRaw(K key, QueryOptions opts)
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.Predicate<V> keyPredicate(K key)
key
- document key.void markReady(boolean ready)
ready
- whether the index is ready