public class Search extends Object
List results = repository.search()
.filter("field", "value*")
.fields("fieldA", "fieldB")
.limit(10)
.page(2)
.list();
| Constructor and Description |
|---|
Search(Repository<? extends Base> repository) |
| Modifier and Type | Method and Description |
|---|---|
long |
count()
Count the number of results.
|
long |
count(String id)
Count the number of results of a specific identifier.
|
Search |
debug()
Print queries and parameters to stdout.
|
Search |
fields(FieldList fields)
Fields to fetch on results.
|
Search |
fields(QueryField... fields)
Fields to fetch on results.
|
Search |
fields(String... fields)
Fields to fetch on results.
|
Search |
filter(Filter filter)
Adds a
filter for results. |
Search |
filter(String property,
String value)
Filter results by field values.
|
Search |
ids(Collection<Long> ids)
Filter results by ids.
|
Search |
ids(Long... ids)
Filter results by ids.
|
Search |
limit(int limit)
Limit results to a specific count.
|
<T extends Base> |
list()
Get a
list of results. |
Search |
locale(Locale locale)
Locale to use for queries. |
Search |
orderBy(String field)
Sort results by a specific field in ascending order.
|
Search |
orderBy(String field,
SearchParameter.SortOrder dir)
Sort results by a specific field and given order.
|
Search |
page(int page)
Page number to return, starts with 1.
|
Search |
params(SearchParameter params)
Replaces the underlying
SearchParameter object. |
Search |
query(String query)
Query indexed fields.
|
Search |
returns(String... fields)
Fields to return.
|
<T extends Base> |
set()
Get a
set of results. |
<T extends Base> |
single()
Get a single result.
|
Search |
start(int start)
Start results at a specific position.
|
<T extends Base> |
stream()
Get a
stream of results. |
Number |
sum(String field)
Adds all found field values.
|
Integer |
toInt()
Get a
Integer value. |
Long |
toLong()
Get a
Long value. |
Search |
uuids(Collection<String> uuids)
Filter results by uuids.
|
Search |
uuids(String... uuids)
Filter results by uuids.
|
public Search(Repository<? extends Base> repository)
public long count()
public long count(String id)
id - The identifier to usepublic Number sum(String field)
field - The field to sum uppublic <T extends Base> java.util.stream.Stream<T> stream()
stream of results.stream of resultsClassCastException - when the SearchParameter.returns value was not matching the class to returnpublic <T extends Base> List<T> list()
list of results.list of resultsClassCastException - when the SearchParameter.returns value was not matching the class to returnpublic <T extends Base> Set<T> set()
set of results.set of resultsClassCastException - when the SearchParameter.returns value was not matching the class to returnpublic <T extends Base> T single()
ClassCastException - when the SearchParameter.returns value was not matching the class to returnpublic Long toLong()
Long value. Tries to convert the result to Long and throws an
UnsupportedOperationException if that fails.Long valuepublic Integer toInt()
Integer value. Tries to convert the result to Integer and
throws an UnsupportedOperationException if that fails.Integer valuepublic Search debug()
public Search fields(String... fields)
fields - Fields to fetchpublic Search fields(QueryField... fields)
fields - QueryField's to fetchpublic Search fields(FieldList fields)
fields - FieldList containing all fields to fetchpublic Search filter(String property, String value)
Filter.Equals filter.property - Field to apply the filter onvalue - Value to look forpublic Search filter(Filter filter)
filter for results.filter - Filter to addpublic Search params(SearchParameter params)
SearchParameter object.
This should be called first, to prevent overriding.params - SearchParameter objectpublic Search locale(Locale locale)
Locale to use for queries.locale - Locale to usepublic Search query(String query)
filters. But this provides a convenient way to make simple queries.query - The querystring to usepublic Search start(int start)
ordered.start - The position to start from.public Search ids(Long... ids)
ids - Ids to include in resultspublic Search ids(Collection<Long> ids)
ids - Ids to include in results as setpublic Search uuids(String... uuids)
uuids - UUIDs to include in resultspublic Search uuids(Collection<String> uuids)
uuids - UUIDs to include in results as listpublic Search limit(int limit)
limit - Amount of results to returnpublic Search page(int page)
limit.
If set, there's no start required.page - Page numberpublic Search orderBy(String field)
field - Field, by which results will be sortedpublic Search orderBy(String field, SearchParameter.SortOrder dir)
field - Field, by which results will be sorteddir - Sort direction (ascending or descending)Copyright © 2018. All rights reserved.