Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/main/java/com/yelp/nrtsearch/server/field/AtomFieldDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,24 @@ public class AtomFieldDef extends TextBaseFieldDef

public AtomFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
super(name, requestField, context);
this(name, requestField, context, null);
}

/**
* Constructor for creating an instance of this field based on a previous instance. This is used
* when updating field properties.
*
* @param name name of the field
* @param requestField the field definition from the request
* @param context context for creating the field definition
* @param previousField the previous instance of this field definition, or null if there is none
*/
protected AtomFieldDef(
String name,
Field requestField,
FieldDefCreator.FieldDefCreatorContext context,
AtomFieldDef previousField) {
super(name, requestField, context, previousField);
}

@Override
Expand All @@ -59,6 +76,12 @@ public String getType() {
return "ATOM";
}

@Override
public FieldDef createUpdatedFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
return new AtomFieldDef(name, requestField, context, this);
}

@Override
public Object parseLastValue(String value) {
return new BytesRef(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,24 @@
public class BooleanFieldDef extends IndexableFieldDef<Boolean> implements TermQueryable {
protected BooleanFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
super(name, requestField, context, Boolean.class);
this(name, requestField, context, null);
}

/**
* Constructor for creating an instance of this field based on a previous instance. This is used
* when updating field properties.
*
* @param name name of the field
* @param requestField the field definition from the request
* @param context context for creating the field definition
* @param previousField the previous instance of this field definition, or null if there is none
*/
protected BooleanFieldDef(
String name,
Field requestField,
FieldDefCreator.FieldDefCreatorContext context,
BooleanFieldDef previousField) {
super(name, requestField, context, Boolean.class, previousField);
}

@Override
Expand Down Expand Up @@ -138,6 +155,12 @@ public String getType() {
return "BOOLEAN";
}

@Override
public FieldDef createUpdatedFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
return new BooleanFieldDef(name, requestField, context, this);
}

@Override
public Query getTermQueryFromBooleanValue(boolean booleanValue) {
verifySearchable("Term query");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,24 @@ public class ContextSuggestFieldDef extends IndexableFieldDef<Void> {
*/
protected ContextSuggestFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
super(name, requestField, context, Void.class);
this(name, requestField, context, null);
}

/**
* Constructor for creating an instance of this field based on a previous instance. This is used
* when updating field properties.
*
* @param name name of the field
* @param requestField the field definition from the request
* @param context context for creating the field definition
* @param previousField the previous instance of this field definition, or null if there is none
*/
protected ContextSuggestFieldDef(
String name,
Field requestField,
FieldDefCreator.FieldDefCreatorContext context,
ContextSuggestFieldDef previousField) {
super(name, requestField, context, Void.class, previousField);
this.indexAnalyzer = this.parseIndexAnalyzer(requestField);
this.searchAnalyzer = this.parseSearchAnalyzer(requestField);
this.postingsFormat =
Expand All @@ -64,6 +81,12 @@ public String getType() {
return "CONTEXT_SUGGEST";
}

@Override
public FieldDef createUpdatedFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
return new ContextSuggestFieldDef(name, requestField, context, this);
}

@Override
public void parseDocumentField(
Document document, List<String> fieldValues, List<List<String>> facetHierarchyPaths) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,24 @@ private static DateTimeFormatter createDateTimeFormatter(String dateTimeFormat)

public DateTimeFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
super(name, requestField, context, Instant.class);
this(name, requestField, context, null);
}

/**
* Constructor for creating an instance of this field based on a previous instance. This is used
* when updating field properties.
*
* @param name name of the field
* @param requestField the field definition from the request
* @param context context for creating the field definition
* @param previousField the previous instance of this field definition, or null if there is none
*/
protected DateTimeFieldDef(
String name,
Field requestField,
FieldDefCreator.FieldDefCreatorContext context,
DateTimeFieldDef previousField) {
super(name, requestField, context, Instant.class, previousField);
dateTimeFormat = requestField.getDateTimeFormat();
dateTimeFormatter = createDateTimeFormatter(dateTimeFormat);
}
Expand Down Expand Up @@ -369,6 +386,12 @@ public String getType() {
return "DATE_TIME";
}

@Override
public FieldDef createUpdatedFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
return new DateTimeFieldDef(name, requestField, context, this);
}

/**
* Get the format used to parse date time string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,24 @@ public class DoubleFieldDef extends NumberFieldDef<Double> {

public DoubleFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
super(name, requestField, DOUBLE_PARSER, context, Double.class);
this(name, requestField, context, null);
}

/**
* Constructor for creating an instance of this field based on a previous instance. This is used
* when updating field properties.
*
* @param name name of the field
* @param requestField the field definition from the request
* @param context context for creating the field definition
* @param previousField the previous instance of this field definition, or null if there is none
*/
protected DoubleFieldDef(
String name,
Field requestField,
FieldDefCreator.FieldDefCreatorContext context,
DoubleFieldDef previousField) {
super(name, requestField, DOUBLE_PARSER, context, Double.class, previousField);
}

@Override
Expand Down Expand Up @@ -101,6 +118,12 @@ public String getType() {
return "DOUBLE";
}

@Override
public FieldDef createUpdatedFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
return new DoubleFieldDef(name, requestField, context, this);
}

@Override
public Query getRangeQuery(RangeQuery rangeQuery) {
verifySearchableOrDocValues("Range query");
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/yelp/nrtsearch/server/field/FieldDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.yelp.nrtsearch.server.field;

import com.yelp.nrtsearch.server.grpc.Field;
import java.io.Closeable;

/** Base class for all field definition types. */
Expand All @@ -35,6 +36,22 @@ public String getName() {
return name;
}

/**
* Create a new instance of the current {@link FieldDef} that is updated to use the provided
* request field definition. This method must not modify the current instance, but instead return
* a new instance with the updated properties.
*
* @param name name of the field
* @param requestField the field definition from the request
* @param context context for creating the field definition
* @return a new instance of the field definition with updated properties
*/
public FieldDef createUpdatedFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
throw new UnsupportedOperationException(
String.format("Field %s does not support update", this.getName()));
}

/** Get String representation of the field type. */
public abstract String getType();

Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/yelp/nrtsearch/server/field/FieldDefCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,29 @@ public FieldDef createFieldDef(String name, Field field, FieldDefCreatorContext
return provider.get(name, field, context);
}

/**
* Create a new {@link FieldDef} instance based on a previous {@link FieldDef}. This is typically
* used when updating a field definition in the index.
*
* @param name name of the field
* @param field grpc request field definition
* @param previousFieldDef previous field definition, or null if there is none
* @param context context for creating the field definition
* @return new field definition instance
*/
public FieldDef createFieldDefFromPrevious(
String name, Field field, FieldDef previousFieldDef, FieldDefCreatorContext context) {
if (previousFieldDef == null) {
return createFieldDef(name, field, context);
}
FieldDef updatedFieldDef = previousFieldDef.createUpdatedFieldDef(name, field, context);
if (updatedFieldDef == null) {
throw new IllegalArgumentException(
"FieldDef " + previousFieldDef.getName() + " cannot be updated");
}
return updatedFieldDef;
}

/**
* Create a new {@link FieldDefCreatorContext} instance.
*
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/com/yelp/nrtsearch/server/field/FloatFieldDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,24 @@ public class FloatFieldDef extends NumberFieldDef<Float> {

public FloatFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
super(name, requestField, FLOAT_PARSER, context, Float.class);
this(name, requestField, context, null);
}

/**
* Constructor for creating an instance of this field based on a previous instance. This is used
* when updating field properties.
*
* @param name name of the field
* @param requestField the field definition from the request
* @param context context for creating the field definition
* @param previousField the previous instance of this field definition, or null if there is none
*/
protected FloatFieldDef(
String name,
Field requestField,
FieldDefCreator.FieldDefCreatorContext context,
FloatFieldDef previousField) {
super(name, requestField, FLOAT_PARSER, context, Float.class, previousField);
}

@Override
Expand Down Expand Up @@ -99,6 +116,12 @@ public String getType() {
return "FLOAT";
}

@Override
public FieldDef createUpdatedFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
return new FloatFieldDef(name, requestField, context, this);
}

@Override
public Query getRangeQuery(RangeQuery rangeQuery) {
verifySearchableOrDocValues("Range query");
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/com/yelp/nrtsearch/server/field/IdFieldDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,24 @@ public class IdFieldDef extends IndexableFieldDef<String> implements TermQueryab

protected IdFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
super(name, requestField, context, String.class);
this(name, requestField, context, null);
}

/**
* Constructor for creating an instance of this field based on a previous instance. This is used
* when updating field properties.
*
* @param name name of the field
* @param requestField the field definition from the request
* @param context context for creating the field definition
* @param previousField the previous instance of this field definition, or null if there is none
*/
protected IdFieldDef(
String name,
Field requestField,
FieldDefCreator.FieldDefCreatorContext context,
IdFieldDef previousField) {
super(name, requestField, context, String.class, previousField);
}

/**
Expand Down Expand Up @@ -142,6 +159,12 @@ public String getType() {
return "_ID";
}

@Override
public FieldDef createUpdatedFieldDef(
String name, Field requestField, FieldDefCreator.FieldDefCreatorContext context) {
return new IdFieldDef(name, requestField, context, this);
}

/**
* Construct a Term with the given field and value to identify the document to be added or updated
*
Expand Down
Loading
Loading