GroupField: Change UUID fields' type to KEYWORD

This is a preparatory change for adding support for Elasticsearch
version 5, where handling of keyword types is changed.

For the Lucene index, handle KEYWORD the same way as EXACT.

For Elasticsearch, also handle both KEYWORD and EXACT in the same way
since at this point we don't yet support Elasticsearch 5.

Change-Id: I545c3ce85b44f6f640c51afd22ba3c663ff6ba80
This commit is contained in:
David Pursehouse 2018-06-04 11:13:17 +09:00
parent 506125e71a
commit 09fdc3eaad
4 changed files with 13 additions and 11 deletions

View File

@ -26,7 +26,7 @@ class ElasticMapping {
for (FieldDef<?, ?> field : schema.getFields().values()) { for (FieldDef<?, ?> field : schema.getFields().values()) {
String name = field.getName(); String name = field.getName();
FieldType<?> fieldType = field.getType(); FieldType<?> fieldType = field.getType();
if (fieldType == FieldType.EXACT) { if (fieldType == FieldType.EXACT || fieldType == FieldType.KEYWORD) {
mapping.addExactField(name); mapping.addExactField(name);
} else if (fieldType == FieldType.TIMESTAMP) { } else if (fieldType == FieldType.TIMESTAMP) {
mapping.addTimestamp(name); mapping.addTimestamp(name);

View File

@ -94,7 +94,7 @@ public class ElasticQueryBuilder {
return intRangeQuery(p); return intRangeQuery(p);
} else if (type == FieldType.TIMESTAMP) { } else if (type == FieldType.TIMESTAMP) {
return timestampQuery(p); return timestampQuery(p);
} else if (type == FieldType.EXACT) { } else if (type == FieldType.EXACT || type == FieldType.KEYWORD) {
return exactQuery(p); return exactQuery(p);
} else if (type == FieldType.PREFIX) { } else if (type == FieldType.PREFIX) {
return QueryBuilders.matchPhrasePrefixQuery(name, value); return QueryBuilders.matchPhrasePrefixQuery(name, value);

View File

@ -141,20 +141,21 @@ public class QueryBuilder<V> {
"field not in schema v%s: %s", "field not in schema v%s: %s",
schema.getVersion(), schema.getVersion(),
p.getField().getName()); p.getField().getName());
if (p.getType() == FieldType.INTEGER) { FieldType<?> type = p.getType();
if (type == FieldType.INTEGER) {
return intQuery(p); return intQuery(p);
} else if (p.getType() == FieldType.INTEGER_RANGE) { } else if (type == FieldType.INTEGER_RANGE) {
return intRangeQuery(p); return intRangeQuery(p);
} else if (p.getType() == FieldType.TIMESTAMP) { } else if (type == FieldType.TIMESTAMP) {
return timestampQuery(p); return timestampQuery(p);
} else if (p.getType() == FieldType.EXACT) { } else if (type == FieldType.EXACT || type == FieldType.KEYWORD) {
return exactQuery(p); return exactQuery(p);
} else if (p.getType() == FieldType.PREFIX) { } else if (type == FieldType.PREFIX) {
return prefixQuery(p); return prefixQuery(p);
} else if (p.getType() == FieldType.FULL_TEXT) { } else if (type == FieldType.FULL_TEXT) {
return fullTextQuery(p); return fullTextQuery(p);
} else { } else {
throw FieldType.badFieldType(p.getType()); throw FieldType.badFieldType(type);
} }
} }

View File

@ -17,6 +17,7 @@ package com.google.gerrit.server.index.group;
import static com.google.gerrit.server.index.FieldDef.exact; import static com.google.gerrit.server.index.FieldDef.exact;
import static com.google.gerrit.server.index.FieldDef.fullText; import static com.google.gerrit.server.index.FieldDef.fullText;
import static com.google.gerrit.server.index.FieldDef.integer; import static com.google.gerrit.server.index.FieldDef.integer;
import static com.google.gerrit.server.index.FieldDef.keyword;
import static com.google.gerrit.server.index.FieldDef.prefix; import static com.google.gerrit.server.index.FieldDef.prefix;
import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroup;
@ -31,11 +32,11 @@ public class GroupField {
/** Group UUID. */ /** Group UUID. */
public static final FieldDef<AccountGroup, String> UUID = public static final FieldDef<AccountGroup, String> UUID =
exact("uuid").stored().build(g -> g.getGroupUUID().get()); keyword("uuid").stored().build(g -> g.getGroupUUID().get());
/** Group owner UUID. */ /** Group owner UUID. */
public static final FieldDef<AccountGroup, String> OWNER_UUID = public static final FieldDef<AccountGroup, String> OWNER_UUID =
exact("owner_uuid").build(g -> g.getOwnerGroupUUID().get()); keyword("owner_uuid").build(g -> g.getOwnerGroupUUID().get());
/** Group name. */ /** Group name. */
public static final FieldDef<AccountGroup, String> NAME = public static final FieldDef<AccountGroup, String> NAME =