public final class FacetRefinementA Facet Refinement to filter out search results based on a facet value.
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);
Static Methods
fromTokenString(String token)
public static FacetRefinement fromTokenString(String token)Converts a token string to a FacetRefinement object.
NOTE: Do not persist token strings. The format may change.
| Parameter | |
|---|---|
| Name | Description |
token |
StringA token string returned by FacetResultValue#getRefinementToken or FacetRefinement#toTokenString. |
| Returns | |
|---|---|
| Type | Description |
FacetRefinement |
A FacetRefinement object. |
withRange(String name, FacetRange range)
public static FacetRefinement withRange(String name, FacetRange range)Create a FacetRefinement with the given name and range.
| Parameters | |
|---|---|
| Name | Description |
name |
Stringthe name of the facet. |
range |
FacetRangethe range of the numeric facet. |
| Returns | |
|---|---|
| Type | Description |
FacetRefinement |
an instance of FacetRefinement. |
withValue(String name, String value)
public static FacetRefinement withValue(String name, String value)Create a FacetRefinement with the given name and value.
| Parameters | |
|---|---|
| Name | Description |
name |
Stringthe name of the facet. |
value |
Stringthe value of the facet (both numeric and atom). |
| Returns | |
|---|---|
| Type | Description |
FacetRefinement |
an instance of FacetRefinement. |
Methods
getName()
public String getName()Returns the name of the facet.
| Returns | |
|---|---|
| Type | Description |
String |
|
getRange()
public FacetRange getRange()Returns the range for numeric facets or null if there is no range.
| Returns | |
|---|---|
| Type | Description |
FacetRange |
|
getValue()
public String getValue()Returns the value of the facet or null if there is no value.
| Returns | |
|---|---|
| Type | Description |
String |
|
toString()
public String toString()| Returns | |
|---|---|
| Type | Description |
String |
|
toTokenString()
public String toTokenString()Converts this refinement to a token string safe to be used in HTML.
NOTE: Do not persist token strings. The format may change.
| Returns | |
|---|---|
| Type | Description |
String |
A token string safe to be used in HTML for this facet refinement. |