Class Field


  • @API(MAINTAINED)
    public class Field
    extends Object
    Class that provides context for asserting about a field value. oneOfThem() and matches(QueryComponent) allow you to create other components, while the remaining functions allow you to match on the value of the associated field directly.
    • Method Detail

      • matches

        @Nonnull
        public QueryComponent matches​(@Nonnull
                                      QueryComponent child)
        If the associated field is a submessage, this allows you to match against the fields within that submessage. The child is evaluated and validated in the context of this field, not the record containing this field.
        Parameters:
        child - a component asserting about the content of the submessage in this field
        Returns:
        a new component ready for evaluation
      • oneOfThem

        @Nonnull
        public OneOfThem oneOfThem()
        If the associated field is a repeated one, this allows you to match against one of the repeated values. The record will be returned if any one of the values returns true. The same record may be returned more than once. If the repeated field is empty, the match result will be UNKNOWN.
        Returns:
        an OneOfThem that can have further assertions called on it about the value of the given field
      • oneOfThem

        @Nonnull
        public OneOfThem oneOfThem​(Field.OneOfThemEmptyMode emptyMode)
        If the associated field is a repeated one, this allows you to match against one of the repeated values. The record will be returned if any one of the values returns true. The same record may be returned more than once.
        Parameters:
        emptyMode - whether an empty repeated field should cause an UNKNOWN result instead of failing to match any (and so returning FALSE)
        Returns:
        an OneOfThem that can have further assertions called on it about the value of the given field
      • equalsValue

        @Nonnull
        public QueryComponent equalsValue​(@Nonnull
                                          Object comparand)
        Checks if the field has a value equal to the given comparand. Evaluates to null if the field does not have a value.
        Parameters:
        comparand - the object to compare with the value in the field
        Returns:
        a new component for doing the actual evaluation
      • notEquals

        @Nonnull
        public QueryComponent notEquals​(@Nonnull
                                        Object comparand)
        Checks if the field has a value not equal to the given comparand. Evaluates to null if the field does not have a value.
        Parameters:
        comparand - the object to compare with the value in the field
        Returns:
        a new component for doing the actual evaluation
      • greaterThan

        @Nonnull
        public QueryComponent greaterThan​(@Nonnull
                                          Object comparand)
        Checks if the field has a value greater than the given comparand. Evaluates to null if the field does not have a value.
        Parameters:
        comparand - the object to compare with the value in the field
        Returns:
        a new component for doing the actual evaluation
      • greaterThanOrEquals

        @Nonnull
        public QueryComponent greaterThanOrEquals​(@Nonnull
                                                  Object comparand)
        Checks if the field has a value greater than or equal to the given comparand. Evaluates to null if the field does not have a value.
        Parameters:
        comparand - the object to compare with the value in the field
        Returns:
        a new component for doing the actual evaluation
      • lessThan

        @Nonnull
        public QueryComponent lessThan​(@Nonnull
                                       Object comparand)
        Checks if the field has a value less than the given comparand. Evaluates to null if the field does not have a value.
        Parameters:
        comparand - the object to compare with the value in the field
        Returns:
        a new component for doing the actual evaluation
      • lessThanOrEquals

        @Nonnull
        public QueryComponent lessThanOrEquals​(@Nonnull
                                               Object comparand)
        Checks if the field has a value less than or equal to the given comparand. Evaluates to null if the field does not have a value.
        Parameters:
        comparand - the object to compare with the value in the field
        Returns:
        a new component for doing the actual evaluation
      • startsWith

        @Nonnull
        public QueryComponent startsWith​(@Nonnull
                                         String comparand)
        Checks if the field starts with the given string. Requires that the field contains a string. Evaluates to null if the field does not have a value.
        Parameters:
        comparand - the object to compare with the value in the field
        Returns:
        a new component for doing the actual evaluation
      • isNull

        @Nonnull
        public QueryComponent isNull()
        Returns true if the field has not been set and uses the default value.
        Returns:
        a new component for doing the actual evaluation
      • notNull

        @Nonnull
        public QueryComponent notNull()
        Returns true if the field does not use the default value.
        Returns:
        a new component for doing the actual evaluation
      • isEmpty

        @Nonnull
        public QueryComponent isEmpty()
        Returns true if the repeated field does not have any occurrences.
        Returns:
        a new component for doing the actual evaluation
      • notEmpty

        @Nonnull
        public QueryComponent notEmpty()
        Returns true if the repeated field has occurrences.
        Returns:
        a new component for doing the actual evaluation
      • in

        @Nonnull
        public QueryComponent in​(@Nonnull
                                 List<?> comparand)
        Query where the value of this field is in the given list.
        Parameters:
        comparand - a list of elements
        Returns:
        a new component for doing the actual evaluation
      • in

        @Nonnull
        public QueryComponent in​(@Nonnull
                                 String param)
        Query where the value of this field is in the list that is bound to the given param.
        Parameters:
        param - a param that will be bound to a list in the execution context
        Returns:
        a new component for doing the actual evaluation
      • text

        @Nonnull
        public Text text()
        Query where the value of this field matches some property when performing a full-text search. It does not specify any tokenizer information, so it is assumed that any tokenizer is acceptable for parsing query string (if not already tokenized) or to parse the record's text or to match against an index. If an index is used during query execution, then it is guaranteed that the same tokenizer that was used to tokenize the index is used to tokenize the query string (if not already tokenized).
        Returns:
        an intermediate object to use to select the appropriate predicate
      • text

        @Nonnull
        public Text text​(@Nullable
                         String tokenizerName)
        Query where the value of this field matches some property when performing a full-text search. If tokenizerName is not null, then this will use that tokenizer to tokenize the query string (if not already tokenized) and to parse the record's text. If an index is used, then it is guaranteed that the index uses this same tokenizer. If tokenizerName is null, then this behaves the same as text().
        Parameters:
        tokenizerName - the name of the tokenizer to use to tokenize the record and (if necessary) the query string
        Returns:
        an intermediate object to use to select the appropriate predicate
      • text

        @Nonnull
        public Text text​(@Nullable
                         String tokenizerName,
                         @Nullable
                         String defaultTokenizerName)
        Query where the value of this field matches some property when performing a full-text search. If tokenizerName is not null, then this will use that tokenizer to tokenize the query string (if not already tokenized) and to parse the record's text. If an index is used, then it is guaranteed that the index uses this same tokenizer. If tokenizerName is null, then this behaves the same as text() except that if defaultTokenizerName is not null, then it will use that tokenizer to tokenize the document and query string (if no index is available) instead of the normal default tokenizer, DefaultTextTokenizer.
        Parameters:
        tokenizerName - the name of the tokenizer to use to tokenize the record and (if necessary) the query string
        defaultTokenizerName - the name of the tokenizer to use if tokenizerName is null and no index can be found to satisfy the query
        Returns:
        an intermediate object to use to select the appropriate predicate
      • equalsParameter

        @Nonnull
        public QueryComponent equalsParameter​(@Nonnull
                                              String param)
        Checks if the field has a value equal to the given parameter. Evaluates to null if the field does not have a value.
        Parameters:
        param - the name of the parameter
        Returns:
        a new component for doing the actual evaluation
      • mapMatches

        @Nonnull
        public QueryComponent mapMatches​(@Nullable
                                         Function<Field,​QueryComponent> keyMatcher,
                                         @Nullable
                                         Function<Field,​QueryComponent> valueMatcher)
        Match map field entries.
        
         Query.field("map_field").mapMatches(k -> k.equals("akey"), v -> v.greaterThan(10))
         
        Parameters:
        keyMatcher - a function to apply to the key Field or null not to restrict the key
        valueMatcher - a function to apply to the value Field or null not to restrict the value
        Returns:
        a new component that will return the record if the map field has an entry matching the key and value criteria