Merge "Account index: Add new field that contains name parts without secondary emails"
This commit is contained in:
commit
b5688c67ba
@ -33,6 +33,7 @@ import com.google.gerrit.server.account.AccountState;
|
|||||||
import com.google.gerrit.server.account.externalids.ExternalId;
|
import com.google.gerrit.server.account.externalids.ExternalId;
|
||||||
import com.google.gerrit.server.index.RefState;
|
import com.google.gerrit.server.index.RefState;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -43,27 +44,38 @@ public class AccountField {
|
|||||||
public static final FieldDef<AccountState, Integer> ID =
|
public static final FieldDef<AccountState, Integer> ID =
|
||||||
integer("id").stored().build(a -> a.getAccount().getId().get());
|
integer("id").stored().build(a -> a.getAccount().getId().get());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* External IDs.
|
||||||
|
*
|
||||||
|
* <p>This field includes secondary emails. Use this field only if the current user is allowed to
|
||||||
|
* see secondary emails (requires the {@link GlobalCapability.MODIFY_ACCOUNT} capability).
|
||||||
|
*/
|
||||||
public static final FieldDef<AccountState, Iterable<String>> EXTERNAL_ID =
|
public static final FieldDef<AccountState, Iterable<String>> EXTERNAL_ID =
|
||||||
exact("external_id")
|
exact("external_id")
|
||||||
.buildRepeatable(a -> Iterables.transform(a.getExternalIds(), id -> id.key().get()));
|
.buildRepeatable(a -> Iterables.transform(a.getExternalIds(), id -> id.key().get()));
|
||||||
|
|
||||||
/** Fuzzy prefix match on name and email parts. */
|
/**
|
||||||
|
* Fuzzy prefix match on name and email parts.
|
||||||
|
*
|
||||||
|
* <p>This field includes parts from the secondary emails. Use this field only if the current user
|
||||||
|
* is allowed to see secondary emails (requires the {@link GlobalCapability.MODIFY_ACCOUNT}
|
||||||
|
* capability).
|
||||||
|
*
|
||||||
|
* <p>Use the {@link AccountField#NAME_PART_NO_SECONDARY_EMAIL} if the current user can't see
|
||||||
|
* secondary emails.
|
||||||
|
*/
|
||||||
public static final FieldDef<AccountState, Iterable<String>> NAME_PART =
|
public static final FieldDef<AccountState, Iterable<String>> NAME_PART =
|
||||||
prefix("name")
|
prefix("name")
|
||||||
.buildRepeatable(
|
.buildRepeatable(
|
||||||
a -> {
|
a -> getNameParts(a, Iterables.transform(a.getExternalIds(), ExternalId::email)));
|
||||||
String fullName = a.getAccount().getFullName();
|
|
||||||
Set<String> parts =
|
|
||||||
SchemaUtil.getNameParts(
|
|
||||||
fullName, Iterables.transform(a.getExternalIds(), ExternalId::email));
|
|
||||||
|
|
||||||
// Additional values not currently added by getPersonParts.
|
/**
|
||||||
// TODO(dborowitz): Move to getPersonParts and remove this hack.
|
* Fuzzy prefix match on name and preferred email parts. Parts of secondary emails are not
|
||||||
if (fullName != null) {
|
* included.
|
||||||
parts.add(fullName.toLowerCase(Locale.US));
|
*/
|
||||||
}
|
public static final FieldDef<AccountState, Iterable<String>> NAME_PART_NO_SECONDARY_EMAIL =
|
||||||
return parts;
|
prefix("name2")
|
||||||
});
|
.buildRepeatable(a -> getNameParts(a, Arrays.asList(a.getAccount().getPreferredEmail())));
|
||||||
|
|
||||||
public static final FieldDef<AccountState, String> FULL_NAME =
|
public static final FieldDef<AccountState, String> FULL_NAME =
|
||||||
exact("full_name").build(a -> a.getAccount().getFullName());
|
exact("full_name").build(a -> a.getAccount().getFullName());
|
||||||
@ -71,6 +83,12 @@ public class AccountField {
|
|||||||
public static final FieldDef<AccountState, String> ACTIVE =
|
public static final FieldDef<AccountState, String> ACTIVE =
|
||||||
exact("inactive").build(a -> a.getAccount().isActive() ? "1" : "0");
|
exact("inactive").build(a -> a.getAccount().isActive() ? "1" : "0");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All emails (preferred email + secondary emails). Use this field only if the current user is
|
||||||
|
* allowed to see secondary emails (requires the 'Modify Account' capability).
|
||||||
|
*
|
||||||
|
* <p>Use the {@link AccountField#PREFERRED_EMAIL} if the current user can't see secondary emails.
|
||||||
|
*/
|
||||||
public static final FieldDef<AccountState, Iterable<String>> EMAIL =
|
public static final FieldDef<AccountState, Iterable<String>> EMAIL =
|
||||||
prefix("email")
|
prefix("email")
|
||||||
.buildRepeatable(
|
.buildRepeatable(
|
||||||
@ -145,5 +163,17 @@ public class AccountField {
|
|||||||
.map(e -> e.toByteArray())
|
.map(e -> e.toByteArray())
|
||||||
.collect(toSet()));
|
.collect(toSet()));
|
||||||
|
|
||||||
|
private static final Set<String> getNameParts(AccountState a, Iterable<String> emails) {
|
||||||
|
String fullName = a.getAccount().getFullName();
|
||||||
|
Set<String> parts = SchemaUtil.getNameParts(fullName, emails);
|
||||||
|
|
||||||
|
// Additional values not currently added by getPersonParts.
|
||||||
|
// TODO(dborowitz): Move to getPersonParts and remove this hack.
|
||||||
|
if (fullName != null) {
|
||||||
|
parts.add(fullName.toLowerCase(Locale.US));
|
||||||
|
}
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
private AccountField() {}
|
private AccountField() {}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,9 @@ public class AccountSchemaDefinitions extends SchemaDefinitions<AccountState> {
|
|||||||
static final Schema<AccountState> V6 =
|
static final Schema<AccountState> V6 =
|
||||||
schema(V5, AccountField.REF_STATE, AccountField.EXTERNAL_ID_STATE);
|
schema(V5, AccountField.REF_STATE, AccountField.EXTERNAL_ID_STATE);
|
||||||
|
|
||||||
static final Schema<AccountState> V7 = schema(V6, AccountField.PREFERRED_EMAIL_EXACT);
|
@Deprecated static final Schema<AccountState> V7 = schema(V6, AccountField.PREFERRED_EMAIL_EXACT);
|
||||||
|
|
||||||
|
static final Schema<AccountState> V8 = schema(V7, AccountField.NAME_PART_NO_SECONDARY_EMAIL);
|
||||||
|
|
||||||
public static final String NAME = "accounts";
|
public static final String NAME = "accounts";
|
||||||
public static final AccountSchemaDefinitions INSTANCE = new AccountSchemaDefinitions();
|
public static final AccountSchemaDefinitions INSTANCE = new AccountSchemaDefinitions();
|
||||||
|
Loading…
Reference in New Issue
Block a user