Skip to content

Commit

Permalink
Remove use of deprecated field highlight parameter (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
aprudhomme authored Sep 17, 2024
1 parent 65509c9 commit ab103d0
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 104 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ public AtomFieldDef(String name, Field requestField) {

@Override
protected void validateRequest(Field requestField) {
if (requestField.getHighlight() && !requestField.getSearch()) {
throw new IllegalArgumentException("search must be true when highlight is true");
}

if (requestField.getHighlight() && !requestField.getStore()) {
throw new IllegalArgumentException("store must be true when highlight is true");
}

if (hasAnalyzer(requestField)) {
throw new IllegalArgumentException(
"no analyzer allowed with atom (it's hardwired to KeywordAnalyzer internally)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ protected BooleanFieldDef(String name, Field requestField) {
protected void validateRequest(Field requestField) {
super.validateRequest(requestField);

if (requestField.getHighlight()) {
throw new IllegalArgumentException(
String.format(
"Field: %s cannot have highlight=true. only type=text or type=atom fields can have highlight=true",
getName()));
}

if (hasAnalyzer(requestField) && !requestField.getSearch()) {
throw new IllegalArgumentException("No analyzer allowed when search=false");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,6 @@ private void ensureUpperIsMoreThanLower(RangeQuery rangeQuery, long lower, long
protected void validateRequest(Field requestField) {
super.validateRequest(requestField);

if (requestField.getHighlight()) {
throw new IllegalArgumentException(
String.format(
"field: %s cannot have highlight=true. only type=text or type=atom fields can have highlight=true",
getName()));
}

if (hasAnalyzer(requestField)) {
throw new IllegalArgumentException("no analyzer allowed on datetime field");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ public LatLonFieldDef(String name, Field requestField) {
protected void validateRequest(Field requestField) {
super.validateRequest(requestField);

if (requestField.getHighlight()) {
throw new IllegalArgumentException(
String.format(
"field: %s cannot have highlight=true. only type=text or type=atom fields can have highlight=true",
getName()));
}

if (requestField.getStore()) {
throw new IllegalArgumentException("latlon fields cannot be stored");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ protected NumberFieldDef(String name, Field requestField, Function<String, Numbe
protected void validateRequest(Field requestField) {
super.validateRequest(requestField);

if (requestField.getHighlight()) {
throw new IllegalArgumentException(
String.format(
"field: %s cannot have highlight=true. only type=text or type=atom fields can have highlight=true",
getName()));
}

if (hasAnalyzer(requestField)) {
throw new IllegalArgumentException("no analyzer allowed on Number fields");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ protected PolygonfieldDef(String name, Field requestField) {
protected void validateRequest(Field requestField) {
super.validateRequest(requestField);

if (requestField.getHighlight()) {
throw new IllegalArgumentException(
String.format(
"field: %s cannot have highlight=true. only type=text or type=atom fields can have highlight=true",
getName()));
}

if (hasAnalyzer(requestField)) {
throw new IllegalArgumentException("no analyzer allowed on polygon field");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.yelp.nrtsearch.server.grpc.*;
import com.yelp.nrtsearch.server.grpc.Field;
import com.yelp.nrtsearch.server.luceneserver.Constants;
import com.yelp.nrtsearch.server.luceneserver.analysis.AnalyzerCreator;
import com.yelp.nrtsearch.server.luceneserver.analysis.PosIncGapAnalyzerWrapper;
import com.yelp.nrtsearch.server.luceneserver.doc.DocValuesFactory;
Expand Down Expand Up @@ -51,13 +50,12 @@

/**
* Base class for all text base field definitions. In addition to the properties from {@link
* IndexableFieldDef}, text fields have the option for {@link Analyzer}s and highlighting.
* IndexableFieldDef}, text fields have the option for {@link Analyzer}s.
*/
public abstract class TextBaseFieldDef extends IndexableFieldDef
implements TermQueryable, GlobalOrdinalable {
static final int DEFAULT_POSITION_INCREMENT_GAP = 100;

private final boolean isHighlighted;
private final Analyzer indexAnalyzer;
private final Analyzer searchAnalyzer;
private final boolean eagerFieldGlobalOrdinals;
Expand All @@ -67,16 +65,14 @@ public abstract class TextBaseFieldDef extends IndexableFieldDef

/**
* Field constructor. Uses {@link IndexableFieldDef#IndexableFieldDef(String, Field)} to do common
* initialization, then sets up highlighting and analyzers. Analyzers are parsed through calls to
* the protected methods {@link #parseIndexAnalyzer(Field)} and {@link
* #parseSearchAnalyzer(Field)}.
* initialization, then sets up analyzers. Analyzers are parsed through calls to the protected
* methods {@link #parseIndexAnalyzer(Field)} and {@link #parseSearchAnalyzer(Field)}.
*
* @param name field name
* @param requestField field definition from grpc request
*/
protected TextBaseFieldDef(String name, Field requestField) {
super(name, requestField);
isHighlighted = requestField.getHighlight();
indexAnalyzer = parseIndexAnalyzer(requestField);
searchAnalyzer = parseSearchAnalyzer(requestField);
eagerFieldGlobalOrdinals = requestField.getEagerFieldGlobalOrdinals();
Expand Down Expand Up @@ -119,9 +115,6 @@ protected DocValuesType parseDocValuesType(Field requestField) {
protected FacetValueType parseFacetValueType(Field requestField) {
FacetType facetType = requestField.getFacet();
if (facetType.equals(FacetType.HIERARCHY)) {
if (requestField.getHighlight()) {
throw new IllegalArgumentException("facet=hierarchy fields cannot have highlight=true");
}
if (requestField.getSearch()) {
throw new IllegalArgumentException("facet=hierarchy fields cannot have search=true");
}
Expand Down Expand Up @@ -239,16 +232,6 @@ public void parseDocumentField(

for (int i = 0; i < fieldValues.size(); i++) {
String fieldStr = fieldValues.get(i);
if (isHighlighted && isMultiValue() && fieldStr.indexOf(Constants.INFORMATION_SEP) != -1) {
// TODO: we could remove this restriction if it
// ever matters ... we can highlight multi-valued
// fields at search time without stealing a
// character:
throw new IllegalArgumentException(
String.format(
"%s multiValued and highlighted fields cannot contain INFORMATION_SEPARATOR (U+001F) character: this character is used internally when highlighting multi-valued fields",
getName()));
}
if (hasDocValues()) {
BytesRef stringBytes = new BytesRef(fieldStr);
if (docValuesType == DocValuesType.BINARY) {
Expand Down Expand Up @@ -280,7 +263,7 @@ private void addFacet(Document document, String value, List<String> paths) {
if (paths.isEmpty()) {
document.add(new FacetField(getName(), value));
} else {
document.add(new FacetField(getName(), paths.toArray(new String[paths.size()])));
document.add(new FacetField(getName(), paths.toArray(new String[0])));
}
} else if (facetValueType == FacetValueType.FLAT) {
document.add(new FacetField(getName(), value));
Expand All @@ -290,15 +273,6 @@ private void addFacet(Document document, String value, List<String> paths) {
}
}

/**
* Get if this field is highlighted.
*
* @return if this field is highlighted
*/
public boolean isHighlighted() {
return isHighlighted;
}

@Override
public Query getTermQueryFromTextValue(String textValue) {
return new org.apache.lucene.search.TermQuery(new Term(getName(), textValue));
Expand Down

0 comments on commit ab103d0

Please sign in to comment.