Session: Querying: How to Perform Queries Lazily
In some situations, query execution must be delayed. To cover such a scenario, lazily
and many other query extensions have been introduced.
Lazily
Lazy<List<T>> lazily();
Lazy<List<T>> lazily(Consumer<List<T>> onEval);
Parameters | ||
---|---|---|
onEval | Consumer<List<TResult>> | An action that will be performed on the query results. |
Return Value | |
---|---|
Lazy<List<TResult>> | Lazy query initializer returning query results. |
Example
Lazy<List<Employee>> employeesLazy = session
.query(Employee.class)
.whereEquals("FirstName", "Robert")
.lazily();
List<Employee> employees = employeesLazy.getValue(); // query will be executed here
Counts
Lazy<Integer> countLazily();
Return Value | |
---|---|
Lazy |
Lazy query initializer returning a count of matched documents. |
Example
Lazy<Integer> countLazy = session
.query(Employee.class)
.whereEquals("FirstName", "Robert")
.countLazily();
Integer count = countLazy.getValue(); // query will be executed here
Suggestions
Lazy<Map<String, SuggestionResult>> executeLazy();
Lazy<Map<String, SuggestionResult>> executeLazy(Consumer<Map<String, SuggestionResult>> onEval);
Return Value | |
---|---|
Lazy<Map<String, SuggestionResult>> | Lazy query initializer containing a map with suggestions for matching executed query |
Example
Lazy<Map<String, SuggestionResult>> suggestLazy = session
.query(Employee.class, Query.index("Employees_ByFullName"))
.suggestUsing(builder -> builder.byField("FullName", "johne"))
.executeLazy();
Map<String, SuggestionResult> suggest = suggestLazy.getValue(); // query will be executed here
List<String> suggestions = suggest.get("FullName").getSuggestions();
Facets
Lazy<Map<String, FacetResult>> executeLazy();
Lazy<Map<String, FacetResult>> executeLazy(Consumer<Map<String, FacetResult>> onEval);
Return Value | |
---|---|
Lazy<Map<String, FacetResult>> | Lazy query initializer containing a map with facet results matching executed query |
Example
Lazy<Map<String, FacetResult>> facetsLazy = session
.query(Camera.class, Query.index("Camera/Costs"))
.aggregateUsing("facets/CameraFacets")
.executeLazy();
Map<String, FacetResult> facets = facetsLazy.getValue(); // query will be executed here
FacetResult results = facets.get("manufacturer");