in app/vidispine/search/VidispineSearch.ts [200:241]
withSearchTerm(fieldName: string, values: string[], toGroup?: string) {
const newEl: SearchFieldIF = {
name: fieldName,
value: values.map((stringval) => ({ value: stringval })),
};
let newObject = Object.assign(new VidispineSearchDoc(), this);
let groupMatch;
if (toGroup) {
groupMatch = newObject.findOrMakeMatchingGroupIndex(toGroup);
console.log("groupMatch", groupMatch);
}
//TODO: this needs a load of optimising, if we decide to keep it (not currently used)
if (groupMatch) {
const updatedGroupContent = groupMatch[0].field.concat(newEl);
console.log("updatedGroupContent", updatedGroupContent);
if (newObject.operator && newObject.operator.group) {
newObject.operator.group[groupMatch[1]].field = updatedGroupContent;
} else if (newObject.group) {
console.log("adding to ", newObject.group[groupMatch[1]].field);
newObject.group[groupMatch[1]].field = updatedGroupContent;
} else {
console.error(
"Unexpected problem setting withSearchTerm, this indicates a code bug"
);
return this;
}
} else {
if (newObject.operator) {
newObject.operator.field = newObject.operator.field
? newObject.operator.field.concat(newEl)
: [newEl];
} else {
newObject.field = newObject.field
? newObject.field.concat(newEl)
: [newEl];
}
}
return newObject;
}