Class SearchOperatorBuilder

java.lang.Object
net.ygbstudio.jbrave.core.builders.SearchOperatorBuilder

public final class SearchOperatorBuilder extends Object
A builder class for constructing search operators.

This class provides a fluent API for constructing search operators. The build() method returns the constructed search operator string.

Example usage:

String searchOperator = SearchOperatorBuilder.builder()
    .filetype("html")
    .and(op -> op.loc("ca"), op -> op.intitle("java"))
    .build();

This will construct the search operator string filetype:html loc:caANDintitle:java.

  • Method Details

    • builder

      @Contract(" -> new") @NotNull public static @NotNull SearchOperatorBuilder builder()
      Creates a new instance of the SearchOperatorBuilder class.
      Returns:
      a new instance of the SearchOperatorBuilder class
    • ext

      public SearchOperatorBuilder ext(@NotNull @NotNull String extension)
      Adds an "ext" operator and its corresponding value to the builder.
      Parameters:
      extension - the file extension to search for
      Returns:
      the current instance of the SearchOperatorBuilder class
    • filetype

      public SearchOperatorBuilder filetype(@NotNull @NotNull String filetype)
      Adds a "filetype" operator and its corresponding value to the .
      Parameters:
      filetype - the file type to search for
      Returns:
      the current instance of the SearchOperatorBuilder class
    • intitle

      public SearchOperatorBuilder intitle(@NotNull @NotNull String intitleContent)
      Adds an "intitle" operator and its corresponding value to the builder.
      Parameters:
      intitleContent - the content to search for in the title
      Returns:
      the current instance of the SearchOperatorBuilder class
    • inpage

      public SearchOperatorBuilder inpage(@NotNull @NotNull String inpageContent)
      Adds an "inpage" operator and its corresponding value to the builder.
      Parameters:
      inpageContent - the content to search for within the page
      Returns:
      the current instance of the SearchOperatorBuilder class
    • lang

      public SearchOperatorBuilder lang(@NotNull @NotNull String language)
      Adds a "lang" operator and its corresponding value to the builder.
      Parameters:
      language - the language to search for
      Returns:
      the current instance of the SearchOperatorBuilder class
    • loc

      public SearchOperatorBuilder loc(@NotNull @NotNull String location)
      Adds a "loc" operator and its corresponding value to the builder.
      Parameters:
      location - the location to search for
      Returns:
      the current instance of the SearchOperatorBuilder class
    • site

      public SearchOperatorBuilder site(@NotNull @NotNull String site)
      Adds a "site" operator and its corresponding value to the builder.
      Parameters:
      site - the site to search for
      Returns:
      the current instance of the SearchOperatorBuilder class
    • include

      public SearchOperatorBuilder include(@NotNull @NotNull String toInclude)
      Adds an "+" operator with its corresponding value to the builder.
      Parameters:
      toInclude - the content to include in the search
      Returns:
      the current instance of the SearchOperatorBuilder class
    • exclude

      public SearchOperatorBuilder exclude(@NotNull @NotNull String toExclude)
      Adds a "-" operator with its corresponding value to the builder.
      Parameters:
      toExclude - the content to exclude from the search
      Returns:
      the current instance of the SearchOperatorBuilder class
    • exactMatch

      public SearchOperatorBuilder exactMatch(@NotNull @NotNull String exactMatch)
      Adds double quotes to the corresponding value (exact search term match) and adds it to the builder.
      Parameters:
      exactMatch - the exact match to search for
      Returns:
      the current instance of the SearchOperatorBuilder class
    • and

      public SearchOperatorBuilder and(@NotNull @NotNull String termOne, @NotNull @NotNull String termTwo)
      Adds the logical AND operator and its corresponding values to the builder.
      Parameters:
      termOne - the first term to search for
      termTwo - the second term to search for
      Returns:
      the current instance of the SearchOperatorBuilder class
    • and

      public SearchOperatorBuilder and(@NotNull @NotNull UnaryOperator<SearchOperatorBuilder> operatorOne, @NotNull @NotNull UnaryOperator<SearchOperatorBuilder> operatorTwo)
      Adds the logical AND operator and its corresponding values to the builder. Combines two builder lambdas in order to construct logical expressions with search operators.
      Parameters:
      operatorOne - the first operator to search for
      operatorTwo - the second operator to search for
      Returns:
      the current instance of the SearchOperatorBuilder class
    • or

      public SearchOperatorBuilder or(@NotNull @NotNull String termOne, @NotNull @NotNull String termTwo)
      Adds the logical OR operator and its corresponding values to the builder.
      Parameters:
      termOne - the first term to search for
      termTwo - the second term to search for
      Returns:
      the current instance of the SearchOperatorBuilder class
    • or

      public SearchOperatorBuilder or(@NotNull @NotNull UnaryOperator<SearchOperatorBuilder> operatorOne, @NotNull @NotNull UnaryOperator<SearchOperatorBuilder> operatorTwo)
      Adds the logical OR operator and its corresponding values to the builder. Combines two builder lambdas in order to construct logical expressions with search operators.
      Parameters:
      operatorOne - the first operator to search for
      operatorTwo - the second operator to search for
      Returns:
      the current instance of the SearchOperatorBuilder class
    • not

      public SearchOperatorBuilder not(@NotNull @NotNull String termOne, @NotNull @NotNull String termTwo)
      Adds the logical NOT operator and its corresponding values to the builder.
      Parameters:
      termOne - the term to search for that should not be present
      termTwo - the term that should not be present
      Returns:
      the current instance of the SearchOperatorBuilder class
    • not

      public SearchOperatorBuilder not(@NotNull @NotNull UnaryOperator<SearchOperatorBuilder> operatorOne, @NotNull @NotNull UnaryOperator<SearchOperatorBuilder> operatorTwo)
      Adds the logical NOT operator and its corresponding values to the builder. Combines two builder lambdas in order to construct logical expressions with search operators.
      Parameters:
      operatorOne - the first operator to search for that should not be present
      operatorTwo - the second operator to search for that should not be present
      Returns:
      the current instance of the SearchOperatorBuilder class
    • clear

      public SearchOperatorBuilder clear()
      Clears the search operator builder by removing all the operators and their corresponding values.
      Returns:
      the current instance of the SearchOperatorBuilder class
    • build

      public String build()
      Constructs the search operator string by concatenating the values of the builder with the corresponding operators.
      Returns:
      the search operator string