Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename index_prefix to index_prefixes #30932

Merged
merged 2 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"search with index prefixes":
- skip:
version: " - 6.99.99"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the way we'll need to change this to 6.2.99 after you merge this

reason: index_prefix is only available as of 6.3.0
reason: index_prefixes is only available as of 6.3.0
- do:
indices.create:
index: test
Expand All @@ -12,7 +12,7 @@
properties:
text:
type: text
index_prefix:
index_prefixes:
min_chars: 1
max_chars: 10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public TextFieldMapper build(BuilderContext context) {
PrefixFieldMapper prefixMapper = null;
if (prefixFieldType != null) {
if (fieldType().isSearchable() == false) {
throw new IllegalArgumentException("Cannot set index_prefix on unindexed field [" + name() + "]");
throw new IllegalArgumentException("Cannot set index_prefixes on unindexed field [" + name() + "]");
}
if (fieldType.indexOptions() == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) {
prefixFieldType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
Expand Down Expand Up @@ -203,7 +203,7 @@ public Mapper.Builder parse(String fieldName, Map<String, Object> node, ParserCo
builder.fielddataFrequencyFilter(minFrequency, maxFrequency, minSegmentSize);
DocumentMapperParser.checkNoRemainingFields(propName, frequencyFilter, parserContext.indexVersionCreated());
iterator.remove();
} else if (propName.equals("index_prefix")) {
} else if (propName.equals("index_prefixes")) {
Map<?, ?> indexPrefix = (Map<?, ?>) propNode;
int minChars = XContentMapValues.nodeIntegerValue(indexPrefix.remove("min_chars"),
Defaults.INDEX_PREFIX_MIN_CHARS);
Expand Down Expand Up @@ -243,7 +243,7 @@ protected TokenStreamComponents wrapComponents(String fieldName, TokenStreamComp
}
}

private static final class PrefixFieldType extends StringFieldType {
static final class PrefixFieldType extends StringFieldType {

final int minChars;
final int maxChars;
Expand All @@ -268,14 +268,14 @@ boolean accept(int length) {
}

void doXContent(XContentBuilder builder) throws IOException {
builder.startObject("index_prefix");
builder.startObject("index_prefixes");
builder.field("min_chars", minChars);
builder.field("max_chars", maxChars);
builder.endObject();
}

@Override
public MappedFieldType clone() {
public PrefixFieldType clone() {
return new PrefixFieldType(name(), minChars, maxChars);
}

Expand Down Expand Up @@ -305,6 +305,22 @@ public void checkCompatibility(MappedFieldType other, List<String> conflicts) {
public Query existsQuery(QueryShardContext context) {
throw new UnsupportedOperationException();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
PrefixFieldType that = (PrefixFieldType) o;
return minChars == that.minChars &&
maxChars == that.maxChars;
}

@Override
public int hashCode() {

return Objects.hash(super.hashCode(), minChars, maxChars);
}
}

private static final class PrefixFieldMapper extends FieldMapper {
Expand Down Expand Up @@ -355,6 +371,9 @@ protected TextFieldType(TextFieldType ref) {
this.fielddataMinFrequency = ref.fielddataMinFrequency;
this.fielddataMaxFrequency = ref.fielddataMaxFrequency;
this.fielddataMinSegmentSize = ref.fielddataMinSegmentSize;
if (ref.prefixFieldType != null) {
this.prefixFieldType = ref.prefixFieldType.clone();
}
}

public TextFieldType clone() {
Expand All @@ -368,14 +387,15 @@ public boolean equals(Object o) {
}
TextFieldType that = (TextFieldType) o;
return fielddata == that.fielddata
&& Objects.equals(prefixFieldType, that.prefixFieldType)
&& fielddataMinFrequency == that.fielddataMinFrequency
&& fielddataMaxFrequency == that.fielddataMaxFrequency
&& fielddataMinSegmentSize == that.fielddataMinSegmentSize;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), fielddata,
return Objects.hash(super.hashCode(), fielddata, prefixFieldType,
fielddataMinFrequency, fielddataMaxFrequency, fielddataMinSegmentSize);
}

Expand Down Expand Up @@ -420,6 +440,10 @@ void setPrefixFieldType(PrefixFieldType prefixFieldType) {
this.prefixFieldType = prefixFieldType;
}

public PrefixFieldType getPrefixFieldType() {
return this.prefixFieldType;
}

@Override
public String typeName() {
return CONTENT_TYPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ public void testIndexPrefixIndexTypes() throws IOException {
.startObject("properties").startObject("field")
.field("type", "text")
.field("analyzer", "english")
.startObject("index_prefix").endObject()
.startObject("index_prefixes").endObject()
.field("index_options", "offsets")
.endObject().endObject().endObject().endObject());

Expand All @@ -623,7 +623,7 @@ public void testIndexPrefixIndexTypes() throws IOException {
.startObject("properties").startObject("field")
.field("type", "text")
.field("analyzer", "english")
.startObject("index_prefix").endObject()
.startObject("index_prefixes").endObject()
.field("index_options", "positions")
.endObject().endObject().endObject().endObject());

Expand All @@ -640,7 +640,7 @@ public void testIndexPrefixIndexTypes() throws IOException {
.startObject("properties").startObject("field")
.field("type", "text")
.field("analyzer", "english")
.startObject("index_prefix").endObject()
.startObject("index_prefixes").endObject()
.field("term_vector", "with_positions_offsets")
.endObject().endObject().endObject().endObject());

Expand All @@ -657,7 +657,7 @@ public void testIndexPrefixIndexTypes() throws IOException {
.startObject("properties").startObject("field")
.field("type", "text")
.field("analyzer", "english")
.startObject("index_prefix").endObject()
.startObject("index_prefixes").endObject()
.field("term_vector", "with_positions")
.endObject().endObject().endObject().endObject());

Expand All @@ -682,7 +682,7 @@ public void testIndexPrefixMapping() throws IOException {
.startObject("properties").startObject("field")
.field("type", "text")
.field("analyzer", "english")
.startObject("index_prefix")
.startObject("index_prefixes")
.field("min_chars", 1)
.field("max_chars", 10)
.endObject()
Expand Down Expand Up @@ -716,7 +716,7 @@ public void testIndexPrefixMapping() throws IOException {
.startObject("properties").startObject("field")
.field("type", "text")
.field("analyzer", "english")
.startObject("index_prefix").endObject()
.startObject("index_prefixes").endObject()
.endObject().endObject()
.endObject().endObject());
CompressedXContent json = new CompressedXContent(mapping);
Expand All @@ -741,7 +741,7 @@ public void testIndexPrefixMapping() throws IOException {
.startObject("properties").startObject("field")
.field("type", "text")
.field("analyzer", "english")
.startObject("index_prefix")
.startObject("index_prefixes")
.field("min_chars", 1)
.field("max_chars", 10)
.endObject()
Expand All @@ -760,7 +760,7 @@ public void testIndexPrefixMapping() throws IOException {
.startObject("properties").startObject("field")
.field("type", "text")
.field("analyzer", "english")
.startObject("index_prefix")
.startObject("index_prefixes")
.field("min_chars", 1)
.field("max_chars", 10)
.endObject()
Expand All @@ -783,7 +783,7 @@ public void testIndexPrefixMapping() throws IOException {
.startObject("properties").startObject("field")
.field("type", "text")
.field("analyzer", "english")
.startObject("index_prefix")
.startObject("index_prefixes")
.field("min_chars", 11)
.field("max_chars", 10)
.endObject()
Expand All @@ -800,7 +800,7 @@ public void testIndexPrefixMapping() throws IOException {
.startObject("properties").startObject("field")
.field("type", "text")
.field("analyzer", "english")
.startObject("index_prefix")
.startObject("index_prefixes")
.field("min_chars", 0)
.field("max_chars", 10)
.endObject()
Expand All @@ -817,7 +817,7 @@ public void testIndexPrefixMapping() throws IOException {
.startObject("properties").startObject("field")
.field("type", "text")
.field("analyzer", "english")
.startObject("index_prefix")
.startObject("index_prefixes")
.field("min_chars", 1)
.field("max_chars", 25)
.endObject()
Expand All @@ -834,27 +834,27 @@ public void testIndexPrefixMapping() throws IOException {
.startObject("properties").startObject("field")
.field("type", "text")
.field("analyzer", "english")
.field("index_prefix", (String) null)
.field("index_prefixes", (String) null)
.endObject().endObject()
.endObject().endObject());
MapperParsingException e = expectThrows(MapperParsingException.class,
() -> parser.parse("type", new CompressedXContent(badConfigMapping))
);
assertThat(e.getMessage(), containsString("[index_prefix] must not have a [null] value"));
assertThat(e.getMessage(), containsString("[index_prefixes] must not have a [null] value"));
}

{
String badConfigMapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field")
.field("type", "text")
.field("index", "false")
.startObject("index_prefix").endObject()
.startObject("index_prefixes").endObject()
.endObject().endObject()
.endObject().endObject());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> parser.parse("type", new CompressedXContent(badConfigMapping))
);
assertThat(e.getMessage(), containsString("Cannot set index_prefix on unindexed field [field]"));
assertThat(e.getMessage(), containsString("Cannot set index_prefixes on unindexed field [field]"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ public void modify(MappedFieldType ft) {
tft.setFielddataMinSegmentSize(1000);
}
});
addModifier(new Modifier("index_prefixes", true) {
@Override
public void modify(MappedFieldType ft) {
TextFieldMapper.TextFieldType tft = (TextFieldMapper.TextFieldType)ft;
TextFieldMapper.PrefixFieldType pft = tft.getPrefixFieldType();
if (pft == null) {
tft.setPrefixFieldType(new TextFieldMapper.PrefixFieldType(ft.name(), 3, 3));
}
else {
tft.setPrefixFieldType(null);
}
}
});
}

public void testTermQuery() {
Expand Down