Interface SearchFacet

All Superinterfaces:
Bson
All Known Subinterfaces:
DateSearchFacet, NumberSearchFacet, StringSearchFacet

@Evolving @Beta({CLIENT,SERVER}) public interface SearchFacet extends Bson
A facet definition for FacetSearchCollector.
Since:
4.7
MongoDB Atlas documentation
Facet definition
  • Method Details

    • stringFacet

      static StringSearchFacet stringFacet(String name, FieldSearchPath path)
      Returns a SearchFacet that allows narrowing down search results based on the most frequent BSON String values of the specified field.
      Parameters:
      name - The facet name.
      path - The field to facet on.
      Returns:
      The requested SearchFacet.
      MongoDB Atlas documentation
      String facet definition
    • numberFacet

      static NumberSearchFacet numberFacet(String name, FieldSearchPath path, Iterable<? extends Number> boundaries)
      Returns a SearchFacet that allows determining the frequency of BSON 32-bit integer / 64-bit integer / Double values in the search results by breaking the results into separate ranges.
      Parameters:
      name - The facet name.
      path - The path to facet on.
      boundaries - Bucket boundaries in ascending order. Must contain at least two boundaries.
      Returns:
      The requested SearchFacet.
      MongoDB Atlas documentation
      Numeric facet definition
    • dateFacet

      static DateSearchFacet dateFacet(String name, FieldSearchPath path, Iterable<Instant> boundaries)
      Returns a SearchFacet that allows determining the frequency of BSON Date values in the search results by breaking the results into separate ranges.
      Parameters:
      name - The facet name.
      path - The path to facet on.
      boundaries - Bucket boundaries in ascending order. Must contain at least two boundaries.
      Returns:
      The requested SearchFacet.
      See Also:
      MongoDB Atlas documentation
      Date facet definition
    • of

      static SearchFacet of(Bson facet)
      Creates a SearchFacet from a Bson in situations when there is no builder method that better satisfies your needs. This method cannot be used to validate the syntax.

      Example
      The following code creates two functionally equivalent SearchFacets, though they may not be equal.

      
        SearchFacet facet1 = SearchFacet.stringFacet("facetName",
                SearchPath.fieldPath("fieldName"));
        SearchFacet facet2 = SearchFacet.of(new Document("facetName", new Document("type", "string")
                .append("path", SearchPath.fieldPath("fieldName").toValue())));
       
      Parameters:
      facet - A Bson representing the required SearchFacet.
      Returns:
      The requested SearchFacet.
    • combineToBson

      static Bson combineToBson(Iterable<? extends SearchFacet> facets)
      Combines SearchFacets into a Bson.

      This method may be useful when using SearchCollector.of(Bson).

      Parameters:
      facets - The non-empty facet definitions to combine.
      Returns:
      A Bson representing combined facets.