Interface Search
- All Known Implementing Classes:
DefaultDocumentStore.DefaultSearch
public interface Search
Fluent interface for building and executing document search queries in Fluxzero.
A Search instance is typically obtained via Fluxzero.search("collectionName") and can be
configured using a combination of time-based constraints, field constraints, sorting rules, pagination, and content
selection.
The search is only executed when a terminal operation like fetch(...) or stream() is invoked.
Supported operations include:
- Time-based filtering (e.g.
since(Instant),inLast(Duration)) - Content-based filtering (e.g.
match(Object, String...),query(String, String...)) - Sorting and pagination (e.g.
sortByTimestamp(),skip(Integer)) - Aggregation and facets (e.g.
aggregate(String...),facetStats()) - Streaming and fetching results (e.g.
stream(),fetch(int))
Example usage:
List<MyDocument> results = Fluxzero.search("myCollection")
.inLast(Duration.ofDays(30))
.match("searchTerm", "title", "description")
.sortByTimestamp(true)
.fetch(50);
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default number of records to fetch in a single batch during search operations. -
Method Summary
Modifier and TypeMethodDescriptiondefault Map<String, DocumentStats.FieldStats> Returns field statistics for one or more fields.default Searchall(Constraint... constraints) Combines multiple constraints using a logical AND.default Searchany(Constraint... constraints) Combines multiple constraints using a logical OR.default SearchConstrains the search to documents that have any of the given paths.default SearchAdds a lower-bound constraint for a field.default SearchFilters documents with timestamps strictly before the given end time.Filters documents with timestamps before the given time.default SearchbeforeLast(Duration period) Filters out documents older than the given duration.default SearchAdds an upper-bound constraint for a field.default SearchAdds a numeric range constraint.constraint(Constraint... constraints) Adds one or more custom constraints to the search using a logical AND.default Longcount()Returns the number of matching documents.delete()Deletes all matching documents in the current search.Excludes specific fields from the returned documents.Returns facet statistics for the current search.<T> List<T> fetch(int maxSize) Fetches up to the given number of matching documents and deserializes them to the stored type.<T> List<T> Fetches up to the given number of documents and deserializes them to the specified type.default <T> List<T> fetchAll()Fetches all matching documents and deserializes each to its stored type.default <T> List<T> Fetches all matching documents and deserializes them to the specified type.default <T> Optional<T> Fetches the first matching document if available and deserializes it to the stored type.default <T> Optional<T> fetchFirst(Class<T> type) Fetches the first matching document if available and deserializes it as an optional value of the specified type.default <T> TFetches the first matching document if available and deserializes it to the stored type.default <T> TfetchFirstOrNull(Class<T> type) Fetches the first matching document if available and deserializes it to the specified type.fetchHistogram(int resolution, int maxSize) Computes a histogram for the timestamp distribution of matching documents.Groups search results by field(s) and supports aggregations.includeOnly(String... paths) Includes only the specified fields in the returned documents.default SearchFilters documents within the last given duration (e.g., last 7 days).Filters documents within a specified time range.default SearchFilters documents within the given time range.default SearchAdds a full-text lookahead constraint using the specified phrase.default SearchAdds a match constraint, optionally enforcing strict equality.default SearchAdds an equality match constraint for the given value across one or more paths.default SearchmatchFacet(String name, Object value) Matches the value of a named facet.default SearchmatchMetadata(String key, Object value) Matches a metadata key to a value.Moves all matching documents in the current search to the given collection.default Searchnot(Constraint constraint) Negates a constraint using a logical NOT.default SearchAdds a full-text search constraint for the given phrase.default SearchFilters documents with timestamps since the given start time (inclusive).Filters documents with timestamps since the given start time.Skips the first N results.default SearchSorts results by a specific document field.Sorts results by a field, with control over the sort direction.Sorts results by full-text relevance score.default SearchSorts results by timestamp in ascending order.sortByTimestamp(boolean descending) Sorts results by timestamp.default <T> Stream<T> stream()Streams matching values, deserializing each to the stored type.default <T> Stream<T> stream(int fetchSize) Streams matching values, deserializing each to the stored type.default <T> Stream<T> Streams matching values, deserializing each to the specified type.default <T> Stream<T> Streams matching values, deserializing each to the specified type.Streams raw search hits (document + metadata).streamHits(int fetchSize) Streams raw search hits (document + metadata).streamHits(Class<T> type) Streams raw search hits (document + metadata).streamHits(Class<T> type, int fetchSize) Streams raw search hits (document + metadata).
-
Field Details
-
defaultFetchSize
static final int defaultFetchSizeThe default number of records to fetch in a single batch during search operations. Primarily used in streaming and batch-fetching methods to control the size of each data retrieval operation.A higher value increases the data fetch per operation, potentially reducing the number of retrievals but consuming more memory. A lower value minimizes memory usage but may require more network or database calls for large datasets.
- See Also:
-
-
Method Details
-
since
-
since
-
before
-
before
-
beforeLast
-
inLast
-
inPeriod
-
inPeriod
-
lookAhead
-
query
-
match
-
match
-
matchFacet
-
matchMetadata
-
anyExist
-
atLeast
-
below
-
between
-
all
Combines multiple constraints using a logical AND. -
any
Combines multiple constraints using a logical OR. -
not
Negates a constraint using a logical NOT. -
constraint
Adds one or more custom constraints to the search using a logical AND. -
sortByTimestamp
Sorts results by timestamp in ascending order. -
sortByTimestamp
Sorts results by timestamp.- Parameters:
descending- whether to sort in descending order
-
sortByScore
Search sortByScore()Sorts results by full-text relevance score. -
sortBy
-
sortBy
-
exclude
-
includeOnly
-
skip
-
fetch
Fetches up to the given number of matching documents and deserializes them to the stored type. Returns the deserialized values as instances of typeT. -
fetch
-
fetchAll
Fetches all matching documents and deserializes each to its stored type. Returns the deserialized values as instances of typeT. -
fetchAll
-
fetchFirst
Fetches the first matching document if available and deserializes it to the stored type. Returns the deserialized value as an optional instance of typeT. -
fetchFirst
-
fetchFirstOrNull
default <T> T fetchFirstOrNull()Fetches the first matching document if available and deserializes it to the stored type. Returns the deserialized value as an instance of typeT. -
fetchFirstOrNull
Fetches the first matching document if available and deserializes it to the specified type. -
stream
Streams matching values, deserializing each to the stored type. Documents will typically be fetched in batches from the backing store. For thedefault implementation, the fetch size is 10,000. -
stream
Streams matching values, deserializing each to the stored type. Documents will be fetched in batches of sizefetchSizefrom the backing store. -
stream
Streams matching values, deserializing each to the specified type. Documents will typically be fetched in batches from the backing store. For thedefault implementation, the fetch size is 10,000. -
stream
-
streamHits
Streams raw search hits (document + metadata). Documents will typically be fetched in batches from the backing store. For thedefault implementation, the fetch size is 10,000. -
streamHits
Streams raw search hits (document + metadata). Documents will be fetched in batches of sizefetchSizefrom the backing store. For thedefault implementation, the fetch size is 10,000. -
streamHits
Streams raw search hits (document + metadata). Documents will be fetched in batches of sizefetchSizefrom the backing store. For thedefault implementation, the fetch size is 10,000. -
streamHits
Streams raw search hits (document + metadata). Documents will be fetched in batches of sizefetchSizefrom the backing store. For thedefault implementation, the fetch size is 10,000. -
fetchHistogram
Computes a histogram for the timestamp distribution of matching documents. -
groupBy
Groups search results by field(s) and supports aggregations. -
count
Returns the number of matching documents. -
aggregate
Returns field statistics for one or more fields. -
facetStats
List<FacetStats> facetStats()Returns facet statistics for the current search. -
delete
CompletableFuture<Void> delete()Deletes all matching documents in the current search. -
move
Moves all matching documents in the current search to the given collection.- Parameters:
targetCollection- the collection to move to
-