Interface SearchHighlight

All Superinterfaces:
Bson

@Evolving @Beta(CLIENT) public interface SearchHighlight extends Bson
Highlighting options. You may use the $meta: "searchHighlights" expression, e.g., via Projections.metaSearchHighlights(String), to extract the results of highlighting.
Since:
4.7
MongoDB Atlas documentation
Highlighting
  • Method Details

    • maxCharsToExamine

      SearchHighlight maxCharsToExamine(int maxCharsToExamine)
      Creates a new SearchHighlight with the maximum number of characters to examine on a document when performing highlighting for a field.
      Parameters:
      maxCharsToExamine - The maximum number of characters to examine.
      Returns:
      A new SearchHighlight.
    • maxNumPassages

      SearchHighlight maxNumPassages(int maxNumPassages)
      Creates a new SearchHighlight with the maximum number of high-scoring passages to return per document in the "highlights" results for each field.
      Parameters:
      maxNumPassages - The maximum number of high-scoring passages.
      Returns:
      A new SearchHighlight.
    • paths

      static SearchHighlight paths(SearchPath path, SearchPath... paths)
      Returns a SearchHighlight for the given paths.
      Parameters:
      path - The field to be searched.
      paths - More fields to be searched.
      Returns:
      The requested SearchHighlight.
    • paths

      static SearchHighlight paths(Iterable<? extends SearchPath> paths)
      Returns a SearchHighlight for the given paths.
      Parameters:
      paths - The non-empty fields to be searched.
      Returns:
      The requested SearchHighlight.
    • of

      static SearchHighlight of(Bson highlight)
      Creates a SearchHighlight 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 SearchHighlights, though they may not be equal.

      
        SearchHighlight highlight1 = SearchHighlight.paths(
                SearchPath.fieldPath("fieldName"),
                SearchPath.wildcardPath("wildc*rd"));
        SearchHighlight highlight2 = SearchHighlight.of(new Document("path", Arrays.asList(
                SearchPath.fieldPath("fieldName").toBsonValue(),
                SearchPath.wildcardPath("wildc*rd").toBsonValue())));
       
      Parameters:
      highlight - A Bson representing the required SearchHighlight.
      Returns:
      The requested SearchHighlight.