Class FacetConstraint

java.lang.Object
io.fluxcapacitor.common.api.search.constraints.FacetConstraint
All Implemented Interfaces:
Constraint

public class FacetConstraint extends Object implements Constraint
A constraint that matches documents containing a specific FacetEntry.

Facets are indexed fields marked using @Facet annotations. Using this constraint allows for efficient lookups because the facet matching is typically executed directly by the backing search store. This can make it significantly faster than using a general MatchConstraint for the same purpose.

Example usage to match a single facet:


 Constraint facetMatch = FacetConstraint.matchFacet("country", "Netherlands");
 
See Also:
  • Constructor Details

    • FacetConstraint

      public FacetConstraint()
  • Method Details

    • matchFacet

      public static Constraint matchFacet(String name, Object value)
      Factory method to create a constraint that matches documents with the given facet name and value.

      If the value is a Collection, multiple facets are matched using an AnyConstraint over the individual values. If the value is a HasId, its identifier is used for matching.

      Parameters:
      name - the facet field name (normalized internally)
      value - the expected facet value
      Returns:
      a FacetConstraint or a composite constraint if value is a collection, or NoOpConstraint if the name is null or the value is null/empty.
    • matchFacet

      public static Constraint matchFacet(FacetEntry facet)
      Factory method to create a constraint that matches a single FacetEntry.
      Parameters:
      facet - the facet to match
      Returns:
      a FacetConstraint for the provided facet or a NoOpConstraint if the facet is null
    • matches

      public boolean matches(Document document)
      Description copied from interface: Constraint
      Evaluates whether this constraint applies to the given document.
      Specified by:
      matches in interface Constraint
      Parameters:
      document - the document to test
      Returns:
      true if the constraint matches the document
    • hasPathConstraint

      public boolean hasPathConstraint()
      This constraint does not apply to specific document paths, so this always returns false.
      Specified by:
      hasPathConstraint in interface Constraint
      Returns:
      true if path-based filtering is involved