From 1d0f21aeb3261607419d41fa685a9cfbb8f88b60 Mon Sep 17 00:00:00 2001 From: "a.niebisch" <a.niebisch@ANIEBISCH-NB.aditosoftware.local> Date: Thu, 18 Jun 2020 10:45:40 +0200 Subject: [PATCH] #1059353 refactored id filter for the duplicates search --- process/DuplicateScanner_lib/process.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/process/DuplicateScanner_lib/process.js b/process/DuplicateScanner_lib/process.js index 3576d4dcf36..9e6e4e7557b 100644 --- a/process/DuplicateScanner_lib/process.js +++ b/process/DuplicateScanner_lib/process.js @@ -910,9 +910,8 @@ pResultFields, pRecordIdValueToIgnore, pFormatValuesConsumeWebserviceCallback, p let ignoreSourceRecordPattern = _DuplicateScannerUtils._getIgnoreSourceRecordPattern(pRecordIdValueToIgnore); let indexPatternWithValues = _DuplicateScannerUtils._replacePlaceholderForValuesInPattern(pIndexPattern, pEntityFieldConfigValuesRay); - indexPatternWithValues = ignoreSourceRecordPattern + indexPatternWithValues + ")"; - possibleDuplicates = _DuplicateScannerUtils._callIndexSearch(pTargetEntity, indexPatternWithValues, pResultFields, 100); + possibleDuplicates = _DuplicateScannerUtils._callIndexSearch(pTargetEntity, indexPatternWithValues, ignoreSourceRecordPattern, pResultFields, 100); if(possibleDuplicates == null) return null; @@ -948,11 +947,12 @@ _DuplicateScannerUtils._isUseExternalWebservice = function(pFilterName, pTargetE * * @param {String} pTargetEntity Entity which has been configured * @param {String} pIndexPatternWithValues The pattern used to search. Has to contain the values already. + * @param {String} pIdFilter The filter pattern used to exclude the current record from the result. * @param {String} pResultFields The result field config. Use "DuplicateScannerUtils.LoadResultFields" * @param {String} pResultSetRows todo * @returns {[["key", "value"]] || null} Array of Key-Value-Pairs based on the configured pResultFields, if no pattern exists null */ -_DuplicateScannerUtils._callIndexSearch = function(pTargetEntity, pIndexPatternWithValues, pResultFields, pResultSetRows) +_DuplicateScannerUtils._callIndexSearch = function(pTargetEntity, pIndexPatternWithValues, pIdFilter, pResultFields, pResultSetRows) { logging.log(pIndexPatternWithValues) //The indexPattern can't be null because it is required to run the search. @@ -961,9 +961,13 @@ _DuplicateScannerUtils._callIndexSearch = function(pTargetEntity, pIndexPatternW let indexQuery = indexsearch.createIndexQuery() .setPattern(pIndexPatternWithValues) .setEntities([pTargetEntity]) +// .addFilter(pIdFilter); // .setDefaultOperator(indexsearch.OPERATOR_AND) //.addSearchFields("Person_entity.FIRSTNAME", "Person_entity.LASTNAME", "Person_entity.CONTACTID") //.setRows(pResultSetRows); + if(pIdFilter && pIdFilter.length > 0) + indexQuery.addFilter(pIdFilter); + indexQuery = _DuplicateScannerUtils._setResultFields(indexQuery, pResultFields); return indexsearch.searchIndex(indexQuery); } @@ -1102,14 +1106,20 @@ _DuplicateScannerUtils._buildDeleteCachedUnrelatedDuplicateQuery = function(pSou } /* - * Creates a pattern which excludes the field and it's value + * Creates a filter pattern which excludes results with the provided id from the search. * - * @param {String} pRecordIdValueToIgnore The fields value - * @returns {String} Pattern which excludes the gived field in combination with the value + * @param {String} pRecordIdValueToIgnore The id value to exclude from the result. + * @returns {String} Filter pattern which excludes hits with the given id (index) from the result. */ _DuplicateScannerUtils._getIgnoreSourceRecordPattern = function(pRecordIdValueToIgnore) { - return "( +( -" + indexsearch.FIELD_ID + ":(" + pRecordIdValueToIgnore + ") ) "; + // creates -_local_id_:"<pRecordIdValueToIgnore>" + if(pRecordIdValueToIgnore && pRecordIdValueToIgnore.length > 0) + return indexsearch.buildPattern(indexsearch.createPatternConfig().minus( + indexsearch.createPhraseTerm(pRecordIdValueToIgnore) + .setIndexField(indexsearch.FIELD_ID) + )); + return null; } _DuplicateScannerUtils._buildUpdateContactIdStatements = function(pTableInfos, pSourceContactId, pTargetContactId, pAlias) -- GitLab