public final class FacetRefinement
extends java.lang.Object
We recommend using refinement token strings instead of this class. We include a refinement
token string with each FacetResultValue
returned by the backend that can be passed to
Query.Builder.addFacetRefinementFromToken(String)
to refine follow-up queries.
We also support manually-specified query refinements by passing an instance of this class to
Query.Builder.addFacetRefinement(FacetRefinement)
.
Example: Request to only return documents that have a number facet named "rating" with a value between one and two:
FacetRefinement lowRating = FacetRefinement.withRange("rating", FacetRange.startEnd(1.0, 2.0)); query.addFacetRefinement(lowRating);
Modifier and Type | Method and Description |
---|---|
static FacetRefinement |
fromTokenString(java.lang.String token)
Converts a token string to a FacetRefinement object.
|
java.lang.String |
getName()
Returns the name of the facet.
|
FacetRange |
getRange()
Returns the range for numeric facets or null if there is no range.
|
java.lang.String |
getValue()
Returns the value of the facet or null if there is no value.
|
java.lang.String |
toString() |
java.lang.String |
toTokenString()
Converts this refinement to a token string safe to be used in HTML.
|
static FacetRefinement |
withRange(java.lang.String name,
FacetRange range)
|
static FacetRefinement |
withValue(java.lang.String name,
java.lang.String value)
|
public static FacetRefinement withValue(java.lang.String name, java.lang.String value)
name
- the name of the facet.value
- the value of the facet (both numeric and atom).FacetRefinement
.java.lang.IllegalArgumentException
- if name
is null or empty or the value
length
is less than 1 or greater than SearchApiLimits#FACET_MAXIMUM_VALUE_LENGTH.public static FacetRefinement withRange(java.lang.String name, FacetRange range)
name
- the name of the facet.range
- the range of the numeric facet.FacetRefinement
.java.lang.IllegalArgumentException
- if name
is null or empty.public java.lang.String getName()
public java.lang.String getValue()
public FacetRange getRange()
public java.lang.String toTokenString()
NOTE: Do not persist token strings. The format may change.
public static FacetRefinement fromTokenString(java.lang.String token)
NOTE: Do not persist token strings. The format may change.
token
- A token string returned by FacetResultValue.getRefinementToken()
or
toTokenString()
.FacetRefinement
object.java.lang.IllegalArgumentException
- if the given token cannot be processed.public java.lang.String toString()
toString
in class java.lang.Object