public class Search
extends java.lang.Object
Usage Example:
List<Bird> birds = db.search("views101/animals")
.limit(10)
.includeDocs(true)
.query("class:bird", Bird.class);
// groups
Map<String,List<Bird>> birdGroups = db.search("views101/animals")
.limit(10)
.includeDocs(true)
.queryGroups("class:bird", Bird.class);
for ( Entry<String, List<Bird>> group : birdGroups.entrySet()) {
System.out.println("Group Name : " + group.getKey());
for ( Bird b : group.getValue() ) {
System.out.println("\t" + b);
}
}
// search results object
SearchResult<Bird> result = db.search("views101/animals")
.querySearchResult("class:bird", Bird.class);
// pagination
SearchResult<Bird> nextPage = db.search("views101/animals")
.bookmark(result.bookmark)
.querySearchResult("class:bird", Bird.class);
Database.search(String)
,
SearchResult
Modifier and Type | Method and Description |
---|---|
Search |
bookmark(java.lang.String bookmark)
Control which page of results to get.
|
Search |
counts(java.lang.String[] countsfields)
Array of fieldNames for which counts should be produced
|
Search |
drillDown(java.lang.String fieldName,
java.lang.String fieldValue) |
Search |
groupField(java.lang.String fieldName,
boolean isNumber)
Group results by the specified field.
|
Search |
groupLimit(int limit)
Maximum group count when groupField is set
|
Search |
groupSort(java.lang.String groupsortJson)
the sort order of the groups when groupField is set
|
Search |
includeDocs(java.lang.Boolean includeDocs) |
Search |
limit(java.lang.Integer limit) |
<T> java.util.List<T> |
query(java.lang.String query,
java.lang.Class<T> classOfT)
Queries a Search Index and returns ungrouped results.
|
java.io.InputStream |
queryForStream(java.lang.String query)
Performs a Cloudant Search and returns the result as an
InputStream |
<T> java.util.Map<java.lang.String,java.util.List<T>> |
queryGroups(java.lang.String query,
java.lang.Class<T> classOfT)
Queries a Search Index and returns grouped results in a map where key
of the map is the groupName.
|
<T> SearchResult<T> |
querySearchResult(java.lang.String query,
java.lang.Class<T> classOfT)
Performs a Cloudant Search and returns the result as an
SearchResult |
Search |
ranges(java.lang.String rangesJson)
Ranges for faceted searches
|
Search |
sort(java.lang.String sortJson)
Specify the sort order for the result.
|
Search |
stale(boolean stale) |
public java.io.InputStream queryForStream(java.lang.String query)
InputStream
query
- the Lucene query to be passed to the Search index
The stream should be properly closed after usage, as to avoid connection leaks.
InputStream
.public <T> java.util.List<T> query(java.lang.String query, java.lang.Class<T> classOfT)
T
- Object type Tquery
- the Lucene query to be passed to the Search indexclassOfT
- The class of type TList<T>
public <T> java.util.Map<java.lang.String,java.util.List<T>> queryGroups(java.lang.String query, java.lang.Class<T> classOfT)
T
- Object type Tquery
- the Lucene query to be passed to the Search indexclassOfT
- The class of type TMap<String,T>
public <T> SearchResult<T> querySearchResult(java.lang.String query, java.lang.Class<T> classOfT)
SearchResult
T
- Object type T, an instance into which the rows[].doc/group[].rows[].doc
attribute of the Search result response should be deserialized into. Same
goes for the rows[].fields/group[].rows[].fields attributequery
- the Lucene query to be passed to the Search indexclassOfT
- The class of type T.public Search limit(java.lang.Integer limit)
limit
- limit the number of documents in the resultpublic Search bookmark(java.lang.String bookmark)
bookmark
- see the next page of results after this bookmark resultpublic Search sort(java.lang.String sortJson)
sortJson
- JSON string specifying the sort orderpublic Search groupField(java.lang.String fieldName, boolean isNumber)
fieldName
- by which to group resultsisNumber
- whether field isNumeric.public Search groupLimit(int limit)
limit
- the maximum group countpublic Search groupSort(java.lang.String groupsortJson)
groupsortJson
- JSON string specifying the group sortpublic Search ranges(java.lang.String rangesJson)
rangesJson
- JSON string specifying the rangespublic Search counts(java.lang.String[] countsfields)
countsfields
- array of the field namespublic Search drillDown(java.lang.String fieldName, java.lang.String fieldValue)
fieldName
- the name of the fieldfieldValue
- the value of the fieldpublic Search stale(boolean stale)
stale
- Accept values: okpublic Search includeDocs(java.lang.Boolean includeDocs)
includeDocs
- whether to include the document in the result