Internal: Uid#createTypeUids to accept a collection of ids rather than a list, plus rename method variants to avoid clashes
The downside of having createTypeUids accept a list only is that if you do provide a collection nothing breaks at compile time, but you end up calling the same method that accepts an object as second argument. Renamed both methods to avoid clashes to `createUidsForTypesAndId` and `createUidsForTypesAndIds`. The latter accepts now a Collection of Objects rather than just a List. Closes #11263
This commit is contained in:
parent
e91bf8a267
commit
5a0c456ac2
|
@ -130,20 +130,19 @@ public final class Uid {
|
||||||
return spare.get();
|
return spare.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BytesRef[] createTypeUids(Collection<String> types, Object ids) {
|
public static BytesRef[] createUidsForTypesAndId(Collection<String> types, Object id) {
|
||||||
return createTypeUids(types, Collections.singletonList(ids));
|
return createUidsForTypesAndIds(types, Collections.singletonList(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BytesRef[] createTypeUids(Collection<String> types, List<? extends Object> ids) {
|
public static BytesRef[] createUidsForTypesAndIds(Collection<String> types, Collection<?> ids) {
|
||||||
final int numIds = ids.size();
|
|
||||||
BytesRef[] uids = new BytesRef[types.size() * ids.size()];
|
BytesRef[] uids = new BytesRef[types.size() * ids.size()];
|
||||||
BytesRefBuilder typeBytes = new BytesRefBuilder();
|
BytesRefBuilder typeBytes = new BytesRefBuilder();
|
||||||
BytesRefBuilder idBytes = new BytesRefBuilder();
|
BytesRefBuilder idBytes = new BytesRefBuilder();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (String type : types) {
|
for (String type : types) {
|
||||||
typeBytes.copyChars(type);
|
typeBytes.copyChars(type);
|
||||||
for (int i = 0; i < numIds; i++, index++) {
|
for (Object id : ids) {
|
||||||
uids[index] = Uid.createUidAsBytes(typeBytes.get(), BytesRefs.toBytesRef(ids.get(i), idBytes));
|
uids[index++] = Uid.createUidAsBytes(typeBytes.get(), BytesRefs.toBytesRef(id, idBytes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return uids;
|
return uids;
|
||||||
|
|
|
@ -187,7 +187,7 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements RootMa
|
||||||
if (fieldType.indexOptions() != IndexOptions.NONE || context == null) {
|
if (fieldType.indexOptions() != IndexOptions.NONE || context == null) {
|
||||||
return super.termQuery(value, context);
|
return super.termQuery(value, context);
|
||||||
}
|
}
|
||||||
final BytesRef[] uids = Uid.createTypeUids(context.queryTypes(), value);
|
final BytesRef[] uids = Uid.createUidsForTypesAndId(context.queryTypes(), value);
|
||||||
if (uids.length == 1) {
|
if (uids.length == 1) {
|
||||||
return new TermQuery(new Term(UidFieldMapper.NAME, uids[0]));
|
return new TermQuery(new Term(UidFieldMapper.NAME, uids[0]));
|
||||||
} else {
|
} else {
|
||||||
|
@ -200,7 +200,7 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements RootMa
|
||||||
if (fieldType.indexOptions() != IndexOptions.NONE || context == null) {
|
if (fieldType.indexOptions() != IndexOptions.NONE || context == null) {
|
||||||
return super.termsQuery(values, context);
|
return super.termsQuery(values, context);
|
||||||
}
|
}
|
||||||
return new TermsQuery(UidFieldMapper.NAME, Uid.createTypeUids(context.queryTypes(), values));
|
return new TermsQuery(UidFieldMapper.NAME, Uid.createUidsForTypesAndIds(context.queryTypes(), values));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -121,7 +121,7 @@ public class IdsQueryParser implements QueryParser {
|
||||||
types = parseContext.mapperService().types();
|
types = parseContext.mapperService().types();
|
||||||
}
|
}
|
||||||
|
|
||||||
TermsQuery query = new TermsQuery(UidFieldMapper.NAME, Uid.createTypeUids(types, ids));
|
TermsQuery query = new TermsQuery(UidFieldMapper.NAME, Uid.createUidsForTypesAndIds(types, ids));
|
||||||
query.setBoost(boost);
|
query.setBoost(boost);
|
||||||
if (queryName != null) {
|
if (queryName != null) {
|
||||||
parseContext.addNamedQuery(queryName, query);
|
parseContext.addNamedQuery(queryName, query);
|
||||||
|
|
Loading…
Reference in New Issue