@natlibfi/melinda-record-matching 4.3.1-alpha.2 → 4.3.2-alpha.1
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 +61 -7
- package/dist/candidate-search/index.js.map +1 -1
- package/dist/candidate-search/query-list/bib.js +119 -10
- package/dist/candidate-search/query-list/bib.js.map +1 -1
- package/dist/candidate-search/query-list/bib.spec.js +13 -2
- package/dist/candidate-search/query-list/bib.spec.js.map +1 -1
- package/dist/candidate-search/query-list/index.js +12 -0
- package/dist/candidate-search/query-list/index.js.map +1 -1
- package/package.json +1 -1
- package/src/candidate-search/index.js +59 -8
- package/src/candidate-search/query-list/bib.js +76 -10
- package/src/candidate-search/query-list/bib.spec.js +15 -3
- package/src/candidate-search/query-list/index.js +10 -0
|
@@ -25,7 +25,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
25
25
|
*
|
|
26
26
|
* Melinda record matching modules for Javascript
|
|
27
27
|
*
|
|
28
|
-
* Copyright (C) 2020-
|
|
28
|
+
* Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
|
|
29
29
|
*
|
|
30
30
|
* This file is part of melinda-record-matching-js
|
|
31
31
|
*
|
|
@@ -73,7 +73,9 @@ var _default = ({
|
|
|
73
73
|
// Do not retrieve more candidates than defined in maxCandidates
|
|
74
74
|
const adjustedMaxRecordsPerRequest = maxRecordsPerRequest >= maxCandidates ? maxCandidates : maxRecordsPerRequest;
|
|
75
75
|
const inputRecordId = getRecordId(record);
|
|
76
|
-
const
|
|
76
|
+
const queryListResult = (0, _queryList.default)(record, searchSpec);
|
|
77
|
+
const queryList = queryListResult[0]?.queryList ? queryListResult[0].queryList : queryListResult;
|
|
78
|
+
const queryListType = queryListResult[0]?.queryListType ? queryListResult[0].queryListType : undefined;
|
|
77
79
|
const client = (0, _sruClient.default)({
|
|
78
80
|
url,
|
|
79
81
|
maxRecordsPerRequest: adjustedMaxRecordsPerRequest,
|
|
@@ -81,12 +83,28 @@ var _default = ({
|
|
|
81
83
|
retrieveAll: false
|
|
82
84
|
});
|
|
83
85
|
debug(`Searching matches for ${inputRecordId}`);
|
|
84
|
-
|
|
86
|
+
const chosenQueryList = choseQueries(queryList, queryListType);
|
|
85
87
|
|
|
86
|
-
//
|
|
88
|
+
// eslint-disable-next-line require-await
|
|
89
|
+
function choseQueries(queryList, queryListType) {
|
|
90
|
+
debug(`Generated queryList (type: ${queryListType}) ${JSON.stringify(queryList)}`);
|
|
87
91
|
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
// if generateQueryList errored we should throw 422
|
|
93
|
+
if (queryList.length === 0) {
|
|
94
|
+
throw new CandidateSearchError(`Generated query list contains no queries`);
|
|
95
|
+
}
|
|
96
|
+
if (queryListType && queryListType !== 'alternates') {
|
|
97
|
+
throw new CandidateSearchError(`Generated query list has invalid type`);
|
|
98
|
+
}
|
|
99
|
+
if (queryListType === 'alternates' && queryList.length > 1) {
|
|
100
|
+
//const [query] = queryList;
|
|
101
|
+
//const totalResult = await retrieveTotal(query);
|
|
102
|
+
// const totalsForQueries = queryList.map(query => retrieveTotal(query));
|
|
103
|
+
//debug(`${JSON.stringify(totalResult)}`);
|
|
104
|
+
return queryList;
|
|
105
|
+
//return [];
|
|
106
|
+
}
|
|
107
|
+
return queryList;
|
|
90
108
|
}
|
|
91
109
|
|
|
92
110
|
// state.totalRecords : amount of candidate records available to the current query (undefined, if there was no queries left)
|
|
@@ -97,6 +115,7 @@ var _default = ({
|
|
|
97
115
|
// state.queryCounter : sequence for current query
|
|
98
116
|
// state.maxedQueries : queries that resulted in more than serverMaxResults hits
|
|
99
117
|
|
|
118
|
+
// eslint-disable-next-line max-statements
|
|
100
119
|
return async ({
|
|
101
120
|
queryOffset = 0,
|
|
102
121
|
resultSetOffset = 1,
|
|
@@ -106,7 +125,18 @@ var _default = ({
|
|
|
106
125
|
queryCounter = 0,
|
|
107
126
|
maxedQueries = []
|
|
108
127
|
}) => {
|
|
109
|
-
|
|
128
|
+
if (queryListType === 'alternates') {
|
|
129
|
+
debug('Alternates - stop here');
|
|
130
|
+
return {
|
|
131
|
+
records: [],
|
|
132
|
+
failures: [],
|
|
133
|
+
queriesLeft: 0,
|
|
134
|
+
queryCounter,
|
|
135
|
+
maxedQueries
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const query = chosenQueryList[queryOffset];
|
|
139
|
+
debug(`Running query ${JSON.stringify(query)} (${queryOffset})`);
|
|
110
140
|
if (query) {
|
|
111
141
|
const {
|
|
112
142
|
records,
|
|
@@ -234,6 +264,30 @@ var _default = ({
|
|
|
234
264
|
});
|
|
235
265
|
}
|
|
236
266
|
};
|
|
267
|
+
|
|
268
|
+
/*
|
|
269
|
+
async function retrieveTotal(query) {
|
|
270
|
+
debug(`Searching for candidateTotals with query: ${query}`);
|
|
271
|
+
totalClient.searchRetrieve(query)
|
|
272
|
+
.on('error', err => {
|
|
273
|
+
// eslint-disable-next-line functional/no-conditional-statements
|
|
274
|
+
if (err instanceof SruSearchError) {
|
|
275
|
+
debug(`SRU SruSearchError for query: ${query}: ${err}`);
|
|
276
|
+
throw new CandidateSearchError(`SRU SruSearchError for getting total for query: ${query}: ${err}`);
|
|
277
|
+
}
|
|
278
|
+
debug(`SRU error for query: ${query}: ${err}`);
|
|
279
|
+
throw new CandidateSearchError(`SRU error for getting total for query: ${query}: ${err}`);
|
|
280
|
+
})
|
|
281
|
+
.on('total', total => {
|
|
282
|
+
debug(`Got total: ${total}`);
|
|
283
|
+
return {query, total};
|
|
284
|
+
})
|
|
285
|
+
.on('end', end => {
|
|
286
|
+
debug(`End ${JSON.stringify(end)}`);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
*/
|
|
290
|
+
|
|
237
291
|
function checkMaxedQuery(query, total, serverMaxResult) {
|
|
238
292
|
if (total >= serverMaxResult) {
|
|
239
293
|
debug(`WARNING: Query ${query} resulted in ${total} hits which meets the serverMaxResult (${serverMaxResult}) `);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","_sruClient","_interopRequireWildcard","_marcRecord","_marcRecordSerializers","_queryList","_melindaCommons","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","CandidateSearchError","Error","exports","_default","record","searchSpec","url","maxCandidates","maxRecordsPerRequest","serverMaxResult","MarcRecord","setValidationOptions","subfieldValues","debug","createDebugLogger","debugData","extend","JSON","stringify","adjustedMaxRecordsPerRequest","inputRecordId","getRecordId","queryList","generateQueryList","client","createClient","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","status","map","value","reason","payload","recordXML","push","handleRecord","recordMarc","MARCXML","from","recordId","id","idFromXML","getRecordIdFromXML","message","MatchingError","data","field"],"sources":["../../src/candidate-search/index.js"],"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\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) {\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-statements\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 debugData(`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 ${recordPromises.length} records`);\n debug(`Found ${filtered.length} convertable candidates`);\n debug(`Found ${failures.length} NON-convertable candidates`);\n debugData(`Converted: ${JSON.stringify(filtered)}.`);\n debugData(`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', recordXML => {\n promises.push(handleRecord()); // eslint-disable-line functional/immutable-data\n\n async function handleRecord() {\n try {\n const recordMarc = await MARCXML.from(recordXML, {subfieldValues: false});\n const recordId = getRecordId(recordMarc);\n\n return {record: recordMarc, id: recordId};\n } catch (err) {\n // What should this do?\n const idFromXML = getRecordIdFromXML(recordXML);\n debugData(`Failed converting record: ${err.message}, id: ${idFromXML}, data: ${recordXML}`);\n //return {message: `Failed converting record: ${err.message}`, id: idFromXML, data: recordXML};\n throw new MatchingError(422, {message: `Failed converting record: ${err.message}`, id: idFromXML || '000000000', data: recordXML});\n }\n }\n });\n });\n }\n };\n\n function checkMaxedQuery(query, total, serverMaxResult) {\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"],"mappings":";;;;;;;;;;;;AA4BA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,sBAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAH,uBAAA,CAAAF,OAAA;AACA,IAAAM,eAAA,GAAAN,OAAA;AAAiE,SAAAO,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cA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,CAAC+E,KAAK,CAAC,GAAG/E,MAAM,CAAClB,GAAG,CAAC,QAAQ,CAAC;IACpC,OAAOiG,KAAK,GAAGA,KAAK,CAAChB,KAAK,GAAG,EAAE;EACjC;EAEA,SAASY,kBAAkBA,CAACT,SAAS,EAAE;IACrC;IACAzD,KAAK,CAAE,sEAAqEyD,SAAS,CAAC1C,MAAO,GAAE,CAAC;IAChG,OAAOoB,SAAS;EAClB;AAEF,CAAC;AAAA9C,OAAA,CAAAlB,OAAA,GAAAmB,QAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","_sruClient","_interopRequireWildcard","_marcRecord","_marcRecordSerializers","_queryList","_melindaCommons","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","CandidateSearchError","Error","exports","_default","record","searchSpec","url","maxCandidates","maxRecordsPerRequest","serverMaxResult","MarcRecord","setValidationOptions","subfieldValues","debug","createDebugLogger","debugData","extend","JSON","stringify","adjustedMaxRecordsPerRequest","inputRecordId","getRecordId","queryListResult","generateQueryList","queryList","queryListType","undefined","client","createClient","version","retrieveAll","chosenQueryList","choseQueries","length","queryOffset","resultSetOffset","totalRecords","searchCounter","queryCandidateCounter","queryCounter","maxedQueries","records","failures","queriesLeft","query","nextOffset","total","retrieveRecords","newTotalRecords","newQueryCounter","newSearchCounter","newQueryCandidateCounter","maxedQuery","checkMaxedQuery","newMaxedQueries","concat","Promise","resolve","reject","promises","searchRetrieve","startRecord","on","err","SruSearchError","recordPromises","allSettled","filtered","filter","status","map","value","reason","payload","recordXML","push","handleRecord","recordMarc","MARCXML","from","recordId","id","idFromXML","getRecordIdFromXML","message","MatchingError","data","field"],"sources":["../../src/candidate-search/index.js"],"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-2023 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\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 queryListResult = generateQueryList(record, searchSpec);\n const queryList = queryListResult[0]?.queryList ? queryListResult[0].queryList : queryListResult;\n const queryListType = queryListResult[0]?.queryListType ? queryListResult[0].queryListType : undefined;\n\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 const chosenQueryList = choseQueries(queryList, queryListType);\n\n // eslint-disable-next-line require-await\n function choseQueries(queryList, queryListType) {\n debug(`Generated queryList (type: ${queryListType}) ${JSON.stringify(queryList)}`);\n\n // if generateQueryList errored we should throw 422\n if (queryList.length === 0) {\n throw new CandidateSearchError(`Generated query list contains no queries`);\n }\n\n if (queryListType && queryListType !== 'alternates') {\n throw new CandidateSearchError(`Generated query list has invalid type`);\n }\n\n if (queryListType === 'alternates' && queryList.length > 1) {\n //const [query] = queryList;\n //const totalResult = await retrieveTotal(query);\n // const totalsForQueries = queryList.map(query => retrieveTotal(query));\n //debug(`${JSON.stringify(totalResult)}`);\n return queryList;\n //return [];\n }\n return queryList;\n }\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 // eslint-disable-next-line max-statements\n return async ({queryOffset = 0, resultSetOffset = 1, totalRecords = 0, searchCounter = 0, queryCandidateCounter = 0, queryCounter = 0, maxedQueries = []}) => {\n if (queryListType === 'alternates') {\n debug('Alternates - stop here');\n return {records: [], failures: [], queriesLeft: 0, queryCounter, maxedQueries};\n }\n const query = chosenQueryList[queryOffset];\n debug(`Running query ${JSON.stringify(query)} (${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-statements\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 debugData(`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 ${recordPromises.length} records`);\n debug(`Found ${filtered.length} convertable candidates`);\n debug(`Found ${failures.length} NON-convertable candidates`);\n debugData(`Converted: ${JSON.stringify(filtered)}.`);\n debugData(`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', recordXML => {\n promises.push(handleRecord()); // eslint-disable-line functional/immutable-data\n\n async function handleRecord() {\n try {\n const recordMarc = await MARCXML.from(recordXML, {subfieldValues: false});\n const recordId = getRecordId(recordMarc);\n\n return {record: recordMarc, id: recordId};\n } catch (err) {\n // What should this do?\n const idFromXML = getRecordIdFromXML(recordXML);\n debugData(`Failed converting record: ${err.message}, id: ${idFromXML}, data: ${recordXML}`);\n //return {message: `Failed converting record: ${err.message}`, id: idFromXML, data: recordXML};\n throw new MatchingError(422, {message: `Failed converting record: ${err.message}`, id: idFromXML || '000000000', data: recordXML});\n }\n }\n });\n });\n }\n };\n\n /*\n async function retrieveTotal(query) {\n debug(`Searching for candidateTotals with query: ${query}`);\n totalClient.searchRetrieve(query)\n .on('error', err => {\n // eslint-disable-next-line functional/no-conditional-statements\n if (err instanceof SruSearchError) {\n debug(`SRU SruSearchError for query: ${query}: ${err}`);\n throw new CandidateSearchError(`SRU SruSearchError for getting total for query: ${query}: ${err}`);\n }\n debug(`SRU error for query: ${query}: ${err}`);\n throw new CandidateSearchError(`SRU error for getting total for query: ${query}: ${err}`);\n })\n .on('total', total => {\n debug(`Got total: ${total}`);\n return {query, total};\n })\n .on('end', end => {\n debug(`End ${JSON.stringify(end)}`);\n });\n }\n*/\n\n\n function checkMaxedQuery(query, total, serverMaxResult) {\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 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"],"mappings":";;;;;;;;;;;;AA4BA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,sBAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAH,uBAAA,CAAAF,OAAA;AACA,IAAAM,eAAA,GAAAN,OAAA;AAAiE,SAAAO,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAA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GAAG,EAAE;EACjC;EAEA,SAASY,kBAAkBA,CAACT,SAAS,EAAE;IACrC;IACA7D,KAAK,CAAE,sEAAqE6D,SAAS,CAACzC,MAAO,GAAE,CAAC;IAChG,OAAOP,SAAS;EAClB;AAEF,CAAC;AAAAxB,OAAA,CAAAlB,OAAA,GAAAmB,QAAA"}
|
|
@@ -12,6 +12,9 @@ exports.bibStandardIdentifiers = bibStandardIdentifiers;
|
|
|
12
12
|
exports.bibTitle = bibTitle;
|
|
13
13
|
exports.bibTitleAuthor = bibTitleAuthor;
|
|
14
14
|
exports.bibTitleAuthorPublisher = bibTitleAuthorPublisher;
|
|
15
|
+
exports.bibTitleAuthorYear = bibTitleAuthorYear;
|
|
16
|
+
exports.bibTitleAuthorYearAlternates = bibTitleAuthorYearAlternates;
|
|
17
|
+
exports.bibYear = bibYear;
|
|
15
18
|
var _debug = _interopRequireDefault(require("debug"));
|
|
16
19
|
var _candidateSearchUtils = require("../candidate-search-utils");
|
|
17
20
|
var _matchingUtils = require("../../matching-utils");
|
|
@@ -22,7 +25,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
22
25
|
*
|
|
23
26
|
* Melinda record matching modules for Javascript
|
|
24
27
|
*
|
|
25
|
-
* Copyright (C) 2020-
|
|
28
|
+
* Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
|
|
26
29
|
*
|
|
27
30
|
* This file is part of melinda-record-matching-js
|
|
28
31
|
*
|
|
@@ -44,6 +47,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
44
47
|
*
|
|
45
48
|
*/
|
|
46
49
|
|
|
50
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:query');
|
|
47
51
|
function bibSourceIds(record) {
|
|
48
52
|
/* Melinda's SRU-index melinda.sourceid includes source IDs from SID fields in Melinda records
|
|
49
53
|
SID-fields in Melinda have sf $c with local id and sf $b with a code for the local db:
|
|
@@ -135,7 +139,11 @@ function bibMelindaIds(record) {
|
|
|
135
139
|
// bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05
|
|
136
140
|
// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?
|
|
137
141
|
function bibHostComponents(record) {
|
|
142
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents');
|
|
143
|
+
const debugData = debug.extend('data');
|
|
144
|
+
debug(`Creating queries for hostIds`);
|
|
138
145
|
const id = getHostId();
|
|
146
|
+
debugData(`Found id: ${JSON.stringify(id)}`);
|
|
139
147
|
return (0, _matchingUtils.testStringOrNumber)(id) ? [`melinda.partsofhost=${id}`] : [];
|
|
140
148
|
function getHostId() {
|
|
141
149
|
const [field] = record.get(/^773$/u);
|
|
@@ -173,6 +181,7 @@ function bibTitle(record) {
|
|
|
173
181
|
});
|
|
174
182
|
}
|
|
175
183
|
function bibTitleAuthor(record) {
|
|
184
|
+
debug('bibTitleAuthor');
|
|
176
185
|
// We use onlyTitleLength that is longer than our formatted length to
|
|
177
186
|
// get an author or an publisher always
|
|
178
187
|
return bibTitleAuthorPublisher({
|
|
@@ -180,10 +189,41 @@ function bibTitleAuthor(record) {
|
|
|
180
189
|
onlyTitleLength: 100
|
|
181
190
|
});
|
|
182
191
|
}
|
|
192
|
+
function bibTitleAuthorYear(record) {
|
|
193
|
+
debug('bibTitleAuthorYearAlternates');
|
|
194
|
+
// We use onlyTitleLength that is longer than our formatted length to
|
|
195
|
+
// get an author or an publisher always
|
|
196
|
+
|
|
197
|
+
return bibTitleAuthorPublisher({
|
|
198
|
+
record,
|
|
199
|
+
onlyTitleLength: 100,
|
|
200
|
+
addYear: true
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
function bibTitleAuthorYearAlternates(record) {
|
|
204
|
+
debug('bibTitleAuthorYearAlternates');
|
|
205
|
+
// We use onlyTitleLength that is longer than our formatted length to
|
|
206
|
+
// get an author or an publisher always
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
queryList: bibTitleAuthorPublisher({
|
|
210
|
+
record,
|
|
211
|
+
onlyTitleLength: 100,
|
|
212
|
+
addYear: true,
|
|
213
|
+
alternates: true,
|
|
214
|
+
alternateQueries: []
|
|
215
|
+
}),
|
|
216
|
+
queryListType: 'alternates'
|
|
217
|
+
};
|
|
218
|
+
}
|
|
183
219
|
function bibTitleAuthorPublisher({
|
|
184
220
|
record,
|
|
185
|
-
onlyTitleLength
|
|
221
|
+
onlyTitleLength,
|
|
222
|
+
addYear = false,
|
|
223
|
+
alternates = false,
|
|
224
|
+
alternateQueries = []
|
|
186
225
|
}) {
|
|
226
|
+
debug(`bibTitleAuthorPublisher, onlyTitleLength: ${onlyTitleLength}, addYear: ${addYear}, alternates: ${alternates}`);
|
|
187
227
|
const title = getTitle();
|
|
188
228
|
const booleanStartWords = ['and', 'or', 'nor', 'not'];
|
|
189
229
|
if ((0, _matchingUtils.testStringOrNumber)(title)) {
|
|
@@ -195,43 +235,97 @@ function bibTitleAuthorPublisher({
|
|
|
195
235
|
const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));
|
|
196
236
|
// Prevent too many matches / SRU crashing by having a minimum length
|
|
197
237
|
// Note that currently this fails matching if there are no matches from previous matchers
|
|
198
|
-
if (formatted.length >= onlyTitleLength) {
|
|
238
|
+
if (formatted.length >= onlyTitleLength && !alternates) {
|
|
199
239
|
return [`dc.title="${useWordSearch ? '' : '^'}${formatted}*"`];
|
|
200
240
|
}
|
|
201
241
|
const queryIsOkAlone = formatted.length >= 5;
|
|
202
242
|
|
|
203
243
|
// use word search without ending * also in combination searches to avoid SRU-server crashes [MRA-189]
|
|
204
244
|
const query = `dc.title="${useWordSearch || !queryIsOkAlone ? '' : '^'}${formatted}${queryIsOkAlone ? '*' : ''}"`;
|
|
245
|
+
debug(`query: ${query}`);
|
|
246
|
+
const newAlternateQueries = alternates ? [...alternateQueries, query] : alternateQueries;
|
|
205
247
|
return addAuthorsToSearch({
|
|
206
248
|
query,
|
|
207
|
-
queryIsOkAlone
|
|
249
|
+
queryIsOkAlone,
|
|
250
|
+
addYear,
|
|
251
|
+
alternates,
|
|
252
|
+
alternateQueries: newAlternateQueries
|
|
208
253
|
});
|
|
209
254
|
}
|
|
210
255
|
return [];
|
|
211
256
|
function addAuthorsToSearch({
|
|
212
257
|
query,
|
|
213
|
-
queryIsOkAlone = false
|
|
258
|
+
queryIsOkAlone = false,
|
|
259
|
+
addYear = false,
|
|
260
|
+
alternates = false,
|
|
261
|
+
alternateQueries = []
|
|
214
262
|
}) {
|
|
263
|
+
debug('addAuthorsToSearch');
|
|
215
264
|
const [authorQuery] = bibAuthors(record);
|
|
216
265
|
if (authorQuery !== undefined) {
|
|
217
|
-
|
|
266
|
+
if (addYear) {
|
|
267
|
+
const newAlternateQueries = alternates ? [...alternateQueries, `${authorQuery} AND ${query}`] : alternateQueries;
|
|
268
|
+
return addYearToSearch({
|
|
269
|
+
query: `${authorQuery} AND ${query}`,
|
|
270
|
+
queryIsOkAlone: true,
|
|
271
|
+
alternates,
|
|
272
|
+
alternateQueries: newAlternateQueries
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return alternates ? alternateQueries : [`${authorQuery} AND ${query}`];
|
|
218
276
|
}
|
|
219
277
|
return addPublisherToSearch({
|
|
220
278
|
query,
|
|
221
|
-
queryIsOkAlone
|
|
279
|
+
queryIsOkAlone,
|
|
280
|
+
addYear,
|
|
281
|
+
alternates,
|
|
282
|
+
alternateQueries
|
|
222
283
|
});
|
|
223
284
|
//return [];
|
|
224
285
|
}
|
|
225
286
|
function addPublisherToSearch({
|
|
226
287
|
query,
|
|
227
|
-
queryIsOkAlone = false
|
|
288
|
+
queryIsOkAlone = false,
|
|
289
|
+
addYear = false,
|
|
290
|
+
alternates = false,
|
|
291
|
+
alternateQueries = []
|
|
228
292
|
}) {
|
|
229
293
|
const [publisherQuery] = bibPublishers(record);
|
|
230
294
|
if (publisherQuery !== undefined) {
|
|
231
|
-
|
|
295
|
+
if (addYear) {
|
|
296
|
+
const newAlternateQueries = alternates ? [...alternateQueries, `${publisherQuery} AND ${query}`] : alternateQueries;
|
|
297
|
+
return addYearToSearch({
|
|
298
|
+
query: `${publisherQuery} AND ${query}`,
|
|
299
|
+
queryIsOkAlone: true,
|
|
300
|
+
alternates,
|
|
301
|
+
alternateQueries: newAlternateQueries
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
return alternates ? alternateQueries : [`${publisherQuery} AND ${query}`];
|
|
305
|
+
}
|
|
306
|
+
if (queryIsOkAlone && !addYear) {
|
|
307
|
+
return alternates ? alternateQueries : [`${query}`];
|
|
308
|
+
}
|
|
309
|
+
return addYearToSearch({
|
|
310
|
+
query,
|
|
311
|
+
queryIsOkAlone,
|
|
312
|
+
alternates,
|
|
313
|
+
alternateQueries
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
function addYearToSearch({
|
|
317
|
+
query,
|
|
318
|
+
queryIsOkAlone = false,
|
|
319
|
+
alternates = false,
|
|
320
|
+
alternateQueries = []
|
|
321
|
+
}) {
|
|
322
|
+
const [yearQuery] = bibYear(record);
|
|
323
|
+
if (yearQuery !== undefined) {
|
|
324
|
+
const newAlternateQueries = alternates ? [...alternateQueries, `${yearQuery} AND ${query}`] : alternateQueries;
|
|
325
|
+
return alternates ? newAlternateQueries : [`${yearQuery} AND ${query}`];
|
|
232
326
|
}
|
|
233
327
|
if (queryIsOkAlone) {
|
|
234
|
-
return [`${query}`];
|
|
328
|
+
return alternates ? alternateQueries : [`${query}`];
|
|
235
329
|
}
|
|
236
330
|
return [];
|
|
237
331
|
}
|
|
@@ -330,6 +424,21 @@ function bibPublishers(record) {
|
|
|
330
424
|
return false;
|
|
331
425
|
}
|
|
332
426
|
}
|
|
427
|
+
function bibYear(record) {
|
|
428
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:query:bibYear');
|
|
429
|
+
const debugData = debug.extend('data');
|
|
430
|
+
debug(`Creating query for the publishing year`);
|
|
431
|
+
debugData(record);
|
|
432
|
+
const year = getYear(record);
|
|
433
|
+
if (year) {
|
|
434
|
+
return [`dc.date="${year}"`];
|
|
435
|
+
}
|
|
436
|
+
return [];
|
|
437
|
+
function getYear(record) {
|
|
438
|
+
const value = record.get(/^008$/u)?.[0]?.value || undefined;
|
|
439
|
+
return (0, _matchingUtils.testStringOrNumber)(value) ? String(value).slice(7, 11) : undefined;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
333
442
|
function bibStandardIdentifiers(record) {
|
|
334
443
|
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');
|
|
335
444
|
const debugData = debug.extend('data');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bib.js","names":["_debug","_interopRequireDefault","require","_candidateSearchUtils","_matchingUtils","obj","__esModule","default","bibSourceIds","record","debug","createDebugLogger","debugData","extend","fSids","get","length","JSON","stringify","toSidQueries","sidStrings","getSidStrings","sidQueries","toQueries","map","toSidString","filter","nonEmptySid","field","validateSidFieldSubfieldCounts","createSidString","sfC","getSubfieldValues","sfB","cleanedSfC","removeSourcePrefix","normalizeSidSubfieldValue","cleanedSfB","concat","subfieldValue","sourcePrefixRegex","normalizedValue","testStringOrNumber","String","replace","normalizeAwayRegex","bibMelindaIds","melindaIds","getMelindaIdsF035","bibHostComponents","id","getHostId","value","subfields","find","code","test","bibTitle","bibTitleAuthorPublisher","onlyTitleLength","bibTitleAuthor","title","getTitle","booleanStartWords","formatted","trim","slice","useWordSearch","some","word","toLowerCase","startsWith","queryIsOkAlone","query","addAuthorsToSearch","authorQuery","bibAuthors","undefined","addPublisherToSearch","publisherQuery","bibPublishers","titleString","includes","join","author","getAuthor","authorString","publisher","getPublisher","publisherString","bibStandardIdentifiers","fields","identifiers","toIdentifiers","uniqueIdentifiers","Set","tag","issnIsbnReqExp","otherIdReqExp","sub"],"sources":["../../../src/candidate-search/query-list/bib.js"],"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-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*/\nimport createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils';\nimport {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} 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 = testStringOrNumber(subfieldValue) ? String(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 testStringOrNumber(subfieldValue) ? String(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 testStringOrNumber(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 (testStringOrNumber(value) && (/^\\(FI-MELINDA\\)/u).test(String(value))) {\n return String(value).replace(/^\\(FI-MELINDA\\)/u, '');\n }\n\n if (testStringOrNumber(value) && (/^\\(FIN01\\)/u).test(String(value))) {\n return String(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 // We get author/publisher only when formatted title is shorter than 5 chars\n return bibTitleAuthorPublisher({record, onlyTitleLength: 5});\n}\n\nexport function bibTitleAuthor(record) {\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100});\n}\n\nexport function bibTitleAuthorPublisher({record, onlyTitleLength}) {\n const title = getTitle();\n const booleanStartWords = ['and', 'or', 'nor', 'not'];\n\n if (testStringOrNumber(title)) {\n const formatted = String(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 / SRU crashing by having a minimum length\n // Note that currently this fails matching if there are no matches from previous matchers\n if (formatted.length >= onlyTitleLength) {\n return [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n const queryIsOkAlone = formatted.length >= 5;\n\n // use word search without ending * also in combination searches to avoid SRU-server crashes [MRA-189]\n const query = `dc.title=\"${useWordSearch || !queryIsOkAlone ? '' : '^'}${formatted}${queryIsOkAlone ? '*' : ''}\"`;\n\n return addAuthorsToSearch({query, queryIsOkAlone});\n }\n\n return [];\n\n function addAuthorsToSearch({query, queryIsOkAlone = false}) {\n const [authorQuery] = bibAuthors(record);\n if (authorQuery !== undefined) {\n return [`${authorQuery} AND ${query}`];\n }\n return addPublisherToSearch({query, queryIsOkAlone});\n //return [];\n }\n\n function addPublisherToSearch({query, queryIsOkAlone = false}) {\n const [publisherQuery] = bibPublishers(record);\n if (publisherQuery !== undefined) {\n return [`${publisherQuery} AND ${query}`];\n }\n if (queryIsOkAlone) {\n return [`${query}`];\n }\n return [];\n }\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n const titleString = field.subfields\n //.filter(({code}) => ['a', 'b', 'n', 'p'].includes(code))\n .filter(({code}) => ['a', 'b'].includes(code))\n //.filter(({code}) => ['a'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return titleString;\n }\n return false;\n }\n}\n\nexport function bibAuthors(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibAuthors');\n const debugData = debug.extend('data');\n debug(`Creating query for the first author`);\n //debugData(record);\n\n const author = getAuthor(record);\n const booleanStartWords = ['and', 'or', 'nor', 'not'];\n\n\n if (testStringOrNumber(author)) {\n const formatted = String(author)\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 authors starting with a boolean\n const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));\n // Prevent too many matches by having a minimum length\n debugData(`Author string: ${formatted}`);\n if (formatted.length >= 5) {\n return [`dc.author=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n return [];\n }\n\n return [];\n\n function getAuthor(record) {\n //debugData(record);\n // eslint-disable-next-line prefer-named-capture-group\n const [field] = record.get(/^(100)|(110)|(111)|(700)|(710)|(711)$/u);\n //debugData(field);\n\n if (field) {\n const authorString = field.subfields\n .filter(({code}) => ['a'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return authorString;\n }\n return false;\n }\n}\n\nexport function bibPublishers(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibPublishers');\n const debugData = debug.extend('data');\n debug(`Creating query for the first publisher`);\n //debugData(record);\n\n const publisher = getPublisher(record);\n if (testStringOrNumber(publisher)) {\n const formatted = String(publisher)\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 debugData(`Publisher string: ${formatted}`);\n // use non-wildcard word search from dc.publisher\n return [`dc.publisher=\"${formatted}\"`];\n }\n\n return [];\n\n function getPublisher(record) {\n //debugData(record);\n const [field] = record.get(/^(?:260)|(?:264)$/u);\n //debugData(field);\n\n if (field) {\n const publisherString = field.subfields\n .filter(({code}) => ['b'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return publisherString;\n }\n return false;\n }\n}\n\n\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 // DEVELOP: should we query also f015 and f028?\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) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n if (tag === '020') {\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && otherIdReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n}\n"],"mappings":";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G,CAAC/C,KAAK,CAAC,CAAC,CAAC,CAC5H5B,GAAG,CAAC,CAAC;QAAC4B;MAAK,CAAC,KAAKT,MAAM,CAACS,KAAK,CAAC,CAAC;IACpC;IAEA,IAAI4C,GAAG,KAAK,KAAK,EAAE;MACjB,OAAO3C,SAAS,CACb3B,MAAM,CAACyE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACjB,QAAQ,CAACiB,GAAG,CAAC5C,IAAI,CAAC,IAAI,IAAAb,iCAAkB,EAACyD,GAAG,CAAC/C,KAAK,CAAC,IAAI6C,cAAc,CAACzC,IAAI,CAACb,MAAM,CAACwD,GAAG,CAAC/C,KAAK,CAAC,CAAC,CAAC,CACvH5B,GAAG,CAAC,CAAC;QAAC4B;MAAK,CAAC,KAAKT,MAAM,CAACS,KAAK,CAAC,CAAC;IACpC;IAEA,OAAOC,SAAS,CACb3B,MAAM,CAACyE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACjB,QAAQ,CAACiB,GAAG,CAAC5C,IAAI,CAAC,IAAI,IAAAb,iCAAkB,EAACyD,GAAG,CAAC/C,KAAK,CAAC,IAAI8C,aAAa,CAAC1C,IAAI,CAACb,MAAM,CAACwD,GAAG,CAAC/C,KAAK,CAAC,CAAC,CAAC,CACtH5B,GAAG,CAAC,CAAC;MAAC4B;IAAK,CAAC,KAAKT,MAAM,CAACS,KAAK,CAAC,CAAC;EACpC;AACF"}
|
|
1
|
+
{"version":3,"file":"bib.js","names":["_debug","_interopRequireDefault","require","_candidateSearchUtils","_matchingUtils","obj","__esModule","default","debug","createDebugLogger","bibSourceIds","record","debugData","extend","fSids","get","length","JSON","stringify","toSidQueries","sidStrings","getSidStrings","sidQueries","toQueries","map","toSidString","filter","nonEmptySid","field","validateSidFieldSubfieldCounts","createSidString","sfC","getSubfieldValues","sfB","cleanedSfC","removeSourcePrefix","normalizeSidSubfieldValue","cleanedSfB","concat","subfieldValue","sourcePrefixRegex","normalizedValue","testStringOrNumber","String","replace","normalizeAwayRegex","bibMelindaIds","melindaIds","getMelindaIdsF035","bibHostComponents","id","getHostId","value","subfields","find","code","test","bibTitle","bibTitleAuthorPublisher","onlyTitleLength","bibTitleAuthor","bibTitleAuthorYear","addYear","bibTitleAuthorYearAlternates","queryList","alternates","alternateQueries","queryListType","title","getTitle","booleanStartWords","formatted","trim","slice","useWordSearch","some","word","toLowerCase","startsWith","queryIsOkAlone","query","newAlternateQueries","addAuthorsToSearch","authorQuery","bibAuthors","undefined","addYearToSearch","addPublisherToSearch","publisherQuery","bibPublishers","yearQuery","bibYear","titleString","includes","join","author","getAuthor","authorString","publisher","getPublisher","publisherString","year","getYear","bibStandardIdentifiers","fields","identifiers","toIdentifiers","uniqueIdentifiers","Set","tag","issnIsbnReqExp","otherIdReqExp","sub"],"sources":["../../../src/candidate-search/query-list/bib.js"],"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-2023 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, testStringOrNumber} from '../../matching-utils';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query');\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 = testStringOrNumber(subfieldValue) ? String(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 testStringOrNumber(subfieldValue) ? String(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 debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents');\n const debugData = debug.extend('data');\n debug(`Creating queries for hostIds`);\n\n const id = getHostId();\n debugData(`Found id: ${JSON.stringify(id)}`);\n\n return testStringOrNumber(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 (testStringOrNumber(value) && (/^\\(FI-MELINDA\\)/u).test(String(value))) {\n return String(value).replace(/^\\(FI-MELINDA\\)/u, '');\n }\n\n if (testStringOrNumber(value) && (/^\\(FIN01\\)/u).test(String(value))) {\n return String(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 // We get author/publisher only when formatted title is shorter than 5 chars\n return bibTitleAuthorPublisher({record, onlyTitleLength: 5});\n}\n\nexport function bibTitleAuthor(record) {\n debug('bibTitleAuthor');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100});\n}\n\nexport function bibTitleAuthorYear(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true});\n}\n\nexport function bibTitleAuthorYearAlternates(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n\n return {queryList: bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true, alternates: true, alternateQueries: []}), queryListType: 'alternates'};\n}\n\nexport function bibTitleAuthorPublisher({record, onlyTitleLength, addYear = false, alternates = false, alternateQueries = []}) {\n debug(`bibTitleAuthorPublisher, onlyTitleLength: ${onlyTitleLength}, addYear: ${addYear}, alternates: ${alternates}`);\n const title = getTitle();\n const booleanStartWords = ['and', 'or', 'nor', 'not'];\n\n if (testStringOrNumber(title)) {\n const formatted = String(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 / SRU crashing by having a minimum length\n // Note that currently this fails matching if there are no matches from previous matchers\n if (formatted.length >= onlyTitleLength && !alternates) {\n return [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n const queryIsOkAlone = formatted.length >= 5;\n\n // use word search without ending * also in combination searches to avoid SRU-server crashes [MRA-189]\n const query = `dc.title=\"${useWordSearch || !queryIsOkAlone ? '' : '^'}${formatted}${queryIsOkAlone ? '*' : ''}\"`;\n debug(`query: ${query}`);\n const newAlternateQueries = alternates ? [...alternateQueries, query] : alternateQueries;\n\n return addAuthorsToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries: newAlternateQueries});\n }\n\n return [];\n\n function addAuthorsToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n debug('addAuthorsToSearch');\n const [authorQuery] = bibAuthors(record);\n if (authorQuery !== undefined) {\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${authorQuery} AND ${query}`] : alternateQueries;\n return addYearToSearch({query: `${authorQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [`${authorQuery} AND ${query}`];\n }\n return addPublisherToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries});\n //return [];\n }\n\n function addPublisherToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n const [publisherQuery] = bibPublishers(record);\n if (publisherQuery !== undefined) {\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${publisherQuery} AND ${query}`] : alternateQueries;\n return addYearToSearch({query: `${publisherQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [`${publisherQuery} AND ${query}`];\n }\n if (queryIsOkAlone && !addYear) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return addYearToSearch({query, queryIsOkAlone, alternates, alternateQueries});\n }\n\n function addYearToSearch({query, queryIsOkAlone = false, alternates = false, alternateQueries = []}) {\n const [yearQuery] = bibYear(record);\n if (yearQuery !== undefined) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${yearQuery} AND ${query}`] : alternateQueries;\n return alternates ? newAlternateQueries : [`${yearQuery} AND ${query}`];\n }\n if (queryIsOkAlone) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return [];\n }\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n const titleString = field.subfields\n //.filter(({code}) => ['a', 'b', 'n', 'p'].includes(code))\n .filter(({code}) => ['a', 'b'].includes(code))\n //.filter(({code}) => ['a'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return titleString;\n }\n return false;\n }\n}\n\nexport function bibAuthors(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibAuthors');\n const debugData = debug.extend('data');\n debug(`Creating query for the first author`);\n //debugData(record);\n\n const author = getAuthor(record);\n const booleanStartWords = ['and', 'or', 'nor', 'not'];\n\n\n if (testStringOrNumber(author)) {\n const formatted = String(author)\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 authors starting with a boolean\n const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));\n // Prevent too many matches by having a minimum length\n debugData(`Author string: ${formatted}`);\n if (formatted.length >= 5) {\n return [`dc.author=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n return [];\n }\n\n return [];\n\n function getAuthor(record) {\n //debugData(record);\n // eslint-disable-next-line prefer-named-capture-group\n const [field] = record.get(/^(100)|(110)|(111)|(700)|(710)|(711)$/u);\n //debugData(field);\n\n if (field) {\n const authorString = field.subfields\n .filter(({code}) => ['a'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return authorString;\n }\n return false;\n }\n}\n\nexport function bibPublishers(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibPublishers');\n const debugData = debug.extend('data');\n debug(`Creating query for the first publisher`);\n //debugData(record);\n\n const publisher = getPublisher(record);\n if (testStringOrNumber(publisher)) {\n const formatted = String(publisher)\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 debugData(`Publisher string: ${formatted}`);\n // use non-wildcard word search from dc.publisher\n return [`dc.publisher=\"${formatted}\"`];\n }\n\n return [];\n\n function getPublisher(record) {\n //debugData(record);\n const [field] = record.get(/^(?:260)|(?:264)$/u);\n //debugData(field);\n\n if (field) {\n const publisherString = field.subfields\n .filter(({code}) => ['b'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return publisherString;\n }\n return false;\n }\n}\n\nexport function bibYear(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibYear');\n const debugData = debug.extend('data');\n debug(`Creating query for the publishing year`);\n debugData(record);\n\n const year = getYear(record);\n if (year) {\n return [`dc.date=\"${year}\"`];\n }\n return [];\n\n function getYear(record) {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n return testStringOrNumber(value) ? String(value).slice(7, 11) : undefined;\n }\n}\n\n\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 // DEVELOP: should we query also f015 and f028?\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) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n if (tag === '020') {\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && otherIdReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA4BA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAA8H,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,G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IAAI,CAACb,MAAM,CAACqE,GAAG,CAAC5D,KAAK,CAAC,CAAC,CAAC,CACvH5B,GAAG,CAAC,CAAC;QAAC4B;MAAK,CAAC,KAAKT,MAAM,CAACS,KAAK,CAAC,CAAC;IACpC;IAEA,OAAOC,SAAS,CACb3B,MAAM,CAACsF,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACnB,QAAQ,CAACmB,GAAG,CAACzD,IAAI,CAAC,IAAI,IAAAb,iCAAkB,EAACsE,GAAG,CAAC5D,KAAK,CAAC,IAAI2D,aAAa,CAACvD,IAAI,CAACb,MAAM,CAACqE,GAAG,CAAC5D,KAAK,CAAC,CAAC,CAAC,CACtH5B,GAAG,CAAC,CAAC;MAAC4B;IAAK,CAAC,KAAKT,MAAM,CAACS,KAAK,CAAC,CAAC;EACpC;AACF"}
|
|
@@ -5,6 +5,7 @@ var _fixura = require("@natlibfi/fixura");
|
|
|
5
5
|
var _chai = require("chai");
|
|
6
6
|
var _marcRecord = require("@natlibfi/marc-record");
|
|
7
7
|
var generators = _interopRequireWildcard(require("./bib"));
|
|
8
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
8
9
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
10
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -14,7 +15,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
14
15
|
*
|
|
15
16
|
* Melinda record matching modules for Javascript
|
|
16
17
|
*
|
|
17
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
18
|
+
* Copyright (C) 2020, 2023 University Of Helsinki (The National Library Of Finland)
|
|
18
19
|
*
|
|
19
20
|
* This file is part of melinda-record-matching-js
|
|
20
21
|
*
|
|
@@ -36,6 +37,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
36
37
|
*
|
|
37
38
|
*/
|
|
38
39
|
|
|
40
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents:test');
|
|
41
|
+
const debugData = debug.extend('data');
|
|
39
42
|
describe('candidate-search/query-list/bib/', () => {
|
|
40
43
|
(0, _fixugen.default)({
|
|
41
44
|
path: [__dirname, '..', '..', '..', 'test-fixtures', 'candidate-search', 'query-list', 'bib'],
|
|
@@ -47,6 +50,7 @@ describe('candidate-search/query-list/bib/', () => {
|
|
|
47
50
|
type,
|
|
48
51
|
inputRecord,
|
|
49
52
|
expectedQuery,
|
|
53
|
+
expectedQueryListType,
|
|
50
54
|
enabled = true
|
|
51
55
|
}) => {
|
|
52
56
|
const generate = generators[type];
|
|
@@ -56,7 +60,14 @@ describe('candidate-search/query-list/bib/', () => {
|
|
|
56
60
|
if (!enabled) {
|
|
57
61
|
return;
|
|
58
62
|
}
|
|
59
|
-
|
|
63
|
+
const result = generate(record);
|
|
64
|
+
debugData(`Result: ${JSON.stringify(result)}`);
|
|
65
|
+
if (result.queryListType) {
|
|
66
|
+
(0, _chai.expect)(result.queryList).to.eql(expectedQuery);
|
|
67
|
+
(0, _chai.expect)(result.queryListType).to.eql(expectedQueryListType);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
(0, _chai.expect)(result).to.eql(expectedQuery);
|
|
60
71
|
}
|
|
61
72
|
});
|
|
62
73
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bib.spec.js","names":["_fixugen","_interopRequireDefault","require","_fixura","_chai","_marcRecord","generators","_interopRequireWildcard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","describe","generateTests","path","__dirname","useMetadataFile","fixura","reader","READERS","JSON","callback","type","inputRecord","expectedQuery","enabled","generate","record","MarcRecord","subfieldValues","expect","to","eql"],"sources":["../../../src/candidate-search/query-list/bib.spec.js"],"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 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 generateTests from '@natlibfi/fixugen';\nimport {READERS} from '@natlibfi/fixura';\nimport {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport * as generators from './bib';\n\ndescribe('candidate-search/query-list/bib/', () => {\n generateTests({\n path: [__dirname, '..', '..', '..', 'test-fixtures', 'candidate-search', 'query-list', 'bib'],\n useMetadataFile: true,\n fixura: {\n reader: READERS.JSON\n },\n callback: ({type, inputRecord, expectedQuery, enabled = true}) => {\n const generate = generators[type];\n const record = new MarcRecord(inputRecord, {subfieldValues: false});\n\n if (!enabled) {\n return;\n }\n\n
|
|
1
|
+
{"version":3,"file":"bib.spec.js","names":["_fixugen","_interopRequireDefault","require","_fixura","_chai","_marcRecord","generators","_interopRequireWildcard","_debug","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","debug","createDebugLogger","debugData","extend","describe","generateTests","path","__dirname","useMetadataFile","fixura","reader","READERS","JSON","callback","type","inputRecord","expectedQuery","expectedQueryListType","enabled","generate","record","MarcRecord","subfieldValues","result","stringify","queryListType","expect","queryList","to","eql"],"sources":["../../../src/candidate-search/query-list/bib.spec.js"],"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, 2023 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 generateTests from '@natlibfi/fixugen';\nimport {READERS} from '@natlibfi/fixura';\nimport {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport * as generators from './bib';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents:test');\nconst debugData = debug.extend('data');\n\ndescribe('candidate-search/query-list/bib/', () => {\n generateTests({\n path: [__dirname, '..', '..', '..', 'test-fixtures', 'candidate-search', 'query-list', 'bib'],\n useMetadataFile: true,\n fixura: {\n reader: READERS.JSON\n },\n callback: ({type, inputRecord, expectedQuery, expectedQueryListType, enabled = true}) => {\n const generate = generators[type];\n const record = new MarcRecord(inputRecord, {subfieldValues: false});\n\n if (!enabled) {\n return;\n }\n\n const result = generate(record);\n debugData(`Result: ${JSON.stringify(result)}`);\n\n if (result.queryListType) {\n expect(result.queryList).to.eql(expectedQuery);\n expect(result.queryListType).to.eql(expectedQueryListType);\n return;\n }\n expect(result).to.eql(expectedQuery);\n }\n });\n});\n"],"mappings":";;AA4BA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAC,uBAAA,CAAAL,OAAA;AACA,IAAAM,MAAA,GAAAP,sBAAA,CAAAC,OAAA;AAAsC,SAAAO,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,C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AC,KAAK;MACvF,MAAMC,QAAQ,GAAG5C,UAAU,CAACuC,IAAI,CAAC;MACjC,MAAMM,MAAM,GAAG,IAAIC,sBAAU,CAACN,WAAW,EAAE;QAACO,cAAc,EAAE;MAAK,CAAC,CAAC;MAEnE,IAAI,CAACJ,OAAO,EAAE;QACZ;MACF;MAEA,MAAMK,MAAM,GAAGJ,QAAQ,CAACC,MAAM,CAAC;MAC/BlB,SAAS,CAAE,WAAUU,IAAI,CAACY,SAAS,CAACD,MAAM,CAAE,EAAC,CAAC;MAE9C,IAAIA,MAAM,CAACE,aAAa,EAAE;QACxB,IAAAC,YAAM,EAACH,MAAM,CAACI,SAAS,CAAC,CAACC,EAAE,CAACC,GAAG,CAACb,aAAa,CAAC;QAC9C,IAAAU,YAAM,EAACH,MAAM,CAACE,aAAa,CAAC,CAACG,EAAE,CAACC,GAAG,CAACZ,qBAAqB,CAAC;QAC1D;MACF;MACA,IAAAS,YAAM,EAACH,MAAM,CAAC,CAACK,EAAE,CAACC,GAAG,CAACb,aAAa,CAAC;IACtC;EACF,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.searchTypes = exports.default = void 0;
|
|
7
7
|
var bib = _interopRequireWildcard(require("./bib"));
|
|
8
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
10
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
11
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
12
|
/**
|
|
@@ -35,6 +37,8 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
35
37
|
*
|
|
36
38
|
*/
|
|
37
39
|
|
|
40
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:index');
|
|
41
|
+
const debugData = debug.extend('data');
|
|
38
42
|
const searchTypes = exports.searchTypes = {
|
|
39
43
|
bib: {
|
|
40
44
|
standardIdentifiers: 'bibStandardIdentifiers',
|
|
@@ -43,17 +47,25 @@ const searchTypes = exports.searchTypes = {
|
|
|
43
47
|
// title ( + first author + first publisher if needed)
|
|
44
48
|
titleAuthor: 'bibTitleAuthor',
|
|
45
49
|
// title + first author (or first publisher if no author)
|
|
50
|
+
titleAuthorYear: 'bibTitleAuthorYear',
|
|
51
|
+
// title + first author (or first publisher if no author), publishing year
|
|
52
|
+
titleAuthorYearAlternates: 'bibTitleAuthorYearAlternates',
|
|
53
|
+
// title + first author (or first publisher if no author), publishing year
|
|
46
54
|
melindaId: 'bibMelindaIds',
|
|
47
55
|
sourceIds: 'bibSourceIds'
|
|
56
|
+
//DEVELOP: bibContent: 'bibContent'
|
|
48
57
|
}
|
|
49
58
|
};
|
|
50
59
|
var _default = (record, searchSpec) => {
|
|
51
60
|
const extractors = {
|
|
52
61
|
...bib
|
|
53
62
|
};
|
|
63
|
+
debugData(`extractors: ${JSON.stringify(extractors)}`);
|
|
64
|
+
debugData(`searchSpec: ${JSON.stringify(searchSpec)}`);
|
|
54
65
|
return searchSpec.map(generateQueryExtractor).map(cb => cb(record)).flat();
|
|
55
66
|
function generateQueryExtractor(type) {
|
|
56
67
|
if (extractors[type]) {
|
|
68
|
+
//debugData(`${JSON.stringify(extractors[type])}`);
|
|
57
69
|
return extractors[type];
|
|
58
70
|
}
|
|
59
71
|
throw new Error(`Unknown search type: ${type}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["bib","_interopRequireWildcard","require","
|
|
1
|
+
{"version":3,"file":"index.js","names":["bib","_interopRequireWildcard","require","_debug","_interopRequireDefault","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","debug","createDebugLogger","debugData","extend","searchTypes","exports","standardIdentifiers","hostComponents","title","titleAuthor","titleAuthorYear","titleAuthorYearAlternates","melindaId","sourceIds","_default","record","searchSpec","extractors","JSON","stringify","map","generateQueryExtractor","cb","flat","type","Error"],"sources":["../../../src/candidate-search/query-list/index.js"],"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 * as bib from './bib';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:index');\nconst debugData = debug.extend('data');\n\nexport const searchTypes = {\n bib: {\n standardIdentifiers: 'bibStandardIdentifiers',\n hostComponents: 'bibHostComponents',\n title: 'bibTitle', // title ( + first author + first publisher if needed)\n titleAuthor: 'bibTitleAuthor', // title + first author (or first publisher if no author)\n titleAuthorYear: 'bibTitleAuthorYear', // title + first author (or first publisher if no author), publishing year\n titleAuthorYearAlternates: 'bibTitleAuthorYearAlternates', // title + first author (or first publisher if no author), publishing year\n melindaId: 'bibMelindaIds',\n sourceIds: 'bibSourceIds'\n //DEVELOP: bibContent: 'bibContent'\n }\n};\n\nexport default (record, searchSpec) => {\n const extractors = {...bib};\n debugData(`extractors: ${JSON.stringify(extractors)}`);\n debugData(`searchSpec: ${JSON.stringify(searchSpec)}`);\n\n return searchSpec\n .map(generateQueryExtractor)\n .map(cb => cb(record))\n .flat();\n\n function generateQueryExtractor(type) {\n if (extractors[type]) {\n //debugData(`${JSON.stringify(extractors[type])}`);\n return extractors[type];\n }\n\n throw new Error(`Unknown search type: ${type}`);\n }\n};\n"],"mappings":";;;;;;AA4BA,IAAAA,GAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAsC,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAR,wBAAAQ,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAH,UAAA,SAAAG,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAF,OAAA,EAAAE,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAC,GAAA,CAAAJ,CAAA,UAAAG,CAAA,CAAAE,GAAA,CAAAL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CAACC,MAAM,EAAEC,UAAU,KAAK;EACrC,MAAMC,UAAU,GAAG;IAAC,GAAG5C;EAAG,CAAC;EAC3B6B,SAAS,CAAE,eAAcgB,IAAI,CAACC,SAAS,CAACF,UAAU,CAAE,EAAC,CAAC;EACtDf,SAAS,CAAE,eAAcgB,IAAI,CAACC,SAAS,CAACH,UAAU,CAAE,EAAC,CAAC;EAEtD,OAAOA,UAAU,CACdI,GAAG,CAACC,sBAAsB,CAAC,CAC3BD,GAAG,CAACE,EAAE,IAAIA,EAAE,CAACP,MAAM,CAAC,CAAC,CACrBQ,IAAI,CAAC,CAAC;EAET,SAASF,sBAAsBA,CAACG,IAAI,EAAE;IACpC,IAAIP,UAAU,CAACO,IAAI,CAAC,EAAE;MACpB;MACA,OAAOP,UAAU,CAACO,IAAI,CAAC;IACzB;IAEA,MAAM,IAAIC,KAAK,CAAE,wBAAuBD,IAAK,EAAC,CAAC;EACjD;AACF,CAAC;AAAAnB,OAAA,CAAAzB,OAAA,GAAAkC,QAAA"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020-
|
|
7
|
+
* Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -55,7 +55,10 @@ export default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest =
|
|
|
55
55
|
const adjustedMaxRecordsPerRequest = maxRecordsPerRequest >= maxCandidates ? maxCandidates : maxRecordsPerRequest;
|
|
56
56
|
|
|
57
57
|
const inputRecordId = getRecordId(record);
|
|
58
|
-
const
|
|
58
|
+
const queryListResult = generateQueryList(record, searchSpec);
|
|
59
|
+
const queryList = queryListResult[0]?.queryList ? queryListResult[0].queryList : queryListResult;
|
|
60
|
+
const queryListType = queryListResult[0]?.queryListType ? queryListResult[0].queryListType : undefined;
|
|
61
|
+
|
|
59
62
|
const client = createClient({
|
|
60
63
|
url,
|
|
61
64
|
maxRecordsPerRequest: adjustedMaxRecordsPerRequest,
|
|
@@ -64,14 +67,33 @@ export default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest =
|
|
|
64
67
|
});
|
|
65
68
|
|
|
66
69
|
debug(`Searching matches for ${inputRecordId}`);
|
|
67
|
-
|
|
70
|
+
const chosenQueryList = choseQueries(queryList, queryListType);
|
|
71
|
+
|
|
72
|
+
// eslint-disable-next-line require-await
|
|
73
|
+
function choseQueries(queryList, queryListType) {
|
|
74
|
+
debug(`Generated queryList (type: ${queryListType}) ${JSON.stringify(queryList)}`);
|
|
68
75
|
|
|
69
|
-
|
|
76
|
+
// if generateQueryList errored we should throw 422
|
|
77
|
+
if (queryList.length === 0) {
|
|
78
|
+
throw new CandidateSearchError(`Generated query list contains no queries`);
|
|
79
|
+
}
|
|
70
80
|
|
|
71
|
-
|
|
72
|
-
|
|
81
|
+
if (queryListType && queryListType !== 'alternates') {
|
|
82
|
+
throw new CandidateSearchError(`Generated query list has invalid type`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (queryListType === 'alternates' && queryList.length > 1) {
|
|
86
|
+
//const [query] = queryList;
|
|
87
|
+
//const totalResult = await retrieveTotal(query);
|
|
88
|
+
// const totalsForQueries = queryList.map(query => retrieveTotal(query));
|
|
89
|
+
//debug(`${JSON.stringify(totalResult)}`);
|
|
90
|
+
return queryList;
|
|
91
|
+
//return [];
|
|
92
|
+
}
|
|
93
|
+
return queryList;
|
|
73
94
|
}
|
|
74
95
|
|
|
96
|
+
|
|
75
97
|
// state.totalRecords : amount of candidate records available to the current query (undefined, if there was no queries left)
|
|
76
98
|
// state.query : current query (undefined if there was no queries left)
|
|
77
99
|
// state.searchCounter : sequence for current search for current query (undefined, if there we no queries left)
|
|
@@ -81,8 +103,14 @@ export default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest =
|
|
|
81
103
|
// state.maxedQueries : queries that resulted in more than serverMaxResults hits
|
|
82
104
|
|
|
83
105
|
|
|
106
|
+
// eslint-disable-next-line max-statements
|
|
84
107
|
return async ({queryOffset = 0, resultSetOffset = 1, totalRecords = 0, searchCounter = 0, queryCandidateCounter = 0, queryCounter = 0, maxedQueries = []}) => {
|
|
85
|
-
|
|
108
|
+
if (queryListType === 'alternates') {
|
|
109
|
+
debug('Alternates - stop here');
|
|
110
|
+
return {records: [], failures: [], queriesLeft: 0, queryCounter, maxedQueries};
|
|
111
|
+
}
|
|
112
|
+
const query = chosenQueryList[queryOffset];
|
|
113
|
+
debug(`Running query ${JSON.stringify(query)} (${queryOffset})`);
|
|
86
114
|
|
|
87
115
|
if (query) {
|
|
88
116
|
const {records, failures, nextOffset, total} = await retrieveRecords();
|
|
@@ -173,6 +201,30 @@ export default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest =
|
|
|
173
201
|
}
|
|
174
202
|
};
|
|
175
203
|
|
|
204
|
+
/*
|
|
205
|
+
async function retrieveTotal(query) {
|
|
206
|
+
debug(`Searching for candidateTotals with query: ${query}`);
|
|
207
|
+
totalClient.searchRetrieve(query)
|
|
208
|
+
.on('error', err => {
|
|
209
|
+
// eslint-disable-next-line functional/no-conditional-statements
|
|
210
|
+
if (err instanceof SruSearchError) {
|
|
211
|
+
debug(`SRU SruSearchError for query: ${query}: ${err}`);
|
|
212
|
+
throw new CandidateSearchError(`SRU SruSearchError for getting total for query: ${query}: ${err}`);
|
|
213
|
+
}
|
|
214
|
+
debug(`SRU error for query: ${query}: ${err}`);
|
|
215
|
+
throw new CandidateSearchError(`SRU error for getting total for query: ${query}: ${err}`);
|
|
216
|
+
})
|
|
217
|
+
.on('total', total => {
|
|
218
|
+
debug(`Got total: ${total}`);
|
|
219
|
+
return {query, total};
|
|
220
|
+
})
|
|
221
|
+
.on('end', end => {
|
|
222
|
+
debug(`End ${JSON.stringify(end)}`);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
|
|
176
228
|
function checkMaxedQuery(query, total, serverMaxResult) {
|
|
177
229
|
if (total >= serverMaxResult) {
|
|
178
230
|
debug(`WARNING: Query ${query} resulted in ${total} hits which meets the serverMaxResult (${serverMaxResult}) `);
|
|
@@ -180,7 +232,6 @@ export default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest =
|
|
|
180
232
|
}
|
|
181
233
|
}
|
|
182
234
|
|
|
183
|
-
|
|
184
235
|
function getRecordId(record) {
|
|
185
236
|
const [field] = record.get(/^001$/u);
|
|
186
237
|
return field ? field.value : '';
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Melinda record matching modules for Javascript
|
|
7
7
|
*
|
|
8
|
-
* Copyright (C) 2020-
|
|
8
|
+
* Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
|
|
9
9
|
*
|
|
10
10
|
* This file is part of melinda-record-matching-js
|
|
11
11
|
*
|
|
@@ -30,6 +30,7 @@ import createDebugLogger from 'debug';
|
|
|
30
30
|
import {toQueries} from '../candidate-search-utils';
|
|
31
31
|
import {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} from '../../matching-utils';
|
|
32
32
|
|
|
33
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query');
|
|
33
34
|
|
|
34
35
|
export function bibSourceIds(record) {
|
|
35
36
|
|
|
@@ -150,7 +151,13 @@ export function bibMelindaIds(record) {
|
|
|
150
151
|
// bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05
|
|
151
152
|
// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?
|
|
152
153
|
export function bibHostComponents(record) {
|
|
154
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents');
|
|
155
|
+
const debugData = debug.extend('data');
|
|
156
|
+
debug(`Creating queries for hostIds`);
|
|
157
|
+
|
|
153
158
|
const id = getHostId();
|
|
159
|
+
debugData(`Found id: ${JSON.stringify(id)}`);
|
|
160
|
+
|
|
154
161
|
return testStringOrNumber(id) ? [`melinda.partsofhost=${id}`] : [];
|
|
155
162
|
|
|
156
163
|
function getHostId() {
|
|
@@ -187,12 +194,30 @@ export function bibTitle(record) {
|
|
|
187
194
|
}
|
|
188
195
|
|
|
189
196
|
export function bibTitleAuthor(record) {
|
|
197
|
+
debug('bibTitleAuthor');
|
|
190
198
|
// We use onlyTitleLength that is longer than our formatted length to
|
|
191
199
|
// get an author or an publisher always
|
|
192
200
|
return bibTitleAuthorPublisher({record, onlyTitleLength: 100});
|
|
193
201
|
}
|
|
194
202
|
|
|
195
|
-
export function
|
|
203
|
+
export function bibTitleAuthorYear(record) {
|
|
204
|
+
debug('bibTitleAuthorYearAlternates');
|
|
205
|
+
// We use onlyTitleLength that is longer than our formatted length to
|
|
206
|
+
// get an author or an publisher always
|
|
207
|
+
|
|
208
|
+
return bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function bibTitleAuthorYearAlternates(record) {
|
|
212
|
+
debug('bibTitleAuthorYearAlternates');
|
|
213
|
+
// We use onlyTitleLength that is longer than our formatted length to
|
|
214
|
+
// get an author or an publisher always
|
|
215
|
+
|
|
216
|
+
return {queryList: bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true, alternates: true, alternateQueries: []}), queryListType: 'alternates'};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function bibTitleAuthorPublisher({record, onlyTitleLength, addYear = false, alternates = false, alternateQueries = []}) {
|
|
220
|
+
debug(`bibTitleAuthorPublisher, onlyTitleLength: ${onlyTitleLength}, addYear: ${addYear}, alternates: ${alternates}`);
|
|
196
221
|
const title = getTitle();
|
|
197
222
|
const booleanStartWords = ['and', 'or', 'nor', 'not'];
|
|
198
223
|
|
|
@@ -209,35 +234,58 @@ export function bibTitleAuthorPublisher({record, onlyTitleLength}) {
|
|
|
209
234
|
const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));
|
|
210
235
|
// Prevent too many matches / SRU crashing by having a minimum length
|
|
211
236
|
// Note that currently this fails matching if there are no matches from previous matchers
|
|
212
|
-
if (formatted.length >= onlyTitleLength) {
|
|
237
|
+
if (formatted.length >= onlyTitleLength && !alternates) {
|
|
213
238
|
return [`dc.title="${useWordSearch ? '' : '^'}${formatted}*"`];
|
|
214
239
|
}
|
|
215
240
|
const queryIsOkAlone = formatted.length >= 5;
|
|
216
241
|
|
|
217
242
|
// use word search without ending * also in combination searches to avoid SRU-server crashes [MRA-189]
|
|
218
243
|
const query = `dc.title="${useWordSearch || !queryIsOkAlone ? '' : '^'}${formatted}${queryIsOkAlone ? '*' : ''}"`;
|
|
244
|
+
debug(`query: ${query}`);
|
|
245
|
+
const newAlternateQueries = alternates ? [...alternateQueries, query] : alternateQueries;
|
|
219
246
|
|
|
220
|
-
return addAuthorsToSearch({query, queryIsOkAlone});
|
|
247
|
+
return addAuthorsToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries: newAlternateQueries});
|
|
221
248
|
}
|
|
222
249
|
|
|
223
250
|
return [];
|
|
224
251
|
|
|
225
|
-
function addAuthorsToSearch({query, queryIsOkAlone = false}) {
|
|
252
|
+
function addAuthorsToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {
|
|
253
|
+
debug('addAuthorsToSearch');
|
|
226
254
|
const [authorQuery] = bibAuthors(record);
|
|
227
255
|
if (authorQuery !== undefined) {
|
|
228
|
-
|
|
256
|
+
if (addYear) {
|
|
257
|
+
const newAlternateQueries = alternates ? [...alternateQueries, `${authorQuery} AND ${query}`] : alternateQueries;
|
|
258
|
+
return addYearToSearch({query: `${authorQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});
|
|
259
|
+
}
|
|
260
|
+
return alternates ? alternateQueries : [`${authorQuery} AND ${query}`];
|
|
229
261
|
}
|
|
230
|
-
return addPublisherToSearch({query, queryIsOkAlone});
|
|
262
|
+
return addPublisherToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries});
|
|
231
263
|
//return [];
|
|
232
264
|
}
|
|
233
265
|
|
|
234
|
-
function addPublisherToSearch({query, queryIsOkAlone = false}) {
|
|
266
|
+
function addPublisherToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {
|
|
235
267
|
const [publisherQuery] = bibPublishers(record);
|
|
236
268
|
if (publisherQuery !== undefined) {
|
|
237
|
-
|
|
269
|
+
if (addYear) {
|
|
270
|
+
const newAlternateQueries = alternates ? [...alternateQueries, `${publisherQuery} AND ${query}`] : alternateQueries;
|
|
271
|
+
return addYearToSearch({query: `${publisherQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});
|
|
272
|
+
}
|
|
273
|
+
return alternates ? alternateQueries : [`${publisherQuery} AND ${query}`];
|
|
274
|
+
}
|
|
275
|
+
if (queryIsOkAlone && !addYear) {
|
|
276
|
+
return alternates ? alternateQueries : [`${query}`];
|
|
277
|
+
}
|
|
278
|
+
return addYearToSearch({query, queryIsOkAlone, alternates, alternateQueries});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function addYearToSearch({query, queryIsOkAlone = false, alternates = false, alternateQueries = []}) {
|
|
282
|
+
const [yearQuery] = bibYear(record);
|
|
283
|
+
if (yearQuery !== undefined) {
|
|
284
|
+
const newAlternateQueries = alternates ? [...alternateQueries, `${yearQuery} AND ${query}`] : alternateQueries;
|
|
285
|
+
return alternates ? newAlternateQueries : [`${yearQuery} AND ${query}`];
|
|
238
286
|
}
|
|
239
287
|
if (queryIsOkAlone) {
|
|
240
|
-
return [`${query}`];
|
|
288
|
+
return alternates ? alternateQueries : [`${query}`];
|
|
241
289
|
}
|
|
242
290
|
return [];
|
|
243
291
|
}
|
|
@@ -351,6 +399,24 @@ export function bibPublishers(record) {
|
|
|
351
399
|
}
|
|
352
400
|
}
|
|
353
401
|
|
|
402
|
+
export function bibYear(record) {
|
|
403
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibYear');
|
|
404
|
+
const debugData = debug.extend('data');
|
|
405
|
+
debug(`Creating query for the publishing year`);
|
|
406
|
+
debugData(record);
|
|
407
|
+
|
|
408
|
+
const year = getYear(record);
|
|
409
|
+
if (year) {
|
|
410
|
+
return [`dc.date="${year}"`];
|
|
411
|
+
}
|
|
412
|
+
return [];
|
|
413
|
+
|
|
414
|
+
function getYear(record) {
|
|
415
|
+
const value = record.get(/^008$/u)?.[0]?.value || undefined;
|
|
416
|
+
return testStringOrNumber(value) ? String(value).slice(7, 11) : undefined;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
354
420
|
|
|
355
421
|
export function bibStandardIdentifiers(record) {
|
|
356
422
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020, 2023 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -31,6 +31,10 @@ import {READERS} from '@natlibfi/fixura';
|
|
|
31
31
|
import {expect} from 'chai';
|
|
32
32
|
import {MarcRecord} from '@natlibfi/marc-record';
|
|
33
33
|
import * as generators from './bib';
|
|
34
|
+
import createDebugLogger from 'debug';
|
|
35
|
+
|
|
36
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents:test');
|
|
37
|
+
const debugData = debug.extend('data');
|
|
34
38
|
|
|
35
39
|
describe('candidate-search/query-list/bib/', () => {
|
|
36
40
|
generateTests({
|
|
@@ -39,7 +43,7 @@ describe('candidate-search/query-list/bib/', () => {
|
|
|
39
43
|
fixura: {
|
|
40
44
|
reader: READERS.JSON
|
|
41
45
|
},
|
|
42
|
-
callback: ({type, inputRecord, expectedQuery, enabled = true}) => {
|
|
46
|
+
callback: ({type, inputRecord, expectedQuery, expectedQueryListType, enabled = true}) => {
|
|
43
47
|
const generate = generators[type];
|
|
44
48
|
const record = new MarcRecord(inputRecord, {subfieldValues: false});
|
|
45
49
|
|
|
@@ -47,7 +51,15 @@ describe('candidate-search/query-list/bib/', () => {
|
|
|
47
51
|
return;
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
const result = generate(record);
|
|
55
|
+
debugData(`Result: ${JSON.stringify(result)}`);
|
|
56
|
+
|
|
57
|
+
if (result.queryListType) {
|
|
58
|
+
expect(result.queryList).to.eql(expectedQuery);
|
|
59
|
+
expect(result.queryListType).to.eql(expectedQueryListType);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
expect(result).to.eql(expectedQuery);
|
|
51
63
|
}
|
|
52
64
|
});
|
|
53
65
|
});
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import * as bib from './bib';
|
|
30
|
+
import createDebugLogger from 'debug';
|
|
31
|
+
|
|
32
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:index');
|
|
33
|
+
const debugData = debug.extend('data');
|
|
30
34
|
|
|
31
35
|
export const searchTypes = {
|
|
32
36
|
bib: {
|
|
@@ -34,13 +38,18 @@ export const searchTypes = {
|
|
|
34
38
|
hostComponents: 'bibHostComponents',
|
|
35
39
|
title: 'bibTitle', // title ( + first author + first publisher if needed)
|
|
36
40
|
titleAuthor: 'bibTitleAuthor', // title + first author (or first publisher if no author)
|
|
41
|
+
titleAuthorYear: 'bibTitleAuthorYear', // title + first author (or first publisher if no author), publishing year
|
|
42
|
+
titleAuthorYearAlternates: 'bibTitleAuthorYearAlternates', // title + first author (or first publisher if no author), publishing year
|
|
37
43
|
melindaId: 'bibMelindaIds',
|
|
38
44
|
sourceIds: 'bibSourceIds'
|
|
45
|
+
//DEVELOP: bibContent: 'bibContent'
|
|
39
46
|
}
|
|
40
47
|
};
|
|
41
48
|
|
|
42
49
|
export default (record, searchSpec) => {
|
|
43
50
|
const extractors = {...bib};
|
|
51
|
+
debugData(`extractors: ${JSON.stringify(extractors)}`);
|
|
52
|
+
debugData(`searchSpec: ${JSON.stringify(searchSpec)}`);
|
|
44
53
|
|
|
45
54
|
return searchSpec
|
|
46
55
|
.map(generateQueryExtractor)
|
|
@@ -49,6 +58,7 @@ export default (record, searchSpec) => {
|
|
|
49
58
|
|
|
50
59
|
function generateQueryExtractor(type) {
|
|
51
60
|
if (extractors[type]) {
|
|
61
|
+
//debugData(`${JSON.stringify(extractors[type])}`);
|
|
52
62
|
return extractors[type];
|
|
53
63
|
}
|
|
54
64
|
|