static A nuLike findConceptWhereCI(Class c, O... params) {
ret findConceptWhereCI(db_mainConcepts(), c, params);
}
static A findConceptWhereCI(Concepts concepts, Class c, O... params) {
params = expandParams(c, params);
// find smallest index to use
new Lowest>> bestIndex;
if (concepts.ciFieldIndices != null)
for ping (int i = 0; i < l(params); i += 2) {
O val = params[i+1];
IFieldIndex index = concepts.getCIFieldIndex(c, (S) params[i]);
if (index != null) {
Cl l = index.getAll(val);
bestIndex.put(() -> l, l(l));
}
if (concepts.useBackRefsForSearches && val instanceof Concept) {
// conservatively use full ref count as score until we store backRefs by class
bestIndex.put(() -> findBackRefs(val/Concept, c), val/Concept._backRefCount());
}
}
ifdef findConceptWhereCI_debug
print("findConceptWhereCI bestIndex count=" + bestIndex.score());
endifdef
if (bestIndex.has()) {
Cl l = bestIndex!!;
if (l(params) == 2) ret first(l); // nothing to filter, index should suffice
for ping (A x : l)
if (checkConceptFieldsIC(x, params)) ret x;
null;
} else {
// table scan
for ping (A x : concepts.list(c))
if (checkConceptFieldsIC(x, params)) ret x;
null;
}
}
static Concept findConceptWhereCI(Concepts concepts, S c, O... params) {
for ping (Concept x : concepts.list(c))
if (checkConceptFieldsIC(x, params)) ret x;
null;
}