Class IndexedField<I,T>
- java.lang.Object
-
- com.google.gerrit.index.IndexedField<I,T>
-
- Type Parameters:
I
- input type from which documents are created and search results are returned.T
- type that should be extracted from the input object when converting to an index document.
public abstract class IndexedField<I,T> extends Object
Definition of a field stored in the secondary index.Each IndexedField, stored in index, may have multiple
IndexedField.SearchSpec
which defines how it can be searched and how the index tokens are generated.Index implementations may choose to store IndexedField and
IndexedField.SearchSpec
(search tokens) separately, howeverIndexedQuery
always issues the queries toIndexedField.SearchSpec
.This allows index implementations to store IndexedField once, while enabling multiple tokenization strategies on the same IndexedField with
IndexedField.SearchSpec
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IndexedField.Builder<I,T>
A builder forIndexedField
.class
IndexedField.SearchSpec
Defines howIndexedField
can be searched and how the index tokens are generated.
-
Field Summary
Fields Modifier and Type Field Description static com.google.common.reflect.TypeToken<byte[]>
BYTE_ARRAY_TYPE
static com.google.common.reflect.TypeToken<Integer>
INTEGER_TYPE
static com.google.common.reflect.TypeToken<Iterable<byte[]>>
ITERABLE_BYTE_ARRAY_TYPE
static com.google.common.reflect.TypeToken<Iterable<Integer>>
ITERABLE_INTEGER_TYPE
static com.google.common.reflect.TypeToken<Iterable<Long>>
ITERABLE_LONG_TYPE
static com.google.common.reflect.TypeToken<Iterable<String>>
ITERABLE_STRING_TYPE
static com.google.common.reflect.TypeToken<Long>
LONG_TYPE
static com.google.common.reflect.TypeToken<String>
STRING_TYPE
static com.google.common.reflect.TypeToken<Timestamp>
TIMESTAMP_TYPE
-
Constructor Summary
Constructors Constructor Description IndexedField()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description IndexedField.SearchSpec
addSearchSpec(String name, SearchOption searchOption)
AddsIndexedField.SearchSpec
to thisIndexedField
static <I,T>
IndexedField.Builder<I,T>builder(String name, com.google.common.reflect.TypeToken<T> fieldType)
static <I> IndexedField.Builder<I,byte[]>
byteArrayBuilder(String name)
abstract Optional<String>
description()
Optional description of the field data.IndexedField.SearchSpec
exact(String name)
abstract Optional<SchemaFieldDefs.Setter<I,T>>
fieldSetter()
abstract com.google.common.reflect.TypeToken<T>
fieldType()
TheTypeToken
describing the contents of the field.IndexedField.SearchSpec
fullText(String name)
T
get(I input)
Get the field contents from the input object.com.google.common.collect.ImmutableMap<String,IndexedField.SearchSpec>
getSearchSpecs()
Returns allIndexedField.SearchSpec
, enabled on this field.abstract SchemaFieldDefs.Getter<I,T>
getter()
IndexedField.SearchSpec
integer(String name)
static <I> IndexedField.Builder<I,Integer>
integerBuilder(String name)
IndexedField.SearchSpec
integerRange(String name)
boolean
isProtoIterableType()
Returns true if thefieldType()
is a list of proto messages.boolean
isProtoType()
Returns true if thefieldType()
is a proto message.static <I> IndexedField.Builder<I,Iterable<byte[]>>
iterableByteArrayBuilder(String name)
static <I> IndexedField.Builder<I,Iterable<Integer>>
iterableIntegerBuilder(String name)
static <I> IndexedField.Builder<I,Iterable<String>>
iterableStringBuilder(String name)
static <I> IndexedField.Builder<I,Long>
longBuilder(String name)
IndexedField.SearchSpec
longSearch(String name)
abstract String
name()
The name to store this field under.IndexedField.SearchSpec
prefix(String name)
abstract Optional<ProtoConverter<? extends com.google.protobuf.MessageLite,?>>
protoConverter()
If thefieldType()
is proto, the converter to use on byte/proto conversions.IndexedField.SearchSpec
range(String name)
abstract boolean
repeatable()
True if this field is repeatable.abstract boolean
required()
True if this field is mandatory.boolean
setIfPossible(I object, StoredValue doc)
abstract Optional<Integer>
size()
Optional size constrain on the field.abstract boolean
stored()
Allow reading the actual data from the index.IndexedField.SearchSpec
storedOnly(String name)
static <I> IndexedField.Builder<I,String>
stringBuilder(String name)
IndexedField.SearchSpec
timestamp(String name)
static <I> IndexedField.Builder<I,Timestamp>
timestampBuilder(String name)
-
-
-
Field Detail
-
INTEGER_TYPE
public static final com.google.common.reflect.TypeToken<Integer> INTEGER_TYPE
-
ITERABLE_INTEGER_TYPE
public static final com.google.common.reflect.TypeToken<Iterable<Integer>> ITERABLE_INTEGER_TYPE
-
LONG_TYPE
public static final com.google.common.reflect.TypeToken<Long> LONG_TYPE
-
ITERABLE_LONG_TYPE
public static final com.google.common.reflect.TypeToken<Iterable<Long>> ITERABLE_LONG_TYPE
-
STRING_TYPE
public static final com.google.common.reflect.TypeToken<String> STRING_TYPE
-
ITERABLE_STRING_TYPE
public static final com.google.common.reflect.TypeToken<Iterable<String>> ITERABLE_STRING_TYPE
-
BYTE_ARRAY_TYPE
public static final com.google.common.reflect.TypeToken<byte[]> BYTE_ARRAY_TYPE
-
ITERABLE_BYTE_ARRAY_TYPE
public static final com.google.common.reflect.TypeToken<Iterable<byte[]>> ITERABLE_BYTE_ARRAY_TYPE
-
TIMESTAMP_TYPE
public static final com.google.common.reflect.TypeToken<Timestamp> TIMESTAMP_TYPE
-
-
Method Detail
-
builder
public static <I,T> IndexedField.Builder<I,T> builder(String name, com.google.common.reflect.TypeToken<T> fieldType)
-
iterableStringBuilder
public static <I> IndexedField.Builder<I,Iterable<String>> iterableStringBuilder(String name)
-
stringBuilder
public static <I> IndexedField.Builder<I,String> stringBuilder(String name)
-
integerBuilder
public static <I> IndexedField.Builder<I,Integer> integerBuilder(String name)
-
longBuilder
public static <I> IndexedField.Builder<I,Long> longBuilder(String name)
-
iterableIntegerBuilder
public static <I> IndexedField.Builder<I,Iterable<Integer>> iterableIntegerBuilder(String name)
-
timestampBuilder
public static <I> IndexedField.Builder<I,Timestamp> timestampBuilder(String name)
-
byteArrayBuilder
public static <I> IndexedField.Builder<I,byte[]> byteArrayBuilder(String name)
-
iterableByteArrayBuilder
public static <I> IndexedField.Builder<I,Iterable<byte[]>> iterableByteArrayBuilder(String name)
-
addSearchSpec
public IndexedField.SearchSpec addSearchSpec(String name, SearchOption searchOption)
AddsIndexedField.SearchSpec
to thisIndexedField
- Parameters:
name
- the name to use for in the search.searchOption
- the tokenization option, enabled by the newIndexedField.SearchSpec
- Returns:
- the added
IndexedField.SearchSpec
.
-
exact
public IndexedField.SearchSpec exact(String name)
-
fullText
public IndexedField.SearchSpec fullText(String name)
-
range
public IndexedField.SearchSpec range(String name)
-
integerRange
public IndexedField.SearchSpec integerRange(String name)
-
integer
public IndexedField.SearchSpec integer(String name)
-
longSearch
public IndexedField.SearchSpec longSearch(String name)
-
prefix
public IndexedField.SearchSpec prefix(String name)
-
storedOnly
public IndexedField.SearchSpec storedOnly(String name)
-
timestamp
public IndexedField.SearchSpec timestamp(String name)
-
name
public abstract String name()
The name to store this field under.The name should use the UpperCamelCase format, see
IndexedField.Builder.checkName(java.lang.String)
.
-
required
public abstract boolean required()
True if this field is mandatory. Default is false.This property is not enforced by the common indexing logic. It is up to the index implementations to enforce that the field is required.
-
stored
public abstract boolean stored()
Allow reading the actual data from the index. Default is false.
-
repeatable
public abstract boolean repeatable()
True if this field is repeatable.
-
size
public abstract Optional<Integer> size()
Optional size constrain on the field. The size is not constrained if this property isOptional.empty()
This property is not enforced by the common indexing logic. It is up to the index implementations to enforce the size.
If the field is
repeatable()
, the constraint applies to each element separately.
-
getter
public abstract SchemaFieldDefs.Getter<I,T> getter()
-
fieldSetter
public abstract Optional<SchemaFieldDefs.Setter<I,T>> fieldSetter()
-
fieldType
public abstract com.google.common.reflect.TypeToken<T> fieldType()
TheTypeToken
describing the contents of the field. See static constants for the common supported types.- Returns:
TypeToken
of this field.
-
protoConverter
public abstract Optional<ProtoConverter<? extends com.google.protobuf.MessageLite,?>> protoConverter()
If thefieldType()
is proto, the converter to use on byte/proto conversions.
-
getSearchSpecs
public com.google.common.collect.ImmutableMap<String,IndexedField.SearchSpec> getSearchSpecs()
Returns allIndexedField.SearchSpec
, enabled on this field.Note: weather or not a search is supported by the index depends on
Schema
version.
-
get
public T get(I input)
Get the field contents from the input object.- Parameters:
input
- input object.- Returns:
- the field value(s) to index.
-
setIfPossible
public boolean setIfPossible(I object, StoredValue doc)
-
isProtoType
public boolean isProtoType()
Returns true if thefieldType()
is a proto message.
-
isProtoIterableType
public boolean isProtoIterableType()
Returns true if thefieldType()
is a list of proto messages.
-
-