Class FacetRefinement (2.0.0)

public final class FacetRefinement

A 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);
 

Inheritance

java.lang.Object > FacetRefinement

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
NameDescription
tokenString

A token string returned by FacetResultValue#getRefinementToken or FacetRefinement#toTokenString.

Returns
TypeDescription
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
NameDescription
nameString

the name of the facet.

rangeFacetRange

the range of the numeric facet.

Returns
TypeDescription
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
NameDescription
nameString

the name of the facet.

valueString

the value of the facet (both numeric and atom).

Returns
TypeDescription
FacetRefinement

an instance of FacetRefinement.

Methods

getName()

public String getName()

Returns the name of the facet.

Returns
TypeDescription
String

getRange()

public FacetRange getRange()

Returns the range for numeric facets or null if there is no range.

Returns
TypeDescription
FacetRange

getValue()

public String getValue()

Returns the value of the facet or null if there is no value.

Returns
TypeDescription
String

toString()

public String toString()
Returns
TypeDescription
String
Overrides

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
TypeDescription
String

A token string safe to be used in HTML for this facet refinement.