Skip to content

Commit

Permalink
[backend] fix tests (#6549)
Browse files Browse the repository at this point in the history
  • Loading branch information
Archidoit committed Apr 15, 2024
1 parent 7d9071f commit b81f8ad
Showing 1 changed file with 56 additions and 32 deletions.
88 changes: 56 additions & 32 deletions opencti-platform/opencti-graphql/src/database/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1705,51 +1705,73 @@ const buildLocalMustFilter = async (validFilter) => {
throw UnsupportedError('Filter must have only one field', { keys: arrayKeys });
} else {
const schemaKey = schemaAttributesDefinition.getAttributeByName(R.head(arrayKeys));
valuesFiltering.push(schemaKey?.type === 'string' && schemaKey?.format === 'text'
? { // text filters: use wildcard
bool: {
must_not: {
wildcard: {
[R.head(arrayKeys)]: '*'
}
},
let valueFiltering = { // classic filters: field doesn't exist
bool: {
must_not: {
exists: {
field: R.head(arrayKeys)
}
}
} : { // other filters: nil <-> (field doesn't exist) OR (field = empty string)
bool: {
should: [{
bool: {
must_not: {
exists: {
field: R.head(arrayKeys)
}
}
};
if (schemaKey?.type === 'string') {
if (schemaKey?.format === 'text') { // text filters: use wildcard
valueFiltering = {
bool: {
must_not: {
wildcard: {
[R.head(arrayKeys)]: '*'
}
}
}, {
multi_match: {
fields: arrayKeys.map((k) => `${isDateNumericOrBooleanAttribute(k) || k === '_id' || isObjectFlatAttribute(k) ? k : `${k}.keyword`}`),
query: '',
},
}],
minimum_should_match: 1,
}
});
}
};
} else { // string filters: nil <-> (field doesn't exist) OR (field = empty string)
valueFiltering = {
bool: {
should: [{
bool: {
must_not: {
exists: {
field: R.head(arrayKeys)
}
}
}
}, {
multi_match: {
fields: arrayKeys.map((k) => `${k === '_id' ? k : `${k}.keyword`}`),
query: '',
},
}],
minimum_should_match: 1,
}
};
}
}
valuesFiltering.push(valueFiltering);
}
} else if (operator === 'not_nil') {
if (arrayKeys.length > 1) {
throw UnsupportedError('Filter must have only one field', { keys: arrayKeys });
} else {
const schemaKey = schemaAttributesDefinition.getAttributeByName(R.head(arrayKeys));
valuesFiltering.push(
schemaKey?.type === 'string' && schemaKey?.format === 'text'
? { // text filters: use wildcard
let valueFiltering = { // classic filters: field exists
exists: {
field: R.head(arrayKeys)
}
};
if (schemaKey?.type === 'string') {
if (schemaKey?.format === 'text') { // text filters: use wildcard
valueFiltering = {
bool: {
must: {
wildcard: {
[R.head(arrayKeys)]: '*'
}
},
}
} : { // other filters: not_nil <-> (field exists) AND (field != empty string)
};
} else { // other filters: not_nil <-> (field exists) AND (field != empty string)
valueFiltering = {
bool: {
should: [{
exists: {
Expand All @@ -1759,16 +1781,18 @@ const buildLocalMustFilter = async (validFilter) => {
bool: {
must_not: {
multi_match: {
fields: arrayKeys.map((k) => `${isDateNumericOrBooleanAttribute(k) || k === '_id' || isObjectFlatAttribute(k) ? k : `${k}.keyword`}`),
fields: arrayKeys.map((k) => `${k === '_id' ? k : `${k}.keyword`}`),
query: '',
},
}
}
}],
minimum_should_match: 2,
}
}
);
};
}
}
valuesFiltering.push(valueFiltering);
}
}
// 03. Handle values according to the operator
Expand Down

0 comments on commit b81f8ad

Please sign in to comment.