Package com.google.gerrit.index
Class FieldDef<I,T>
- java.lang.Object
-
- com.google.gerrit.index.FieldDef<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.
- All Implemented Interfaces:
SchemaFieldDefs.SchemaField<I,T>
public final class FieldDef<I,T> extends Object implements SchemaFieldDefs.SchemaField<I,T>
Definition of a field stored in the secondary index.FieldDef
-s must not be changed once introduced to the codebase. Instead, a new FieldDef must be added and the old one removed from the schema (in two upgrade steps, seecom.google.gerrit.index.IndexUpgradeValidator
).Note that
FieldDef
does not overrideObject.equals(Object)
. It relies on instances being singletons so that the default (i.e. reference) comparison works.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FieldDef.Builder<T>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FieldDef.Builder<String>
exact(String name)
static FieldDef.Builder<String>
fullText(String name)
T
get(I input)
Get the field contents from the input object.String
getName()
Returns name of the field.FieldType<?>
getType()
Returns type of the field; for repeatable fields, the inner type, not the iterable type.static FieldDef.Builder<Integer>
integer(String name)
static FieldDef.Builder<Integer>
intRange(String name)
boolean
isRepeatable()
Returns whether the field is repeatable.boolean
isStored()
Returns whether the field should be stored in the index.static FieldDef.Builder<String>
prefix(String name)
boolean
setIfPossible(I object, StoredValue doc)
Set the field contents back to an object.static FieldDef.Builder<byte[]>
storedOnly(String name)
static FieldDef.Builder<Timestamp>
timestamp(String name)
-
-
-
Method Detail
-
exact
public static FieldDef.Builder<String> exact(String name)
-
fullText
public static FieldDef.Builder<String> fullText(String name)
-
intRange
public static FieldDef.Builder<Integer> intRange(String name)
-
integer
public static FieldDef.Builder<Integer> integer(String name)
-
prefix
public static FieldDef.Builder<String> prefix(String name)
-
storedOnly
public static FieldDef.Builder<byte[]> storedOnly(String name)
-
timestamp
public static FieldDef.Builder<Timestamp> timestamp(String name)
-
getName
public String getName()
Returns name of the field.- Specified by:
getName
in interfaceSchemaFieldDefs.SchemaField<I,T>
-
getType
public FieldType<?> getType()
Returns type of the field; for repeatable fields, the inner type, not the iterable type.- Specified by:
getType
in interfaceSchemaFieldDefs.SchemaField<I,T>
-
isStored
public boolean isStored()
Returns whether the field should be stored in the index.- Specified by:
isStored
in interfaceSchemaFieldDefs.SchemaField<I,T>
-
get
public T get(I input)
Get the field contents from the input object.- Specified by:
get
in interfaceSchemaFieldDefs.SchemaField<I,T>
- Parameters:
input
- input object.- Returns:
- the field value(s) to index.
-
setIfPossible
public boolean setIfPossible(I object, StoredValue doc)
Set the field contents back to an object. Used to reconstruct fields from indexed values. No-op if the field can't be reconstructed.- Specified by:
setIfPossible
in interfaceSchemaFieldDefs.SchemaField<I,T>
- Parameters:
object
- input object.doc
- indexed document- Returns:
true
if the field was set,false
otherwise
-
isRepeatable
public boolean isRepeatable()
Returns whether the field is repeatable.- Specified by:
isRepeatable
in interfaceSchemaFieldDefs.SchemaField<I,T>
-
-