@natlibfi/melinda-record-matching 2.2.0-alpha.2 → 2.2.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/candidate-search/index.js +1 -1
- package/dist/candidate-search/index.js.map +1 -1
- package/dist/candidate-search/query-list/bib.js +2 -2
- package/dist/candidate-search/query-list/bib.js.map +1 -1
- package/dist/index.js +102 -32
- package/dist/index.js.map +1 -1
- package/dist/match-detection/features/bib/authors.js +1 -1
- package/dist/match-detection/features/bib/authors.js.map +1 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js +3 -2
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -1
- package/dist/match-detection/index.js +36 -30
- package/dist/match-detection/index.js.map +1 -1
- package/dist/match-detection/index.spec.js +20 -2
- package/dist/match-detection/index.spec.js.map +1 -1
- package/dist/matching-utils.js +1 -1
- package/dist/matching-utils.js.map +1 -1
- package/package.json +1 -1
- package/src/candidate-search/index.js +3 -0
- package/src/candidate-search/query-list/bib.js +2 -2
- package/src/index.js +70 -29
- package/src/match-detection/features/bib/authors.js +1 -1
- package/src/match-detection/features/bib/standard-identifier-factory.js +2 -1
- package/src/match-detection/index.js +29 -19
- package/src/match-detection/index.spec.js +17 -3
- package/src/matching-utils.js +1 -1
|
@@ -92,7 +92,7 @@ var _default = ({
|
|
|
92
92
|
retrieveAll: false
|
|
93
93
|
});
|
|
94
94
|
debug(`Searching matches for ${inputRecordId}`);
|
|
95
|
-
debug(`Generated queryList ${JSON.stringify(queryList)}`);
|
|
95
|
+
debug(`Generated queryList ${JSON.stringify(queryList)}`); // if generateQueryList errored we should throw 422
|
|
96
96
|
|
|
97
97
|
if (queryList.length === 0) {
|
|
98
98
|
// eslint-disable-line functional/no-conditional-statement
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/candidate-search/index.js"],"names":["CandidateSearchError","Error","record","searchSpec","url","maxCandidates","maxRecordsPerRequest","serverMaxResult","MarcRecord","setValidationOptions","subfieldValues","debug","debugData","extend","JSON","stringify","adjustedMaxRecordsPerRequest","inputRecordId","getRecordId","queryList","client","version","retrieveAll","length","queryOffset","resultSetOffset","totalRecords","searchCounter","queryCandidateCounter","queryCounter","maxedQueries","query","records","failures","nextOffset","total","retrieveRecords","newTotalRecords","newQueryCounter","newSearchCounter","newQueryCandidateCounter","maxedQuery","checkMaxedQuery","undefined","newMaxedQueries","concat","queriesLeft","Promise","resolve","reject","promises","searchRetrieve","startRecord","on","err","SruSearchError","recordPromises","allSettled","filtered","filter","r","status","map","value","reason","payload","foundRecordXML","push","handleRecord","foundRecordMarc","MARCXML","from","foundRecordId","id","idFromXML","getRecordIdFromXML","message","MatchingError","data","field","get","recordXML"],"mappings":";;;;;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAjCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAWO,MAAMA,oBAAN,SAAmCC,KAAnC,CAAyC,E,CAEhD;AAEA;;;;;eACe,CAAC;AAACC,EAAAA,MAAD;AAASC,EAAAA,UAAT;AAAqBC,EAAAA,GAArB;AAA0BC,EAAAA,aAA1B;AAAyCC,EAAAA,oBAAoB,GAAG,EAAhE;AAAoEC,EAAAA,eAAe,GAAG;AAAtF,CAAD,KAAkG;AAC/GC,yBAAWC,oBAAX,CAAgC;AAACC,IAAAA,cAAc,EAAE;AAAjB,GAAhC;;AAEA,QAAMC,KAAK,GAAG,oBAAkB,oDAAlB,CAAd;AACA,QAAMC,SAAS,GAAGD,KAAK,CAACE,MAAN,CAAa,MAAb,CAAlB;AAEAD,EAAAA,SAAS,CAAE,eAAcE,IAAI,CAACC,SAAL,CAAeZ,UAAf,CAA2B,EAA3C,CAAT;AACAS,EAAAA,SAAS,CAAE,QAAOR,GAAI,EAAb,CA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P,EAAY;AACZ;AACA,oBAAMoB,SAAS,GAAGC,kBAAkB,CAACT,cAAD,CAApC;AACAtD,cAAAA,SAAS,CAAE,6BAA4B0C,GAAG,CAACsB,OAAQ,SAAQF,SAAU,WAAUR,cAAe,EAArF,CAAT,CAHY,CAIZ;;AACA,oBAAM,IAAIW,qBAAJ,CAAkB,GAAlB,EAAuB;AAACD,gBAAAA,OAAO,EAAG,6BAA4BtB,GAAG,CAACsB,OAAQ,EAAnD;AAAsDH,gBAAAA,EAAE,EAAEC,SAAS,IAAI,WAAvE;AAAoFI,gBAAAA,IAAI,EAAEZ;AAA1F,eAAvB,CAAN;AACD;AACF;AACF,SAnDH;AAoDD,OA3DM,CAAP;AA4DD;AACF,GA1FD;;AA4FA,WAASxB,eAAT,CAAyBX,KAAzB,EAAgCI,KAAhC,EAAuC5B,eAAvC,EAAwD;AACtD;AACA,QAAI4B,KAAK,IAAI5B,eAAb,EAA8B;AAC5BI,MAAAA,KAAK,CAAE,kBAAiBoB,KAAM,gBAAeI,KAAM,0CAAyC5B,eAAgB,IAAvG,CAAL;AACA,aAAOwB,KAAP;AACD;AACF;;AAGD,WAASb,WAAT,CAAqBhB,MAArB,EAA6B;AAC3B,UAAM,CAAC6E,KAAD,IAAU7E,MAAM,CAAC8E,GAAP,CAAW,QAAX,CAAhB;AACA,WAAOD,KAAK,GAAGA,KAAK,CAAChB,KAAT,GAAiB,EAA7B;AACD;;AAED,WAASY,kBAAT,CAA4BM,SAA5B,EAAuC;AACrC;AACAtE,IAAAA,KAAK,CAAE,sEAAqEsE,SAAS,CAAC1D,MAAO,GAAxF,CAAL;AACA,WAAOoB,SAAP;AACD;AAEF,C","sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\nimport createClient, {SruSearchError} from '@natlibfi/sru-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {MARCXML} from '@natlibfi/marc-record-serializers';\nimport generateQueryList from './query-list';\nimport {Error as MatchingError} from '@natlibfi/melinda-commons';\n\nexport {searchTypes} from './query-list';\n\nexport class CandidateSearchError extends Error {}\n\n// serverMaxResults : maximum size of total search result available from the server, defaults to Aleph's 20000\n\n// eslint-disable-next-line max-statements\nexport default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest = 50, serverMaxResult = 20000}) => {\n MarcRecord.setValidationOptions({subfieldValues: false});\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search');\n const debugData = debug.extend('data');\n\n debugData(`SearchSpec: ${JSON.stringify(searchSpec)}`);\n debugData(`Url: ${url}`);\n debugData(`MaxRecordsPerRequest ${maxRecordsPerRequest}`);\n debugData(`ServerMaxResult: ${serverMaxResult}`);\n debugData(`MaxCandidates: ${maxCandidates}`);\n\n // Do not retrieve more candidates than defined in maxCandidates\n const adjustedMaxRecordsPerRequest = maxRecordsPerRequest >= maxCandidates ? maxCandidates : maxRecordsPerRequest;\n\n const inputRecordId = getRecordId(record);\n const queryList = generateQueryList(record, searchSpec);\n const client = createClient({\n url,\n maxRecordsPerRequest: adjustedMaxRecordsPerRequest,\n version: '2.0',\n retrieveAll: false\n });\n\n debug(`Searching matches for ${inputRecordId}`);\n debug(`Generated queryList ${JSON.stringify(queryList)}`);\n if (queryList.length === 0) { // eslint-disable-line functional/no-conditional-statement\n throw new CandidateSearchError(`Generated query list contains no queries`);\n }\n\n // state.totalRecords : amount of candidate records available to the current query (undefined, if there was no queries left)\n // state.query : current query (undefined if there was no queries left)\n // state.searchCounter : sequence for current search for current query (undefined, if there we no queries left)\n // state.queryCandidateCounter: amount of candidates (records+failures) retrieved from SRU for matching for current query, including the current record+failure set (undefined if there were no queries left)\n // state.queriesLeft : amount of queries left\n // state.queryCounter : sequence for current query\n // state.maxedQueries : queries that resulted in more than serverMaxResults hits\n\n\n return async ({queryOffset = 0, resultSetOffset = 1, totalRecords = 0, searchCounter = 0, queryCandidateCounter = 0, queryCounter = 0, maxedQueries = []}) => {\n const query = queryList[queryOffset];\n\n if (query) {\n const {records, failures, nextOffset, total} = await retrieveRecords();\n\n // If resultSetOffset === 1 this is the first search for the current query\n debugData(`ResultSetOffset: ${resultSetOffset}`);\n const newTotalRecords = resultSetOffset === 1 ? total : totalRecords;\n const newQueryCounter = resultSetOffset === 1 ? queryCounter + 1 : queryCounter;\n const newSearchCounter = resultSetOffset === 1 ? 1 : searchCounter + 1;\n const newQueryCandidateCounter = resultSetOffset === 1 ? records.length + failures.length : queryCandidateCounter + records.length + failures.length;\n\n const maxedQuery = resultSetOffset === 1 ? checkMaxedQuery(query, total, serverMaxResult) : undefined;\n const newMaxedQueries = maxedQuery ? maxedQueries.concat(maxedQuery) : maxedQueries;\n\n if (typeof nextOffset === 'number') {\n debug(`Next search will be for query ${queryOffset} ${query}, starting from record ${nextOffset}`);\n return {records, failures, queryOffset, resultSetOffset: nextOffset, queriesLeft: queryList.length - (queryOffset + 1), totalRecords: newTotalRecords, query, searchCounter: newSearchCounter, queryCandidateCounter: newQueryCandidateCounter, queryCounter: newQueryCounter, maxedQueries: newMaxedQueries};\n }\n debug(`Query ${queryOffset} ${query} done.`);\n debug(`There are (${queryList.length - (queryOffset + 1)} queries left)`);\n return {records, failures, queryOffset: queryOffset + 1, queriesLeft: queryList.length - (queryOffset + 1), totalRecords: newTotalRecords, query, searchCounter: newSearchCounter, queryCandidateCounter: newQueryCandidateCounter, queryCounter: newQueryCounter, maxedQueries: newMaxedQueries};\n }\n\n debug(`All ${queryList.length} queries done, there's no query for ${queryOffset}`);\n return {records: [], failures: [], queriesLeft: 0, queryCounter, maxedQueries};\n\n function retrieveRecords() {\n return new Promise((resolve, reject) => {\n const promises = [];\n // eslint-disable-next-line functional/no-let\n let totalRecords = 0;\n\n debug(`Searching for candidates with query: ${query} (Offset ${resultSetOffset})`);\n\n client.searchRetrieve(query, {startRecord: resultSetOffset})\n .on('error', err => {\n // eslint-disable-next-line functional/no-conditional-statement\n if (err instanceof SruSearchError) {\n debug(`SRU SruSearchError for query: ${query}: ${err}`);\n reject(new CandidateSearchError(`SRU SruSearchError for query: ${query}: ${err}`));\n }\n debug(`SRU error for query: ${query}: ${err}`);\n reject(new CandidateSearchError(`SRU error for query: ${query}: ${err}`));\n })\n .on('total', total => {\n debug(`Got total: ${total}`);\n totalRecords += total;\n })\n .on('end', async nextOffset => {\n try {\n const recordPromises = await Promise.allSettled(promises);\n debug(`All recordPromises: ${JSON.stringify(recordPromises)}`);\n const filtered = recordPromises.filter(r => r.status === 'fulfilled').map(r => r.value);\n const failures = recordPromises.filter(r => r.status === 'rejected').map(r => ({status: r.reason.status, payload: r.reason.payload}));\n\n debug(`Found ${JSON.stringify(recordPromises)} records`);\n debug(`Found ${filtered.length} convertable candidates`);\n debug(`Found ${failures.length} NON-convertable candidates`);\n debug(`Converted: ${JSON.stringify(filtered)}.`);\n debug(`Not converted: ${JSON.stringify(failures)}.`);\n\n\n resolve({nextOffset, records: filtered, failures, total: totalRecords});\n } catch (err) {\n debug(`Error caught on END`);\n reject(err);\n }\n })\n .on('record', foundRecordXML => {\n promises.push(handleRecord()); // eslint-disable-line functional/immutable-data\n\n async function handleRecord() {\n try {\n const foundRecordMarc = await MARCXML.from(foundRecordXML, {subfieldValues: false});\n const foundRecordId = getRecordId(foundRecordMarc);\n\n return {record: foundRecordMarc, id: foundRecordId};\n } catch (err) {\n // What should this do?\n const idFromXML = getRecordIdFromXML(foundRecordXML);\n debugData(`Failed converting record: ${err.message}, id: ${idFromXML}, data: ${foundRecordXML}`);\n //return {message: `Failed converting record: ${err.message}`, id: idFromXML, data: foundRecordXML};\n throw new MatchingError(422, {message: `Failed converting record: ${err.message}`, id: idFromXML || '000000000', data: foundRecordXML});\n }\n }\n });\n });\n }\n };\n\n function checkMaxedQuery(query, total, serverMaxResult) {\n // eslint-disable-next-line functional/no-conditional-statement\n if (total >= serverMaxResult) {\n debug(`WARNING: Query ${query} resulted in ${total} hits which meets the serverMaxResult (${serverMaxResult}) `);\n return query;\n }\n }\n\n\n function getRecordId(record) {\n const [field] = record.get(/^001$/u);\n return field ? field.value : '';\n }\n\n function getRecordIdFromXML(recordXML) {\n //<controlfield tag=\\\"001\\\">015376846</controlfield\n debug(`Cannot yet find possible database record id from recordXML (length ${recordXML.length})`);\n return undefined;\n }\n\n};\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/candidate-search/index.js"],"names":["CandidateSearchError","Error","record","searchSpec","url","maxCandidates","maxRecordsPerRequest","serverMaxResult","MarcRecord","setValidationOptions","subfieldValues","debug","debugData","extend","JSON","stringify","adjustedMaxRecordsPerRequest","inputRecordId","getRecordId","queryList","client","version","retrieveAll","length","queryOffset","resultSetOffset","totalRecords","searchCounter","queryCandidateCounter","queryCounter","maxedQueries","query","records","failures","nextOffset","total","retrieveRecords","newTotalRecords","newQueryCounter","newSearchCounter","newQueryCandidateCounter","maxedQuery","checkMaxedQuery","undefined","newMaxedQueries","concat","queriesLeft","Promise","resolve","reject","promises","searchRetrieve","startRecord","on","err","SruSearchError","recordPromises","allSettled","filtered","filter","r","status","map","value","reason","payload","foundRecordXML","push","handleRecord","foundRecordMarc","MARCXML","from","foundRecordId","id","idFromXML","getRecordIdFromXML","message","MatchingError","data","field","get","recordXML"],"mappings":";;;;;;;;;;;;;AA4BA;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X,KAAzB,EAAgCI,KAAhC,EAAuC5B,eAAvC,EAAwD;AACtD;AACA,QAAI4B,KAAK,IAAI5B,eAAb,EAA8B;AAC5BI,MAAAA,KAAK,CAAE,kBAAiBoB,KAAM,gBAAeI,KAAM,0CAAyC5B,eAAgB,IAAvG,CAAL;AACA,aAAOwB,KAAP;AACD;AACF;;AAGD,WAASb,WAAT,CAAqBhB,MAArB,EAA6B;AAC3B,UAAM,CAAC6E,KAAD,IAAU7E,MAAM,CAAC8E,GAAP,CAAW,QAAX,CAAhB;AACA,WAAOD,KAAK,GAAGA,KAAK,CAAChB,KAAT,GAAiB,EAA7B;AACD;;AAED,WAASY,kBAAT,CAA4BM,SAA5B,EAAuC;AACrC;AACAtE,IAAAA,KAAK,CAAE,sEAAqEsE,SAAS,CAAC1D,MAAO,GAAxF,CAAL;AACA,WAAOoB,SAAP;AACD;AAEF,C","sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\nimport createClient, {SruSearchError} from '@natlibfi/sru-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {MARCXML} from '@natlibfi/marc-record-serializers';\nimport generateQueryList from './query-list';\nimport {Error as MatchingError} from '@natlibfi/melinda-commons';\n\nexport {searchTypes} from './query-list';\n\nexport class CandidateSearchError extends Error {}\n\n// serverMaxResults : maximum size of total search result available from the server, defaults to Aleph's 20000\n\n// eslint-disable-next-line max-statements\nexport default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest = 50, serverMaxResult = 20000}) => {\n MarcRecord.setValidationOptions({subfieldValues: false});\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search');\n const debugData = debug.extend('data');\n\n debugData(`SearchSpec: ${JSON.stringify(searchSpec)}`);\n debugData(`Url: ${url}`);\n debugData(`MaxRecordsPerRequest ${maxRecordsPerRequest}`);\n debugData(`ServerMaxResult: ${serverMaxResult}`);\n debugData(`MaxCandidates: ${maxCandidates}`);\n\n // Do not retrieve more candidates than defined in maxCandidates\n const adjustedMaxRecordsPerRequest = maxRecordsPerRequest >= maxCandidates ? maxCandidates : maxRecordsPerRequest;\n\n const inputRecordId = getRecordId(record);\n const queryList = generateQueryList(record, searchSpec);\n const client = createClient({\n url,\n maxRecordsPerRequest: adjustedMaxRecordsPerRequest,\n version: '2.0',\n retrieveAll: false\n });\n\n debug(`Searching matches for ${inputRecordId}`);\n debug(`Generated queryList ${JSON.stringify(queryList)}`);\n\n // if generateQueryList errored we should throw 422\n\n if (queryList.length === 0) { // eslint-disable-line functional/no-conditional-statement\n throw new CandidateSearchError(`Generated query list contains no queries`);\n }\n\n // state.totalRecords : amount of candidate records available to the current query (undefined, if there was no queries left)\n // state.query : current query (undefined if there was no queries left)\n // state.searchCounter : sequence for current search for current query (undefined, if there we no queries left)\n // state.queryCandidateCounter: amount of candidates (records+failures) retrieved from SRU for matching for current query, including the current record+failure set (undefined if there were no queries left)\n // state.queriesLeft : amount of queries left\n // state.queryCounter : sequence for current query\n // state.maxedQueries : queries that resulted in more than serverMaxResults hits\n\n\n return async ({queryOffset = 0, resultSetOffset = 1, totalRecords = 0, searchCounter = 0, queryCandidateCounter = 0, queryCounter = 0, maxedQueries = []}) => {\n const query = queryList[queryOffset];\n\n if (query) {\n const {records, failures, nextOffset, total} = await retrieveRecords();\n\n // If resultSetOffset === 1 this is the first search for the current query\n debugData(`ResultSetOffset: ${resultSetOffset}`);\n const newTotalRecords = resultSetOffset === 1 ? total : totalRecords;\n const newQueryCounter = resultSetOffset === 1 ? queryCounter + 1 : queryCounter;\n const newSearchCounter = resultSetOffset === 1 ? 1 : searchCounter + 1;\n const newQueryCandidateCounter = resultSetOffset === 1 ? records.length + failures.length : queryCandidateCounter + records.length + failures.length;\n\n const maxedQuery = resultSetOffset === 1 ? checkMaxedQuery(query, total, serverMaxResult) : undefined;\n const newMaxedQueries = maxedQuery ? maxedQueries.concat(maxedQuery) : maxedQueries;\n\n if (typeof nextOffset === 'number') {\n debug(`Next search will be for query ${queryOffset} ${query}, starting from record ${nextOffset}`);\n return {records, failures, queryOffset, resultSetOffset: nextOffset, queriesLeft: queryList.length - (queryOffset + 1), totalRecords: newTotalRecords, query, searchCounter: newSearchCounter, queryCandidateCounter: newQueryCandidateCounter, queryCounter: newQueryCounter, maxedQueries: newMaxedQueries};\n }\n debug(`Query ${queryOffset} ${query} done.`);\n debug(`There are (${queryList.length - (queryOffset + 1)} queries left)`);\n return {records, failures, queryOffset: queryOffset + 1, queriesLeft: queryList.length - (queryOffset + 1), totalRecords: newTotalRecords, query, searchCounter: newSearchCounter, queryCandidateCounter: newQueryCandidateCounter, queryCounter: newQueryCounter, maxedQueries: newMaxedQueries};\n }\n\n debug(`All ${queryList.length} queries done, there's no query for ${queryOffset}`);\n return {records: [], failures: [], queriesLeft: 0, queryCounter, maxedQueries};\n\n function retrieveRecords() {\n return new Promise((resolve, reject) => {\n const promises = [];\n // eslint-disable-next-line functional/no-let\n let totalRecords = 0;\n\n debug(`Searching for candidates with query: ${query} (Offset ${resultSetOffset})`);\n\n client.searchRetrieve(query, {startRecord: resultSetOffset})\n .on('error', err => {\n // eslint-disable-next-line functional/no-conditional-statement\n if (err instanceof SruSearchError) {\n debug(`SRU SruSearchError for query: ${query}: ${err}`);\n reject(new CandidateSearchError(`SRU SruSearchError for query: ${query}: ${err}`));\n }\n debug(`SRU error for query: ${query}: ${err}`);\n reject(new CandidateSearchError(`SRU error for query: ${query}: ${err}`));\n })\n .on('total', total => {\n debug(`Got total: ${total}`);\n totalRecords += total;\n })\n .on('end', async nextOffset => {\n try {\n const recordPromises = await Promise.allSettled(promises);\n debug(`All recordPromises: ${JSON.stringify(recordPromises)}`);\n const filtered = recordPromises.filter(r => r.status === 'fulfilled').map(r => r.value);\n const failures = recordPromises.filter(r => r.status === 'rejected').map(r => ({status: r.reason.status, payload: r.reason.payload}));\n\n debug(`Found ${JSON.stringify(recordPromises)} records`);\n debug(`Found ${filtered.length} convertable candidates`);\n debug(`Found ${failures.length} NON-convertable candidates`);\n debug(`Converted: ${JSON.stringify(filtered)}.`);\n debug(`Not converted: ${JSON.stringify(failures)}.`);\n\n\n resolve({nextOffset, records: filtered, failures, total: totalRecords});\n } catch (err) {\n debug(`Error caught on END`);\n reject(err);\n }\n })\n .on('record', foundRecordXML => {\n promises.push(handleRecord()); // eslint-disable-line functional/immutable-data\n\n async function handleRecord() {\n try {\n const foundRecordMarc = await MARCXML.from(foundRecordXML, {subfieldValues: false});\n const foundRecordId = getRecordId(foundRecordMarc);\n\n return {record: foundRecordMarc, id: foundRecordId};\n } catch (err) {\n // What should this do?\n const idFromXML = getRecordIdFromXML(foundRecordXML);\n debugData(`Failed converting record: ${err.message}, id: ${idFromXML}, data: ${foundRecordXML}`);\n //return {message: `Failed converting record: ${err.message}`, id: idFromXML, data: foundRecordXML};\n throw new MatchingError(422, {message: `Failed converting record: ${err.message}`, id: idFromXML || '000000000', data: foundRecordXML});\n }\n }\n });\n });\n }\n };\n\n function checkMaxedQuery(query, total, serverMaxResult) {\n // eslint-disable-next-line functional/no-conditional-statement\n if (total >= serverMaxResult) {\n debug(`WARNING: Query ${query} resulted in ${total} hits which meets the serverMaxResult (${serverMaxResult}) `);\n return query;\n }\n }\n\n\n function getRecordId(record) {\n const [field] = record.get(/^001$/u);\n return field ? field.value : '';\n }\n\n function getRecordIdFromXML(recordXML) {\n //<controlfield tag=\\\"001\\\">015376846</controlfield\n debug(`Cannot yet find possible database record id from recordXML (length ${recordXML.length})`);\n return undefined;\n }\n\n};\n"],"file":"index.js"}
|
|
@@ -104,7 +104,7 @@ function bibSourceIds(record) {
|
|
|
104
104
|
|
|
105
105
|
function removeSourcePrefix(subfieldValue) {
|
|
106
106
|
const sourcePrefixRegex = /^(?<sourcePrefix>\([A-Za-z0-9-]+\))(?<id>.+)$/u;
|
|
107
|
-
const normalizedValue = subfieldValue.replace(sourcePrefixRegex, '$<id>');
|
|
107
|
+
const normalizedValue = subfieldValue ? subfieldValue.replace(sourcePrefixRegex, '$<id>') : '';
|
|
108
108
|
debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);
|
|
109
109
|
return normalizedValue;
|
|
110
110
|
}
|
|
@@ -112,7 +112,7 @@ function bibSourceIds(record) {
|
|
|
112
112
|
function normalizeSidSubfieldValue(subfieldValue) {
|
|
113
113
|
debugData(`Normalizing ${subfieldValue}`);
|
|
114
114
|
const normalizeAwayRegex = /[- ]/u;
|
|
115
|
-
return subfieldValue.replace(normalizeAwayRegex, '');
|
|
115
|
+
return subfieldValue ? subfieldValue.replace(normalizeAwayRegex, '') : '';
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/candidate-search/query-list/bib.js"],"names":["bibSourceIds","record","debug","debugData","extend","fSids","get","length","JSON","stringify","toSidQueries","sidStrings","getSidStrings","sidQueries","map","toSidString","filter","nonEmptySid","field","createSidString","sfC","sfB","cleanedSfC","removeSourcePrefix","normalizeSidSubfieldValue","cleanedSfB","concat","subfieldValue","sourcePrefixRegex","normalizedValue","replace","normalizeAwayRegex","bibMelindaIds","melindaIds","bibHostComponents","id","getHostId","value","subfields","find","code","test","bibTitle","title","getTitle","booleanStartWords","formatted","trim","slice","useWordSearch","some","word","toLowerCase","startsWith","includes","join","bibStandardIdentifiers","fields","identifiers","toIdentifiers","uniqueIdentifiers","Set","tag","issnIsbnReqExp","otherIdReqExp","sub","undefined"],"mappings":";;;;;;;;;;;AA4BA;;AACA;;AACA;;;;AA7BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMO,SAASA,YAAT,CAAsBC,MAAtB,EAA8B;AAEnC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAQE,QAAMC,KAAK,GAAG,oBAAkB,qEAAlB,CAAd;AACA,QAAMC,SAAS,GAAGD,KAAK,CAACE,MAAN,CAAa,MAAb,CAAlB,CA3BmC,CA4BnC;;AAEAF,EAAAA,KAAK,CAAE,iCAAF,CAAL;AAEA,QAAMG,KAAK,GAAGJ,MAAM,CAACK,GAAP,CAAW,KAAX,CAAd;AACAH,EAAAA,SAAS,CAAE,eAAcE,KAAK,CAACE,MAAO,MAAKC,IAAI,CAACC,SAAL,CAAeJ,KAAf,CAAsB,EAAxD,CAAT;AAEA,SAAOA,KAAK,CAACE,MAAN,GAAe,CAAf,GAAmBG,YAAY,CAACL,KAAD,CAA/B,GAAyC,EAAhD;;AAEA,WAASK,YAAT,CAAsBL,KAAtB,EAA6B;AAC3BH,IAAAA,KAAK,CAAE,wCAAF,CAAL;AAEA,UAAMS,UAAU,GAAGC,aAAa,CAACP,KAAD,CAAhC;;AAEA,QAAIM,UAAU,CAACJ,MAAX,GAAoB,CAAxB,EAA2B;AACzBL,MAAAA,KAAK,CAAE,2CAAF,CAAL;AACA,aAAO,EAAP;AACD;;AAED,UAAMW,UAAU,GAAG,qCAAUF,UAAV,EAAsB,kBAAtB,CAAnB;AAEA,WAAOE,UAAP;;AAEA,aAASD,aAAT,CAAuBP,KAAvB,EAA8B;A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BAAxB;AACA,UAAMC,aAAa,GAAI,mBAAvB;;AAEA,QAAIF,GAAG,KAAK,KAAZ,EAAmB;AACjB,aAAOxB,SAAS,CACbtB,MADI,CACGiD,GAAG,IAAI,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgBX,QAAhB,CAAyBW,GAAG,CAACzB,IAA7B,KAAsCuB,cAAc,CAACtB,IAAf,CAAoBwB,GAAG,CAAC5B,KAAxB,CAAtC,IAAwE4B,GAAG,CAAC5B,KAAJ,KAAc6B,SADhG,EAEJpD,GAFI,CAEA,CAAC;AAACuB,QAAAA;AAAD,OAAD,KAAaA,KAFb,CAAP;AAGD;;AAED,QAAIyB,GAAG,KAAK,KAAZ,EAAmB;AACjB,aAAOxB,SAAS,CACbtB,MADI,CACGiD,GAAG,IAAI,CAAC,GAAD,EAAM,GAAN,EAAWX,QAAX,CAAoBW,GAAG,CAACzB,IAAxB,KAAiCuB,cAAc,CAACtB,IAAf,CAAoBwB,GAAG,CAAC5B,KAAxB,CAAjC,IAAmE4B,GAAG,CAAC5B,KAAJ,KAAc6B,SAD3F,EAEJpD,GAFI,CAEA,CAAC;AAACuB,QAAAA;AAAD,OAAD,KAAaA,KAFb,CAAP;AAGD;;AAED,WAAOC,SAAS,CACbtB,MADI,CACGiD,GAAG,IAAI,CAAC,GAAD,EAAM,GAAN,EAAWX,QAAX,CAAoBW,GAAG,CAACzB,IAAxB,KAAiCwB,aAAa,CAACvB,IAAd,CAAmBwB,GAAG,CAAC5B,KAAvB,CAAjC,IAAkE4B,GAAG,CAAC5B,KAAJ,KAAc6B,SAD1F,EAEJpD,GAFI,CAEA,CAAC;AAACuB,MAAAA;AAAD,KAAD,KAAaA,KAFb,CAAP;AAGD;AACF","sourcesContent":["\n/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\nimport createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils';\nimport {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues} from '../../matching-utils';\n\n\nexport function bibSourceIds(record) {\n\n /* Melinda's SRU-index melinda.sourceid includes source IDs from SID fields in Melinda records\n SID-fields in Melinda have sf $c with local id and sf $b with a code for the local db:\n\n SID__ $c 123457 $b helka\n SID__ $c (ANDL100020)1077305 $b sata\n SID__ $c VER999999 $ FI-KV\n SID__ $c /10024/508126 $ REPO_THESEUS\n\n In melinda.sourceid -index case is kept, sourceprefixes in brackets and hyphens are normalized away:\n Note: slashes are not normalized away, but a SRU-search-string including slashes needs to be quoted\n\n 1234567helka\n 1077305sata\n VER999999FIKV\n /10024/508126REPO_THESEUS\n\n Note: All Melinda records that have a matching records in a local db do NOT have SID for that local records,\n existence of a SID field depends on how the record has been added to Melinda and how it has been handled\n afterwards. SIDs are also not reliably maintained. A record might or might not have a SID for a local db\n after the matching record is removed from the local db.\n\n */\n\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:source-ids');\n const debugData = debug.extend('data');\n //const debugInfo = debug.extend('info');\n\n debug(`Creating queries for sourceid's`);\n\n const fSids = record.get('SID');\n debugData(`SID-fields (${fSids.length}): ${JSON.stringify(fSids)}`);\n\n return fSids.length > 0 ? toSidQueries(fSids) : [];\n\n function toSidQueries(fSids) {\n debug(`Creating actual queries for sourceid's`);\n\n const sidStrings = getSidStrings(fSids);\n\n if (sidStrings.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n const sidQueries = toQueries(sidStrings, 'melinda.sourceid');\n\n return sidQueries;\n\n function getSidStrings(fSids) {\n debug(`Getting Sid strings from SID fields`);\n\n // Map SID fields to valid sidStrings, filter out empty strings\n const sidStrings = fSids.map(toSidString).filter(nonEmptySid => nonEmptySid);\n return sidStrings;\n\n function toSidString(field) {\n debug(`Getting string from a field`);\n\n return validateSidFieldSubfieldCounts(field) ? createSidString(field) : '';\n\n function createSidString(field) {\n debug(`Creating string from a field`);\n const [sfC] = getSubfieldValues(field, 'c');\n const [sfB] = getSubfieldValues(field, 'b');\n\n const cleanedSfC = removeSourcePrefix(normalizeSidSubfieldValue(sfC));\n const cleanedSfB = normalizeSidSubfieldValue(sfB);\n\n debugData(`${JSON.stringify(sfC)} + ${JSON.stringify(sfB)}`);\n return cleanedSfC.concat(cleanedSfB);\n }\n\n function removeSourcePrefix(subfieldValue) {\n const sourcePrefixRegex = (/^(?<sourcePrefix>\\([A-Za-z0-9-]+\\))(?<id>.+)$/u);\n const normalizedValue = subfieldValue.replace(sourcePrefixRegex, '$<id>');\n debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);\n return normalizedValue;\n }\n\n function normalizeSidSubfieldValue(subfieldValue) {\n debugData(`Normalizing ${subfieldValue}`);\n const normalizeAwayRegex = (/[- ]/u);\n return subfieldValue.replace(normalizeAwayRegex, '');\n }\n\n }\n }\n }\n}\n\nexport function bibMelindaIds(record) {\n // Melinda's SRU-index melinda.melindaid includes f001 controlnumbers and old Melinda-IDs from f035z's for all non-deleted Melinda-records\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibMelindaIds');\n const debugData = debug.extend('data');\n debug(`Creating queries for MelindaIds`);\n\n // Note: Melinda-ID's for search queries are created just from records f035a's and f035z's\n // Both (FI-MELINDA)- and FCC-prefixed forms are found\n // f001 controlnumber is not currently included, even if record's f003 is FI-MELINDA\n const melindaIds = getMelindaIdsF035(record);\n\n debugData(`Unique identifiers (${melindaIds.length}): ${JSON.stringify(melindaIds)}`);\n\n if (melindaIds.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(melindaIds, 'melinda.melindaid');\n}\n\n\n// bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05\n// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?\nexport function bibHostComponents(record) {\n const id = getHostId();\n return id ? [`melinda.partsofhost=${id}`] : [];\n\n function getHostId() {\n const [field] = record.get(/^773$/u);\n\n if (field) {\n const {value} = field.subfields.find(({code}) => code === 'w') || {};\n\n if (value && (/^\\(FI-MELINDA\\)/u).test(value)) {\n return value.replace(/^\\(FI-MELINDA\\)/u, '');\n }\n\n if (value && (/^\\(FIN01\\)/u).test(value)) {\n return value.replace(/^\\(FIN01\\)/u, '');\n }\n\n return false;\n }\n return false;\n }\n}\n\n// SRU search dc.title with a search phrase starting with ^ maps currently in Melinda to\n// (probably) to *headings* index TIT\n// - Aleph cannot currently handle headings searches starting with a boolean - in these cases use word search\n\n// Headings index TIT drops articles etc. from the start of the title according to the filing indicator\n// Currently filing indicator is not implemented - if the title starts with an article and the Melinda\n// record is correctly catalogued using a filing indicator -> dc.title search won't match\n\nexport function bibTitle(record) {\n const title = getTitle();\n const booleanStartWords = ['and', 'or', 'nor', 'not'];\n\n if (title) {\n const formatted = title\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n // use word search for titles starting with a boolean\n const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));\n // Prevent too many matches by having a minimum length requirement\n return formatted.length >= 5 ? [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`] : [];\n }\n\n return [];\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n return field.subfields\n .filter(({code}) => ['a', 'b'].includes(code))\n .map(({value}) => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n }\n return false;\n }\n}\n\n// eslint-disable-next-line max-statements\nexport function bibStandardIdentifiers(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');\n const debugData = debug.extend('data');\n debug(`Creating queries for standard identifiers`);\n\n const fields = record.get(/^(?<def>020|022|024)$/u);\n const identifiers = [].concat(...fields.map(toIdentifiers));\n const uniqueIdentifiers = [...new Set(identifiers)];\n\n debugData(`Standard identifier fields: ${JSON.stringify(fields)}`);\n debugData(`Identifiers (${identifiers.length}): ${JSON.stringify(identifiers)}`);\n debugData(`Unique identifiers (${uniqueIdentifiers.length}): ${JSON.stringify(uniqueIdentifiers)}`);\n\n if (uniqueIdentifiers.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(uniqueIdentifiers, 'dc.identifier');\n\n function toIdentifiers({tag, subfields}) {\n const issnIsbnReqExp = (/^[A-Za-z0-9-]+$/u);\n const otherIdReqExp = (/^[A-Za-z0-9-:]+$/u);\n\n if (tag === '022') {\n return subfields\n .filter(sub => ['a', 'z', 'y'].includes(sub.code) && issnIsbnReqExp.test(sub.value) && sub.value !== undefined)\n .map(({value}) => value);\n }\n\n if (tag === '020') {\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && issnIsbnReqExp.test(sub.value) && sub.value !== undefined)\n .map(({value}) => value);\n }\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && otherIdReqExp.test(sub.value) && sub.value !== undefined)\n .map(({value}) => value);\n }\n}\n"],"file":"bib.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/candidate-search/query-list/bib.js"],"names":["bibSourceIds","record","debug","debugData","extend","fSids","get","length","JSON","stringify","toSidQueries","sidStrings","getSidStrings","sidQueries","map","toSidString","filter","nonEmptySid","field","createSidString","sfC","sfB","cleanedSfC","removeSourcePrefix","normalizeSidSubfieldValue","cleanedSfB","concat","subfieldValue","sourcePrefixRegex","normalizedValue","replace","normalizeAwayRegex","bibMelindaIds","melindaIds","bibHostComponents","id","getHostId","value","subfields","find","code","test","bibTitle","title","getTitle","booleanStartWords","formatted","trim","slice","useWordSearch","some","word","toLowerCase","startsWith","includes","join","bibStandardIdentifiers","fields","identifiers","toIdentifiers","uniqueIdentifiers","Set","tag","issnIsbnReqExp","otherIdReqExp","sub","undefined"],"mappings":";;;;;;;;;;;AA4BA;;AACA;;AACA;;;;AA7BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMO,SAASA,YAAT,CAAsBC,MAAtB,EAA8B;AAEnC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAQE,QAAMC,KAAK,GAAG,oBAAkB,qEAAlB,CAAd;AACA,QAAMC,SAAS,GAAGD,KAAK,CAACE,MAAN,CAAa,MAAb,CAAlB,CA3BmC,CA4BnC;;AAEAF,EAAAA,KAAK,CAAE,iCAAF,CAAL;AAEA,QAAMG,KAAK,GAAGJ,MAAM,CAACK,GAAP,CAAW,KAAX,CAAd;AACAH,EAAAA,SAAS,CAAE,eAAcE,KAAK,CAACE,MAAO,MAAKC,IAAI,CAACC,SAAL,CAAeJ,KAAf,CAAsB,EAAxD,CAAT;AAEA,SAAOA,KAAK,CAACE,MAAN,GAAe,CAAf,GAAmBG,YAAY,CAACL,KAAD,CAA/B,GAAyC,EAAhD;;AAEA,WAASK,YAAT,CAAsBL,KAAtB,EAA6B;AAC3BH,IAAAA,KAAK,CAAE,wCAAF,CAAL;AAEA,UAAMS,UAAU,GAAGC,aAAa,CAACP,KAAD,CAAhC;;AAEA,QAAIM,UAAU,CAACJ,MAAX,GAAoB,CAAxB,EAA2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EJpD,GAFI,CAEA,CAAC;AAACuB,MAAAA;AAAD,KAAD,KAAaA,KAFb,CAAP;AAGD;AACF","sourcesContent":["\n/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\nimport createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils';\nimport {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues} from '../../matching-utils';\n\n\nexport function bibSourceIds(record) {\n\n /* Melinda's SRU-index melinda.sourceid includes source IDs from SID fields in Melinda records\n SID-fields in Melinda have sf $c with local id and sf $b with a code for the local db:\n\n SID__ $c 123457 $b helka\n SID__ $c (ANDL100020)1077305 $b sata\n SID__ $c VER999999 $ FI-KV\n SID__ $c /10024/508126 $ REPO_THESEUS\n\n In melinda.sourceid -index case is kept, sourceprefixes in brackets and hyphens are normalized away:\n Note: slashes are not normalized away, but a SRU-search-string including slashes needs to be quoted\n\n 1234567helka\n 1077305sata\n VER999999FIKV\n /10024/508126REPO_THESEUS\n\n Note: All Melinda records that have a matching records in a local db do NOT have SID for that local records,\n existence of a SID field depends on how the record has been added to Melinda and how it has been handled\n afterwards. SIDs are also not reliably maintained. A record might or might not have a SID for a local db\n after the matching record is removed from the local db.\n\n */\n\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:source-ids');\n const debugData = debug.extend('data');\n //const debugInfo = debug.extend('info');\n\n debug(`Creating queries for sourceid's`);\n\n const fSids = record.get('SID');\n debugData(`SID-fields (${fSids.length}): ${JSON.stringify(fSids)}`);\n\n return fSids.length > 0 ? toSidQueries(fSids) : [];\n\n function toSidQueries(fSids) {\n debug(`Creating actual queries for sourceid's`);\n\n const sidStrings = getSidStrings(fSids);\n\n if (sidStrings.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n const sidQueries = toQueries(sidStrings, 'melinda.sourceid');\n\n return sidQueries;\n\n function getSidStrings(fSids) {\n debug(`Getting Sid strings from SID fields`);\n\n // Map SID fields to valid sidStrings, filter out empty strings\n const sidStrings = fSids.map(toSidString).filter(nonEmptySid => nonEmptySid);\n return sidStrings;\n\n function toSidString(field) {\n debug(`Getting string from a field`);\n\n return validateSidFieldSubfieldCounts(field) ? createSidString(field) : '';\n\n function createSidString(field) {\n debug(`Creating string from a field`);\n const [sfC] = getSubfieldValues(field, 'c');\n const [sfB] = getSubfieldValues(field, 'b');\n\n const cleanedSfC = removeSourcePrefix(normalizeSidSubfieldValue(sfC));\n const cleanedSfB = normalizeSidSubfieldValue(sfB);\n\n debugData(`${JSON.stringify(sfC)} + ${JSON.stringify(sfB)}`);\n return cleanedSfC.concat(cleanedSfB);\n }\n\n function removeSourcePrefix(subfieldValue) {\n const sourcePrefixRegex = (/^(?<sourcePrefix>\\([A-Za-z0-9-]+\\))(?<id>.+)$/u);\n const normalizedValue = subfieldValue ? subfieldValue.replace(sourcePrefixRegex, '$<id>') : '';\n debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);\n return normalizedValue;\n }\n\n function normalizeSidSubfieldValue(subfieldValue) {\n debugData(`Normalizing ${subfieldValue}`);\n const normalizeAwayRegex = (/[- ]/u);\n return subfieldValue ? subfieldValue.replace(normalizeAwayRegex, '') : '';\n }\n\n }\n }\n }\n}\n\nexport function bibMelindaIds(record) {\n // Melinda's SRU-index melinda.melindaid includes f001 controlnumbers and old Melinda-IDs from f035z's for all non-deleted Melinda-records\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibMelindaIds');\n const debugData = debug.extend('data');\n debug(`Creating queries for MelindaIds`);\n\n // Note: Melinda-ID's for search queries are created just from records f035a's and f035z's\n // Both (FI-MELINDA)- and FCC-prefixed forms are found\n // f001 controlnumber is not currently included, even if record's f003 is FI-MELINDA\n const melindaIds = getMelindaIdsF035(record);\n\n debugData(`Unique identifiers (${melindaIds.length}): ${JSON.stringify(melindaIds)}`);\n\n if (melindaIds.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(melindaIds, 'melinda.melindaid');\n}\n\n\n// bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05\n// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?\nexport function bibHostComponents(record) {\n const id = getHostId();\n return id ? [`melinda.partsofhost=${id}`] : [];\n\n function getHostId() {\n const [field] = record.get(/^773$/u);\n\n if (field) {\n const {value} = field.subfields.find(({code}) => code === 'w') || {};\n\n if (value && (/^\\(FI-MELINDA\\)/u).test(value)) {\n return value.replace(/^\\(FI-MELINDA\\)/u, '');\n }\n\n if (value && (/^\\(FIN01\\)/u).test(value)) {\n return value.replace(/^\\(FIN01\\)/u, '');\n }\n\n return false;\n }\n return false;\n }\n}\n\n// SRU search dc.title with a search phrase starting with ^ maps currently in Melinda to\n// (probably) to *headings* index TIT\n// - Aleph cannot currently handle headings searches starting with a boolean - in these cases use word search\n\n// Headings index TIT drops articles etc. from the start of the title according to the filing indicator\n// Currently filing indicator is not implemented - if the title starts with an article and the Melinda\n// record is correctly catalogued using a filing indicator -> dc.title search won't match\n\nexport function bibTitle(record) {\n const title = getTitle();\n const booleanStartWords = ['and', 'or', 'nor', 'not'];\n\n if (title) {\n const formatted = title\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n // use word search for titles starting with a boolean\n const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));\n // Prevent too many matches by having a minimum length requirement\n return formatted.length >= 5 ? [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`] : [];\n }\n\n return [];\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n return field.subfields\n .filter(({code}) => ['a', 'b'].includes(code))\n .map(({value}) => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n }\n return false;\n }\n}\n\n// eslint-disable-next-line max-statements\nexport function bibStandardIdentifiers(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');\n const debugData = debug.extend('data');\n debug(`Creating queries for standard identifiers`);\n\n const fields = record.get(/^(?<def>020|022|024)$/u);\n const identifiers = [].concat(...fields.map(toIdentifiers));\n const uniqueIdentifiers = [...new Set(identifiers)];\n\n debugData(`Standard identifier fields: ${JSON.stringify(fields)}`);\n debugData(`Identifiers (${identifiers.length}): ${JSON.stringify(identifiers)}`);\n debugData(`Unique identifiers (${uniqueIdentifiers.length}): ${JSON.stringify(uniqueIdentifiers)}`);\n\n if (uniqueIdentifiers.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(uniqueIdentifiers, 'dc.identifier');\n\n function toIdentifiers({tag, subfields}) {\n const issnIsbnReqExp = (/^[A-Za-z0-9-]+$/u);\n const otherIdReqExp = (/^[A-Za-z0-9-:]+$/u);\n\n if (tag === '022') {\n return subfields\n .filter(sub => ['a', 'z', 'y'].includes(sub.code) && issnIsbnReqExp.test(sub.value) && sub.value !== undefined)\n .map(({value}) => value);\n }\n\n if (tag === '020') {\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && issnIsbnReqExp.test(sub.value) && sub.value !== undefined)\n .map(({value}) => value);\n }\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && otherIdReqExp.test(sub.value) && sub.value !== undefined)\n .map(({value}) => value);\n }\n}\n"],"file":"bib.js"}
|
package/dist/index.js
CHANGED
|
@@ -48,6 +48,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
48
48
|
* for the JavaScript code in this file.
|
|
49
49
|
*
|
|
50
50
|
*/
|
|
51
|
+
//import inspect from 'util';
|
|
51
52
|
var _default = ({
|
|
52
53
|
detection: detectionOptions,
|
|
53
54
|
search: searchOptions,
|
|
@@ -93,7 +94,8 @@ var _default = ({
|
|
|
93
94
|
nonMatches = [],
|
|
94
95
|
duplicateCount = 0,
|
|
95
96
|
nonMatchCount = 0,
|
|
96
|
-
conversionFailures = []
|
|
97
|
+
conversionFailures = [],
|
|
98
|
+
matchErrors = []
|
|
97
99
|
}) {
|
|
98
100
|
debugData(`Starting next matcher iteration.`);
|
|
99
101
|
const {
|
|
@@ -101,7 +103,7 @@ var _default = ({
|
|
|
101
103
|
failures,
|
|
102
104
|
...state
|
|
103
105
|
} = await search(initialState);
|
|
104
|
-
debugData(`Current state: ${JSON.stringify(state)}, matches: ${matches.length}, candidateCount: ${candidateCount}, nonMatches: ${nonMatches.length}, nonMatchCount: ${nonMatchCount}, conversionFailures: ${conversionFailures}`);
|
|
106
|
+
debugData(`Current state: ${JSON.stringify(state)}, matches: ${matches.length}, candidateCount: ${candidateCount}, nonMatches: ${nonMatches.length}, nonMatchCount: ${nonMatchCount}, conversionFailures: ${conversionFailures}, matchErrors: ${matchErrors.length}`);
|
|
105
107
|
const recordSetSize = records.length;
|
|
106
108
|
const failureSetSize = failures.length;
|
|
107
109
|
const newCandidateCount = candidateCount + recordSetSize + failureSetSize;
|
|
@@ -121,7 +123,8 @@ var _default = ({
|
|
|
121
123
|
nonMatches,
|
|
122
124
|
nonMatchCount,
|
|
123
125
|
duplicateCount,
|
|
124
|
-
conversionFailures: newConversionFailures
|
|
126
|
+
conversionFailures: newConversionFailures,
|
|
127
|
+
matchErrors
|
|
125
128
|
});
|
|
126
129
|
}
|
|
127
130
|
|
|
@@ -134,7 +137,8 @@ var _default = ({
|
|
|
134
137
|
nonMatchCount,
|
|
135
138
|
candidateCount: newCandidateCount,
|
|
136
139
|
duplicateCount,
|
|
137
|
-
conversionFailures: newConversionFailures
|
|
140
|
+
conversionFailures: newConversionFailures,
|
|
141
|
+
matchErrors
|
|
138
142
|
});
|
|
139
143
|
|
|
140
144
|
function handleRecordSet() {
|
|
@@ -151,8 +155,9 @@ var _default = ({
|
|
|
151
155
|
const newNonMatchCount = nonMatchCount + matchResult.nonMatchCount;
|
|
152
156
|
const {
|
|
153
157
|
newMatches,
|
|
154
|
-
newNonMatches
|
|
155
|
-
|
|
158
|
+
newNonMatches,
|
|
159
|
+
newMatchErrors
|
|
160
|
+
} = handleMatchResult(matchResult, matches, nonMatches, matchErrors);
|
|
156
161
|
|
|
157
162
|
if (maxMatchesFound({
|
|
158
163
|
matches: newMatches,
|
|
@@ -166,7 +171,8 @@ var _default = ({
|
|
|
166
171
|
duplicateCount: newDuplicateCount,
|
|
167
172
|
candidateCount: newCandidateCount,
|
|
168
173
|
nonMatchCount: newNonMatchCount,
|
|
169
|
-
conversionFailures: newConversionFailures
|
|
174
|
+
conversionFailures: newConversionFailures,
|
|
175
|
+
matchErrors: newMatchErrors
|
|
170
176
|
});
|
|
171
177
|
}
|
|
172
178
|
|
|
@@ -179,7 +185,8 @@ var _default = ({
|
|
|
179
185
|
duplicateCount: newDuplicateCount,
|
|
180
186
|
candidateCount: newCandidateCount,
|
|
181
187
|
nonMatchCount: newNonMatchCount,
|
|
182
|
-
conversionFailures: newConversionFailures
|
|
188
|
+
conversionFailures: newConversionFailures,
|
|
189
|
+
matchErrors: newMatchErrors
|
|
183
190
|
});
|
|
184
191
|
}
|
|
185
192
|
|
|
@@ -190,11 +197,12 @@ var _default = ({
|
|
|
190
197
|
nonMatches: newNonMatches,
|
|
191
198
|
duplicateCount: newDuplicateCount,
|
|
192
199
|
nonMatchCount: newNonMatchCount,
|
|
193
|
-
conversionFailures: newConversionFailures
|
|
200
|
+
conversionFailures: newConversionFailures,
|
|
201
|
+
matchErrors: newMatchErrors
|
|
194
202
|
});
|
|
195
203
|
}
|
|
196
204
|
|
|
197
|
-
function handleMatchResult(matchResult, matches, nonMatches) {
|
|
205
|
+
function handleMatchResult(matchResult, matches, nonMatches, matchErrors) {
|
|
198
206
|
debugData(`- Amount of new matches from record set: ${matchResult.matches.length}`); // eslint-disable-next-line functional/no-conditional-statement
|
|
199
207
|
|
|
200
208
|
if (returnNonMatches) {
|
|
@@ -203,15 +211,20 @@ var _default = ({
|
|
|
203
211
|
|
|
204
212
|
const newMatches = matches.concat(returnQuery ? addQuery(matchResult.matches) : matchResult.matches);
|
|
205
213
|
const newNonMatches = returnNonMatches ? nonMatches.concat(returnQuery ? addQuery(matchResult.nonMatches) : matchResult.nonMatches) : [];
|
|
214
|
+
const newMatchErrors = matchErrors.concat(matchResult.matchErrors);
|
|
206
215
|
debugData(`- Total amount of matches: ${newMatches.length}`); // eslint-disable-next-line functional/no-conditional-statement
|
|
207
216
|
|
|
208
217
|
if (returnNonMatches) {
|
|
209
218
|
debugData(`- Total amount of nonMatches: ${newNonMatches.length}`);
|
|
210
219
|
}
|
|
211
220
|
|
|
221
|
+
debugData(`MatchResult: ${JSON.stringify(matchResult)}`);
|
|
222
|
+
debugData(`Old matchErrors: ${JSON.stringify(matchErrors)}, matchErrors from matchResult: ${JSON.stringify(matchResult.matchErrors)}, New matchErrors: ${JSON.stringify(newMatchErrors)}`);
|
|
223
|
+
debugData(`- Total amount of matchErrors: ${newMatchErrors.length}`);
|
|
212
224
|
return {
|
|
213
225
|
newMatches,
|
|
214
|
-
newNonMatches
|
|
226
|
+
newNonMatches,
|
|
227
|
+
newMatchErrors
|
|
215
228
|
};
|
|
216
229
|
}
|
|
217
230
|
|
|
@@ -238,6 +251,7 @@ var _default = ({
|
|
|
238
251
|
// - strategy (if returnStrategy option is true)
|
|
239
252
|
// - treshold (if returnStrategy option is true)
|
|
240
253
|
// - matchQuery (if returnQuery option is true)
|
|
254
|
+
// failures: array of conversionFailures from candidate-search and matchErrors from matchDetection in error format {status, payload: {message, id}} if returnFailures is true
|
|
241
255
|
// we could have here also returnRecords/returnMatchRecords/returnNonMatchRecord options that could be turned false for not to return actual record data
|
|
242
256
|
// matchStatus.status: boolean, true if matcher retrieved and handled all found candidate records, false if it did not
|
|
243
257
|
// matchStatus.stopReason: string ('maxMatches','maxCandidates','maxedQueries','conversionFailures', empty string/undefined), reason for stopping retrieving or handling the candidate records
|
|
@@ -253,18 +267,21 @@ var _default = ({
|
|
|
253
267
|
duplicateCount,
|
|
254
268
|
candidateCount,
|
|
255
269
|
nonMatchCount,
|
|
256
|
-
conversionFailures
|
|
270
|
+
conversionFailures,
|
|
271
|
+
matchErrors
|
|
257
272
|
}) {
|
|
258
273
|
const conversionFailureCount = conversionFailures.length;
|
|
274
|
+
const matchErrorCount = matchErrors.length;
|
|
259
275
|
checkCounts({
|
|
260
276
|
matches,
|
|
261
277
|
nonMatches,
|
|
262
278
|
candidateCount,
|
|
263
279
|
duplicateCount,
|
|
264
280
|
nonMatchCount,
|
|
265
|
-
conversionFailureCount
|
|
281
|
+
conversionFailureCount,
|
|
282
|
+
matchErrorCount
|
|
266
283
|
});
|
|
267
|
-
const matchStatus = getMatchState(state, stopReason, conversionFailureCount); // add nonMatches to result only if returnNonMatches is 'true', otherwise nonMatches have not been gathered
|
|
284
|
+
const matchStatus = getMatchState(state, stopReason, conversionFailureCount, matchErrorCount); // add nonMatches to result only if returnNonMatches is 'true', otherwise nonMatches have not been gathered
|
|
268
285
|
|
|
269
286
|
const matchesResult = returnNonMatches ? {
|
|
270
287
|
matches,
|
|
@@ -274,8 +291,9 @@ var _default = ({
|
|
|
274
291
|
matches,
|
|
275
292
|
matchStatus
|
|
276
293
|
};
|
|
294
|
+
const failures = [...conversionFailures, ...matchErrors];
|
|
277
295
|
const result = returnFailures ? { ...matchesResult,
|
|
278
|
-
conversionFailures
|
|
296
|
+
conversionFailures: failures
|
|
279
297
|
} : matchesResult;
|
|
280
298
|
debugData(`ReturnFailures ${returnFailures}`);
|
|
281
299
|
debugData(`${JSON.stringify(result)}`);
|
|
@@ -287,13 +305,14 @@ var _default = ({
|
|
|
287
305
|
candidateCount,
|
|
288
306
|
duplicateCount,
|
|
289
307
|
nonMatchCount,
|
|
290
|
-
conversionFailureCount
|
|
308
|
+
conversionFailureCount,
|
|
309
|
+
matchErrorCount
|
|
291
310
|
}) {
|
|
292
311
|
const matchCount = matches.length;
|
|
293
312
|
debugData(`Return nonMatches: ${returnNonMatches}`);
|
|
294
313
|
const chosenNonMatchCount = returnNonMatches ? nonMatches.length : nonMatchCount;
|
|
295
314
|
const totalHandled = matchCount + chosenNonMatchCount + duplicateCount;
|
|
296
|
-
debug(`candidateCount: ${candidateCount}, matches: ${matchCount}, nonMatches: ${chosenNonMatchCount}, duplicateCount: ${duplicateCount}, conversionFailureCount: ${conversionFailureCount}`);
|
|
315
|
+
debug(`candidateCount: ${candidateCount}, matches: ${matchCount}, nonMatches: ${chosenNonMatchCount}, duplicateCount: ${duplicateCount}, conversionFailureCount: ${conversionFailureCount}, matchErrorCount: ${matchErrorCount}`);
|
|
297
316
|
debug(`We got result for ${totalHandled} / ${candidateCount} retrieved candidates`);
|
|
298
317
|
|
|
299
318
|
if (totalHandled !== candidateCount) {
|
|
@@ -302,24 +321,28 @@ var _default = ({
|
|
|
302
321
|
}
|
|
303
322
|
|
|
304
323
|
return;
|
|
305
|
-
}
|
|
324
|
+
} // eslint-disable-next-line max-statements
|
|
325
|
+
|
|
306
326
|
|
|
307
|
-
function getMatchState(state, stopReason, conversionFailuresCount) {
|
|
327
|
+
function getMatchState(state, stopReason, conversionFailuresCount, matchErrorCount) {
|
|
308
328
|
debugData(`${JSON.stringify(state)}`);
|
|
309
329
|
debug(`We had ${conversionFailuresCount} retrieved candidates that could not be converted.`);
|
|
330
|
+
debug(`We had ${matchErrorCount} retrieved candidates that errored in matchDetection.`);
|
|
310
331
|
debug(`Queries left ${state.queriesLeft}, Searches for current query left: ${state.resultSetOffset && state.resultSetOffset <= state.totalRecords}, non-retrieved records: ${state.totalRecords - state.queryCandidateCounter}, maxedQueries (${state.maxedQueries.length}): ${state.maxedQueries}`);
|
|
311
332
|
debugData(`StopReason: <${stopReason}>`);
|
|
312
333
|
const searchesLeft = state.resultSetOffset && state.resultSetOffset <= state.totalRecords;
|
|
313
334
|
const nonRetrieved = searchesLeft ? state.totalRecords - state.queryCandidateCounter : 0;
|
|
314
335
|
debugData(`nonRetrieved: ${nonRetrieved}`); // matchStatus.stopReason: string ('maxMatches','maxCandidates','maxedQueries','conversionFailures', empty string/undefined), reason for stopping retrieving or handling the candidate records
|
|
315
|
-
// 'maxMatches' and 'maxCandidates' are in stopReason, 'maxedQueries' and '
|
|
336
|
+
// 'maxMatches' and 'maxCandidates' are in stopReason, 'maxedQueries', 'conversionFailures' and 'matchErrors' are created here
|
|
316
337
|
|
|
317
|
-
if (state.queriesLeft > 0 || nonRetrieved > 0 || state.maxedQueries.length > 0 || conversionFailureCount > 0) {
|
|
338
|
+
if (state.queriesLeft > 0 || nonRetrieved > 0 || state.maxedQueries.length > 0 || conversionFailureCount > 0 || matchErrorCount > 0) {
|
|
318
339
|
const maxedQueriesStopReason = state.maxedQueries.length > 0 ? 'maxedQueries' : undefined;
|
|
319
340
|
const conversionFailuresStopReason = conversionFailureCount > 0 ? 'conversionFailures' : undefined;
|
|
320
|
-
const
|
|
341
|
+
const matchErrorsStopReason = matchErrorCount > 0 ? 'matchErrors' : undefined;
|
|
342
|
+
const newStopReason = stopReason === '' || stopReason === undefined ? maxedQueriesStopReason || conversionFailuresStopReason || matchErrorsStopReason : stopReason;
|
|
321
343
|
debugData(`MaxedQueriesStopReason: <${maxedQueriesStopReason}>`);
|
|
322
344
|
debugData(`ConversionFailureStopReason <${conversionFailuresStopReason}>`);
|
|
345
|
+
debugData(`MatchErrorsStopReason <${matchErrorsStopReason}>`);
|
|
323
346
|
debugData(`NewStopReason: <${newStopReason}>`);
|
|
324
347
|
debug(`Match status: false`);
|
|
325
348
|
return {
|
|
@@ -334,7 +357,12 @@ var _default = ({
|
|
|
334
357
|
stopReason
|
|
335
358
|
};
|
|
336
359
|
}
|
|
337
|
-
}
|
|
360
|
+
} // NOTES:
|
|
361
|
+
// - we could optimize by creating the featureSet for the incoming record once and using it for all database/candidateRecords
|
|
362
|
+
// - if creating the featureSet for the incoming record fails we have an unprocessable entity
|
|
363
|
+
// - if creating the featureSet for a candidate record fails we could skip that candidate - but list the case as a detectionFailure, same as conversionFailures
|
|
364
|
+
// eslint-disable-next-line max-statements
|
|
365
|
+
|
|
338
366
|
|
|
339
367
|
function iterateRecords({
|
|
340
368
|
records,
|
|
@@ -346,7 +374,8 @@ var _default = ({
|
|
|
346
374
|
recordNonMatches = [],
|
|
347
375
|
recordCount = 0,
|
|
348
376
|
recordDuplicateCount = 0,
|
|
349
|
-
recordNonMatchCount = 0
|
|
377
|
+
recordNonMatchCount = 0,
|
|
378
|
+
recordMatchErrors = []
|
|
350
379
|
}) {
|
|
351
380
|
// recordSetSize : total amount of records in the current record set
|
|
352
381
|
// recordCount : amount of records from the current record set that have been handled
|
|
@@ -357,21 +386,57 @@ var _default = ({
|
|
|
357
386
|
// matches : found matches in the current matcher job
|
|
358
387
|
// recordMatches : found matches in the current record set
|
|
359
388
|
// recordNonMatches : found nonMatches in the current record set (only if returnNonMatches setting is true)
|
|
389
|
+
// recordMatchErrors: errored matchDetection in the current record set
|
|
360
390
|
const [candidate] = records;
|
|
361
391
|
const newRecordCount = candidate ? recordCount + 1 : recordCount; // The matcher uses same matchDetection strategy for candidates from all candidate-searches -> matchDetection result for the same candidate is always same
|
|
362
392
|
// Exceptions would happen if the candidate would have been updated in the database between candidate searches
|
|
363
393
|
// Note that if returnNonMatches is false, matcher won't remember candidates that didn't match, so they will be matched again everytime they are retrieved by
|
|
364
394
|
// different candidate search queries. Same candidate search query won't have duplicate records.
|
|
365
395
|
|
|
396
|
+
/* We could optimize and detect all retrieved candidates at once
|
|
397
|
+
const candidateRecords = records.map(record => record.record);
|
|
398
|
+
const recordsIsArray = Array.isArray(candidateRecords);
|
|
399
|
+
debug(`records is an array: ${recordsIsArray}`);
|
|
400
|
+
const result = detect(record, candidateRecords);
|
|
401
|
+
debug(`${JSON.stringify(result)}`);
|
|
402
|
+
*/
|
|
403
|
+
|
|
366
404
|
if (candidate) {
|
|
405
|
+
// eslint-disable-next-line functional/no-conditional-statement
|
|
367
406
|
if (candidateNotInMatches(matches.concat(nonMatches), candidate)) {
|
|
368
407
|
const {
|
|
369
408
|
record: candidateRecord,
|
|
370
409
|
id: candidateId
|
|
371
410
|
} = candidate;
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
411
|
+
|
|
412
|
+
try {
|
|
413
|
+
debug(`Running matchDetection for record ${candidateId} (${newRecordCount}/${recordSetSize})`); // we should handle errors from detection somehow - ie. cases where either record or candidateRecord errors
|
|
414
|
+
|
|
415
|
+
const detectionResult = detect(record, candidateRecord);
|
|
416
|
+
return handleDetectionResult(detectionResult, candidateId, candidateRecord);
|
|
417
|
+
} catch (error) {
|
|
418
|
+
debug(`MatchDetection errored: database record ${candidateId}: ${error}`);
|
|
419
|
+
const matchError = {
|
|
420
|
+
status: 422,
|
|
421
|
+
payload: {
|
|
422
|
+
message: `Matching errored for database record ${candidateId}. ${error.message}.`,
|
|
423
|
+
id: candidateId
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
const newRecordMatchErrors = recordMatchErrors.concat(matchError);
|
|
427
|
+
return iterateRecords({
|
|
428
|
+
records: records.slice(1),
|
|
429
|
+
recordSetSize,
|
|
430
|
+
maxMatches,
|
|
431
|
+
matches,
|
|
432
|
+
recordMatches,
|
|
433
|
+
recordCount: newRecordCount,
|
|
434
|
+
recordNonMatches,
|
|
435
|
+
recordDuplicateCount,
|
|
436
|
+
recordNonMatchCount,
|
|
437
|
+
recordMatchErrors: newRecordMatchErrors
|
|
438
|
+
});
|
|
439
|
+
}
|
|
375
440
|
}
|
|
376
441
|
|
|
377
442
|
return iterateRecords({
|
|
@@ -383,7 +448,8 @@ var _default = ({
|
|
|
383
448
|
recordCount: newRecordCount,
|
|
384
449
|
recordNonMatches,
|
|
385
450
|
recordDuplicateCount: recordDuplicateCount + 1,
|
|
386
|
-
recordNonMatchCount
|
|
451
|
+
recordNonMatchCount,
|
|
452
|
+
recordMatchErrors
|
|
387
453
|
});
|
|
388
454
|
}
|
|
389
455
|
|
|
@@ -392,7 +458,8 @@ var _default = ({
|
|
|
392
458
|
matches: recordMatches,
|
|
393
459
|
nonMatches: returnNonMatches ? recordNonMatches : [],
|
|
394
460
|
duplicateCount: recordDuplicateCount,
|
|
395
|
-
nonMatchCount: recordNonMatchCount
|
|
461
|
+
nonMatchCount: recordNonMatchCount,
|
|
462
|
+
matchErrors: recordMatchErrors
|
|
396
463
|
};
|
|
397
464
|
|
|
398
465
|
function handleDetectionResult(detectionResult, candidateId, candidateRecord) {
|
|
@@ -431,7 +498,8 @@ var _default = ({
|
|
|
431
498
|
recordCount: newRecordCount,
|
|
432
499
|
recordNonMatches,
|
|
433
500
|
recordDuplicateCount,
|
|
434
|
-
recordNonMatchCount: newRecordNonMatchCount
|
|
501
|
+
recordNonMatchCount: newRecordNonMatchCount,
|
|
502
|
+
recordMatchErrors
|
|
435
503
|
});
|
|
436
504
|
}
|
|
437
505
|
|
|
@@ -456,7 +524,8 @@ var _default = ({
|
|
|
456
524
|
matches: newRecordMatches,
|
|
457
525
|
nonMatches: returnNonMatches ? newRecordNonMatches : [],
|
|
458
526
|
duplicateCount: recordDuplicateCount,
|
|
459
|
-
nonMatchCount: newRecordNonMatchCount
|
|
527
|
+
nonMatchCount: newRecordNonMatchCount,
|
|
528
|
+
matchErrors: recordMatchErrors
|
|
460
529
|
};
|
|
461
530
|
}
|
|
462
531
|
|
|
@@ -469,7 +538,8 @@ var _default = ({
|
|
|
469
538
|
recordCount: newRecordCount,
|
|
470
539
|
recordNonMatches: returnNonMatches ? newRecordNonMatches : [],
|
|
471
540
|
duplicateCount: recordDuplicateCount,
|
|
472
|
-
recordNonMatchCount: newRecordNonMatchCount
|
|
541
|
+
recordNonMatchCount: newRecordNonMatchCount,
|
|
542
|
+
matchErrors: recordMatchErrors
|
|
473
543
|
});
|
|
474
544
|
}
|
|
475
545
|
|