@natlibfi/melinda-record-matching 1.0.8 → 2.0.0

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.
Files changed (64) hide show
  1. package/dist/candidate-search/candidate-search-utils.js +58 -0
  2. package/dist/candidate-search/candidate-search-utils.js.map +1 -0
  3. package/dist/candidate-search/index.js +8 -4
  4. package/dist/candidate-search/index.js.map +1 -1
  5. package/dist/candidate-search/index.spec.js +94 -86
  6. package/dist/candidate-search/index.spec.js.map +1 -1
  7. package/dist/candidate-search/query-list/bib.js +113 -23
  8. package/dist/candidate-search/query-list/bib.js.map +1 -1
  9. package/dist/candidate-search/query-list/bib.spec.js +25 -23
  10. package/dist/candidate-search/query-list/bib.spec.js.map +1 -1
  11. package/dist/candidate-search/query-list/index.js +6 -4
  12. package/dist/candidate-search/query-list/index.js.map +1 -1
  13. package/dist/index.js +3 -3
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.spec.js +53 -46
  16. package/dist/index.spec.js.map +1 -1
  17. package/dist/match-detection/features/bib/all-source-ids.js +122 -0
  18. package/dist/match-detection/features/bib/all-source-ids.js.map +1 -0
  19. package/dist/match-detection/features/bib/authors.js.map +1 -1
  20. package/dist/match-detection/features/bib/bibliographic-level.js.map +1 -1
  21. package/dist/match-detection/features/bib/host-component.js.map +1 -1
  22. package/dist/match-detection/features/bib/index.js +32 -16
  23. package/dist/match-detection/features/bib/index.js.map +1 -1
  24. package/dist/match-detection/features/bib/index.spec.js +50 -42
  25. package/dist/match-detection/features/bib/index.spec.js.map +1 -1
  26. package/dist/match-detection/features/bib/isbn.js.map +1 -1
  27. package/dist/match-detection/features/bib/issn.js.map +1 -1
  28. package/dist/match-detection/features/bib/language.js +42 -5
  29. package/dist/match-detection/features/bib/language.js.map +1 -1
  30. package/dist/match-detection/features/bib/melinda-id.js +52 -0
  31. package/dist/match-detection/features/bib/melinda-id.js.map +1 -0
  32. package/dist/match-detection/features/bib/melinda-identifier-factory.js +100 -0
  33. package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +1 -0
  34. package/dist/match-detection/features/bib/other-standard-identifier.js.map +1 -1
  35. package/dist/match-detection/features/bib/publication-time.js.map +1 -1
  36. package/dist/match-detection/features/bib/record-type.js.map +1 -1
  37. package/dist/match-detection/features/bib/standard-identifier-factory.js +8 -0
  38. package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -1
  39. package/dist/match-detection/features/bib/title.js.map +1 -1
  40. package/dist/match-detection/features/index.js +2 -2
  41. package/dist/match-detection/index.js +10 -6
  42. package/dist/match-detection/index.js.map +1 -1
  43. package/dist/match-detection/index.spec.js +32 -25
  44. package/dist/match-detection/index.spec.js.map +1 -1
  45. package/dist/matching-utils.js +95 -0
  46. package/dist/matching-utils.js.map +1 -0
  47. package/package.json +26 -29
  48. package/src/candidate-search/candidate-search-utils.js +53 -0
  49. package/src/candidate-search/index.js +4 -0
  50. package/src/candidate-search/index.spec.js +64 -58
  51. package/src/candidate-search/query-list/bib.js +130 -20
  52. package/src/candidate-search/query-list/bib.spec.js +16 -14
  53. package/src/candidate-search/query-list/index.js +3 -1
  54. package/src/index.spec.js +46 -39
  55. package/src/match-detection/features/bib/all-source-ids.js +122 -0
  56. package/src/match-detection/features/bib/index.js +2 -0
  57. package/src/match-detection/features/bib/index.spec.js +32 -23
  58. package/src/match-detection/features/bib/language.js +37 -3
  59. package/src/match-detection/features/bib/melinda-id.js +34 -0
  60. package/src/match-detection/features/bib/melinda-identifier-factory.js +94 -0
  61. package/src/match-detection/features/bib/standard-identifier-factory.js +6 -0
  62. package/src/match-detection/index.js +7 -4
  63. package/src/match-detection/index.spec.js +27 -20
  64. package/src/matching-utils.js +86 -0
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toQueries = toQueries;
7
+
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ /**
13
+ *
14
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
15
+ *
16
+ * Melinda record matching modules for Javascript
17
+ *
18
+ * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
19
+ *
20
+ * This file is part of melinda-record-matching-js
21
+ *
22
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
23
+ * it under the terms of the GNU Lesser General Public License as
24
+ * published by the Free Software Foundation, either version 3 of the
25
+ * License, or (at your option) any later version.
26
+ *
27
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
28
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30
+ * GNU Lesser General Public License for more details.
31
+ *
32
+ * You should have received a copy of the GNU Affero General Public License
33
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
34
+ *
35
+ * @licend The above is the entire license notice
36
+ * for the JavaScript code in this file.
37
+ *
38
+ */
39
+ function toQueries(identifiers, queryString) {
40
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:toQueries');
41
+ const debugData = debug.extend('data');
42
+ const quotedIdentifiers = identifiers.map(identifier => identifier.match(/\//u) ? `"${identifier}"` : `${identifier}`); // Aleph supports only two queries with or -operator (This is not actually true)
43
+
44
+ const pairs = toPairs(quotedIdentifiers);
45
+ const queries = pairs.map(([a, b]) => b ? `${queryString}=${a} or ${queryString}=${b}` : `${queryString}=${a}`);
46
+ debugData(`Pairs (${pairs.length}): ${JSON.stringify(pairs)}`);
47
+ debugData(`Queries (${queries.length}): ${JSON.stringify(queries)}`);
48
+ return queries;
49
+ }
50
+
51
+ function toPairs(array) {
52
+ if (array.length === 0) {
53
+ return [];
54
+ }
55
+
56
+ return [array.slice(0, 2)].concat(toPairs(array.slice(2), 2));
57
+ }
58
+ //# sourceMappingURL=candidate-search-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/candidate-search/candidate-search-utils.js"],"names":["toQueries","identifiers","queryString","debug","debugData","extend","quotedIdentifiers","map","identifier","match","pairs","toPairs","queries","a","b","length","JSON","stringify","array","slice","concat"],"mappings":";;;;;;;AA4BA;;;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIO,SAASA,SAAT,CAAmBC,WAAnB,EAAgCC,WAAhC,EAA6C;AAElD,QAAMC,KAAK,GAAG,oBAAkB,6CAAlB,CAAd;AACA,QAAMC,SAAS,GAAGD,KAAK,CAACE,MAAN,CAAa,MAAb,CAAlB;AAEA,QAAMC,iBAAiB,GAAGL,WAAW,CAACM,GAAZ,CAAgBC,UAAU,IAAIA,UAAU,CAACC,KAAX,CAAiB,KAAjB,IAA2B,IAAGD,UAAW,GAAzC,GAA+C,GAAEA,UAAW,EAA1F,CAA1B,CALkD,CAOlD;;AACA,QAAME,KAAK,GAAGC,OAAO,CAACL,iBAAD,CAArB;AACA,QAAMM,OAAO,GAAGF,KAAK,CAACH,GAAN,CAAU,CAAC,CAACM,CAAD,EAAIC,CAAJ,CAAD,KAAYA,CAAC,GAAI,GAAEZ,WAAY,IAAGW,CAAE,OAAMX,WAAY,IAAGY,CAAE,EAA9C,GAAmD,GAAEZ,WAAY,IAAGW,CAAE,EAA7F,CAAhB;AAEAT,EAAAA,SAAS,CAAE,UAASM,KAAK,CAACK,MAAO,MAAKC,IAAI,CAACC,SAAL,CAAeP,KAAf,CAAsB,EAAnD,CAAT;AACAN,EAAAA,SAAS,CAAE,YAAWQ,OAAO,CAACG,MAAO,MAAKC,IAAI,CAACC,SAAL,CAAeL,OAAf,CAAwB,EAAzD,CAAT;AAEA,SAAOA,OAAP;AACD;;AAED,SAASD,OAAT,CAAiBO,KAAjB,EAAwB;AACtB,MAAIA,KAAK,CAACH,MAAN,KAAiB,CAArB,EAAwB;AACtB,WAAO,EAAP;AACD;;AACD,SAAO,CAACG,KAAK,CAACC,KAAN,CAAY,CAAZ,EAAe,CAAf,CAAD,EAAoBC,MAApB,CAA2BT,OAAO,CAACO,KAAK,CAACC,KAAN,CAAY,CAAZ,CAAD,EAAiB,CAAjB,CAAlC,CAAP;AACD","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 createDebugLogger from 'debug';\n\nexport function toQueries(identifiers, queryString) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:toQueries');\n const debugData = debug.extend('data');\n\n const quotedIdentifiers = identifiers.map(identifier => identifier.match(/\\//u) ? `\"${identifier}\"` : `${identifier}`);\n\n // Aleph supports only two queries with or -operator (This is not actually true)\n const pairs = toPairs(quotedIdentifiers);\n const queries = pairs.map(([a, b]) => b ? `${queryString}=${a} or ${queryString}=${b}` : `${queryString}=${a}`);\n\n debugData(`Pairs (${pairs.length}): ${JSON.stringify(pairs)}`);\n debugData(`Queries (${queries.length}): ${JSON.stringify(queries)}`);\n\n return queries;\n}\n\nfunction toPairs(array) {\n if (array.length === 0) {\n return [];\n }\n return [array.slice(0, 2)].concat(toPairs(array.slice(2), 2));\n}\n"],"file":"candidate-search-utils.js"}
@@ -3,13 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.default = exports.CandidateSearchError = void 0;
6
7
  Object.defineProperty(exports, "searchTypes", {
7
8
  enumerable: true,
8
9
  get: function () {
9
10
  return _queryList.searchTypes;
10
11
  }
11
12
  });
12
- exports.default = exports.CandidateSearchError = void 0;
13
13
 
14
14
  var _debug = _interopRequireDefault(require("debug"));
15
15
 
@@ -21,9 +21,9 @@ var _marcRecordSerializers = require("@natlibfi/marc-record-serializers");
21
21
 
22
22
  var _queryList = _interopRequireWildcard(require("./query-list"));
23
23
 
24
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
24
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
25
 
26
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
26
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
27
 
28
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
29
 
@@ -77,6 +77,7 @@ var _default = ({
77
77
  version: '2.0',
78
78
  retrieveAll: false
79
79
  });
80
+ debug(`Searching matches for ${inputRecordId}`);
80
81
  debug(`Generated queryList ${JSON.stringify(queryList)}`);
81
82
 
82
83
  if (queryList.length === 0) {
@@ -148,7 +149,10 @@ var _default = ({
148
149
  const foundRecordMarc = await _marcRecordSerializers.MARCXML.from(foundRecord, {
149
150
  subfieldValues: false
150
151
  });
151
- const foundRecordId = getRecordId(foundRecordMarc);
152
+ const foundRecordId = getRecordId(foundRecordMarc); // This does not work and might cause problems:
153
+ // Record *should* match itself AND in REST the input record is given id 000000001 always
154
+
155
+ debug(`Checking ${inputRecordId} vs ${foundRecordId}`);
152
156
 
153
157
  if (inputRecordId === foundRecordId) {
154
158
  debug(`Input and candidate are the same record per 001. Discarding candidate`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/candidate-search/index.js"],"names":["CandidateSearchError","Error","record","searchSpec","url","maxRecordsPerRequest","MarcRecord","setValidationOptions","subfieldValues","debug","inputRecordId","getRecordId","queryList","client","version","retrieveAll","JSON","stringify","length","queryOffset","resultSetOffset","query","records","nextOffset","retrieveRecords","queriesLeft","Promise","resolve","reject","promises","searchRetrieve","startRecord","on","err","all","filtered","filter","r","foundRecord","push","handleRecord","foundRecordMarc","MARCXML","from","foundRecordId","id","field","get","value"],"mappings":";;;;;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAhCA;;;;;;;;;;;;;;;;;;;;;;;;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,CAACjB,MAAO,aAA1B,CAAL;AAEAS,YAAAA,OAAO,CAAC;AAACJ,cAAAA,UAAD;AAAaD,cAAAA,OAAO,EAAEa;AAAtB,aAAD,CAAP;AACD,WAPD,CAOE,OAAOF,GAAP,EAAY;AACZL,YAAAA,MAAM,CAACK,GAAD,CAAN;AACD;AACF,SAfH,EAgBGD,EAhBH,CAgBM,QAhBN,EAgBgBM,WAAW,IAAI;AAC3BT,UAAAA,QAAQ,CAACU,IAAT,CAAcC,YAAY,EAA1B,EAD2B,CACI;;AAE/B,yBAAeA,YAAf,GAA8B;AAC5B,gBAAI;AACF,oBAAMC,eAAe,GAAG,MAAMC,+BAAQC,IAAR,CAAaL,WAAb,EAA0B;AAAC9B,gBAAAA,cAAc,EAAE;AAAjB,eAA1B,CAA9B;AACA,oBAAMoC,aAAa,GAAGjC,WAAW,CAAC8B,eAAD,CAAjC;;AAEA,kBAAI/B,aAAa,KAAKkC,aAAtB,EAAqC;AACnCnC,gBAAAA,KAAK,CAAE,uEAAF,CAAL;AACA;AACD;;AAED,qBAAO;AAACP,gBAAAA,MAAM,EAAEuC,eAAT;AAA0BI,gBAAAA,EAAE,EAAED;AAA9B,eAAP;AACD,aAVD,CAUE,OAAOX,GAAP,EAAY;AACZ,oBAAM,IAAIhC,KAAJ,CAAW,6BAA4BgC,GAAI,aAAYK,WAAY,EAAnE,CAAN;AACD;AACF;AACF,SAlCH;AAmCD,OAxCM,CAAP;AAyCD;AACF,GA5DD;;AA8DA,WAAS3B,WAAT,CAAqBT,MAArB,EAA6B;AAC3B,UAAM,CAAC4C,KAAD,IAAU5C,MAAM,CAAC6C,GAAP,CAAW,QAAX,CAAhB;AACA,WAAOD,KAAK,GAAGA,KAAK,CAACE,KAAT,GAAiB,EAA7B;AACD;AACF,C","sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 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 from '@natlibfi/sru-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {MARCXML} from '@natlibfi/marc-record-serializers';\nimport generateQueryList from './query-list';\n\nexport {searchTypes} from './query-list';\n\nexport class CandidateSearchError extends Error {}\n\nexport default ({record, searchSpec, url, maxRecordsPerRequest = 50}) => {\n MarcRecord.setValidationOptions({subfieldValues: false});\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search');\n const inputRecordId = getRecordId(record);\n const queryList = generateQueryList(record, searchSpec);\n const client = createClient({\n url, maxRecordsPerRequest,\n version: '2.0',\n retrieveAll: false\n });\n\n debug(`Generated queryList ${JSON.stringify(queryList)}`);\n if (queryList.length === 0) { // eslint-disable-line functional/no-conditional-statement\n throw new CandidateSearchError(`Generated query list contains no queries`);\n }\n\n // eslint-disable-next-line max-statements\n return async ({queryOffset = 0, resultSetOffset = 1}) => {\n const query = queryList[queryOffset];\n\n if (query) {\n const {records, nextOffset} = await retrieveRecords();\n\n if (typeof nextOffset === 'number') {\n debug(`Running next search for query ${queryOffset} ${query}`);\n return {records, queryOffset, resultSetOffset: nextOffset, queriesLeft: queryList.length - (queryOffset + 1)};\n }\n debug(`Query ${queryOffset} ${query} done, moving to next query. (${queryList.length - (queryOffset + 1)} queries left)`);\n return {records, queryOffset: queryOffset + 1, queriesLeft: queryList.length - (queryOffset + 1)};\n }\n\n debug(`All ${queryList.length} queries done, there's no query for ${queryOffset}`);\n return {records: []};\n\n function retrieveRecords() {\n return new Promise((resolve, reject) => {\n const promises = [];\n\n debug(`Searching for candidates with query: ${query} (Offset ${resultSetOffset})`);\n\n client.searchRetrieve(query, {startRecord: resultSetOffset})\n .on('error', err => {\n reject(new CandidateSearchError(`SRU error for query: ${query}: ${err}`));\n })\n .on('end', async nextOffset => {\n try {\n const records = await Promise.all(promises);\n const filtered = records.filter(r => r);\n\n debug(`Found ${filtered.length} candidates`);\n\n resolve({nextOffset, records: filtered});\n } catch (err) {\n reject(err);\n }\n })\n .on('record', foundRecord => {\n promises.push(handleRecord()); // eslint-disable-line functional/immutable-data\n\n async function handleRecord() {\n try {\n const foundRecordMarc = await MARCXML.from(foundRecord, {subfieldValues: false});\n const foundRecordId = getRecordId(foundRecordMarc);\n\n if (inputRecordId === foundRecordId) {\n debug(`Input and candidate are the same record per 001. Discarding candidate`);\n return;\n }\n\n return {record: foundRecordMarc, id: foundRecordId};\n } catch (err) {\n throw new Error(`Failed converting record: ${err}, record: ${foundRecord}`);\n }\n }\n });\n });\n }\n };\n\n function getRecordId(record) {\n const [field] = record.get(/^001$/u);\n return field ? field.value : '';\n }\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../src/candidate-search/index.js"],"names":["CandidateSearchError","Error","record","searchSpec","url","maxRecordsPerRequest","MarcRecord","setValidationOptions","subfieldValues","debug","inputRecordId","getRecordId","queryList","client","version","retrieveAll","JSON","stringify","length","queryOffset","resultSetOffset","query","records","nextOffset","retrieveRecords","queriesLeft","Promise","resolve","reject","promises","searchRetrieve","startRecord","on","err","all","filtered","filter","r","foundRecord","push","handleRecord","foundRecordMarc","MARCXML","from","foundRecordId","id","field","get","value"],"mappings":";;;;;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAhCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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B;AACA,WAAOD,KAAK,GAAGA,KAAK,CAACE,KAAT,GAAiB,EAA7B;AACD;AACF,C","sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 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 from '@natlibfi/sru-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {MARCXML} from '@natlibfi/marc-record-serializers';\nimport generateQueryList from './query-list';\n\nexport {searchTypes} from './query-list';\n\nexport class CandidateSearchError extends Error {}\n\nexport default ({record, searchSpec, url, maxRecordsPerRequest = 50}) => {\n MarcRecord.setValidationOptions({subfieldValues: false});\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search');\n const inputRecordId = getRecordId(record);\n const queryList = generateQueryList(record, searchSpec);\n const client = createClient({\n url, maxRecordsPerRequest,\n version: '2.0',\n retrieveAll: false\n });\n\n debug(`Searching matches for ${inputRecordId}`);\n debug(`Generated queryList ${JSON.stringify(queryList)}`);\n if (queryList.length === 0) { // eslint-disable-line functional/no-conditional-statement\n throw new CandidateSearchError(`Generated query list contains no queries`);\n }\n\n // eslint-disable-next-line max-statements\n return async ({queryOffset = 0, resultSetOffset = 1}) => {\n const query = queryList[queryOffset];\n\n if (query) {\n const {records, nextOffset} = await retrieveRecords();\n\n if (typeof nextOffset === 'number') {\n debug(`Running next search for query ${queryOffset} ${query}`);\n return {records, queryOffset, resultSetOffset: nextOffset, queriesLeft: queryList.length - (queryOffset + 1)};\n }\n debug(`Query ${queryOffset} ${query} done, moving to next query. (${queryList.length - (queryOffset + 1)} queries left)`);\n return {records, queryOffset: queryOffset + 1, queriesLeft: queryList.length - (queryOffset + 1)};\n }\n\n debug(`All ${queryList.length} queries done, there's no query for ${queryOffset}`);\n return {records: []};\n\n function retrieveRecords() {\n return new Promise((resolve, reject) => {\n const promises = [];\n\n debug(`Searching for candidates with query: ${query} (Offset ${resultSetOffset})`);\n\n client.searchRetrieve(query, {startRecord: resultSetOffset})\n .on('error', err => {\n reject(new CandidateSearchError(`SRU error for query: ${query}: ${err}`));\n })\n .on('end', async nextOffset => {\n try {\n const records = await Promise.all(promises);\n const filtered = records.filter(r => r);\n\n debug(`Found ${filtered.length} candidates`);\n\n resolve({nextOffset, records: filtered});\n } catch (err) {\n reject(err);\n }\n })\n .on('record', foundRecord => {\n promises.push(handleRecord()); // eslint-disable-line functional/immutable-data\n\n async function handleRecord() {\n try {\n const foundRecordMarc = await MARCXML.from(foundRecord, {subfieldValues: false});\n const foundRecordId = getRecordId(foundRecordMarc);\n\n // This does not work and might cause problems:\n // Record *should* match itself AND in REST the input record is given id 000000001 always\n debug(`Checking ${inputRecordId} vs ${foundRecordId}`);\n if (inputRecordId === foundRecordId) {\n debug(`Input and candidate are the same record per 001. Discarding candidate`);\n return;\n }\n\n return {record: foundRecordMarc, id: foundRecordId};\n } catch (err) {\n throw new Error(`Failed converting record: ${err}, record: ${foundRecord}`);\n }\n }\n });\n });\n }\n };\n\n function getRecordId(record) {\n const [field] = record.get(/^001$/u);\n return field ? field.value : '';\n }\n};\n"],"file":"index.js"}
@@ -10,9 +10,9 @@ var _marcRecord = require("@natlibfi/marc-record");
10
10
 
11
11
  var _ = _interopRequireWildcard(require("."));
12
12
 
13
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
13
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
14
 
15
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
16
 
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
18
 
@@ -43,101 +43,109 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
43
43
  * for the JavaScript code in this file.
44
44
  *
45
45
  */
46
- (0, _fixugenHttpClient.default)({
47
- callback,
48
- path: [__dirname, '..', '..', 'test-fixtures', 'candidate-search', 'index'],
49
- recurse: false,
50
- fixura: {
51
- reader: _fixura.READERS.JSON
52
- }
53
- }); // eslint-disable-next-line max-statements
54
-
55
- async function callback({
56
- getFixture,
57
- factoryOptions,
58
- searchOptions,
59
- expectedFactoryError,
60
- expectedSearchError
61
- }) {
62
- const url = 'http://foo.bar';
63
-
64
- if (expectedFactoryError) {
65
- if (expectedFactoryError.isCandidateSearchError) {
66
- (0, _chai.expect)(() => (0, _.default)({ ...formatFactoryOptions(),
67
- url
68
- })).to.throw(_.CandidateSearchError, new RegExp(expectedFactoryError, 'u'));
69
- return;
46
+ describe('candidate-search', () => {
47
+ (0, _fixugenHttpClient.default)({
48
+ callback,
49
+ path: [__dirname, '..', '..', 'test-fixtures', 'candidate-search', 'index'],
50
+ recurse: false,
51
+ fixura: {
52
+ reader: _fixura.READERS.JSON
70
53
  }
54
+ }); // eslint-disable-next-line max-statements
71
55
 
72
- (0, _chai.expect)(() => (0, _.default)({ ...formatFactoryOptions(),
73
- url
74
- })).to.throw(new RegExp(expectedFactoryError, 'u'));
75
- return;
76
- }
77
-
78
- const search = (0, _.default)({ ...formatFactoryOptions(),
79
- url
80
- });
81
- await iterate({
82
- searchOptions
83
- });
84
-
85
- function formatFactoryOptions() {
86
- return { ...factoryOptions,
87
- maxRecordsPerRequest: 1,
88
- record: new _marcRecord.MarcRecord(factoryOptions.record, {
89
- subfieldValues: false
90
- })
91
- };
92
- } // eslint-disable-next-line max-statements
93
-
94
-
95
- async function iterate({
56
+ async function callback({
57
+ getFixture,
58
+ factoryOptions,
96
59
  searchOptions,
97
- count = 1
60
+ expectedFactoryError,
61
+ expectedSearchError,
62
+ enabled = true
98
63
  }) {
99
- const expectedResults = getFixture(`expectedResults${count}.json`);
100
-
101
- if (expectedSearchError) {
102
- // eslint-disable-line functional/no-conditional-statement
103
- try {
104
- await search(searchOptions);
105
- throw new Error('Expected an error');
106
- } catch (err) {
107
- (0, _chai.expect)(err).to.be.an('error');
108
- (0, _chai.expect)(err.message).to.match(new RegExp(expectedSearchError, 'u'));
109
- return;
110
- }
64
+ const url = 'http://foo.bar';
65
+
66
+ if (!enabled) {
67
+ return;
111
68
  }
112
69
 
113
- const results = await search(searchOptions);
114
- (0, _chai.expect)(formatResults(results)).to.eql(expectedResults);
70
+ if (expectedFactoryError) {
71
+ if (expectedFactoryError.isCandidateSearchError) {
72
+ (0, _chai.expect)(() => (0, _.default)({ ...formatFactoryOptions(),
73
+ url
74
+ })).to.throw(_.CandidateSearchError, new RegExp(expectedFactoryError, 'u'));
75
+ return;
76
+ }
115
77
 
116
- if (results.records.length > 0) {
117
- return iterate({
118
- searchOptions: resultsToOptions(results),
119
- count: count + 1
120
- });
78
+ (0, _chai.expect)(() => (0, _.default)({ ...formatFactoryOptions(),
79
+ url
80
+ })).to.throw(new RegExp(expectedFactoryError, 'u'));
81
+ return;
121
82
  }
122
83
 
123
- function formatResults(results) {
124
- // console.log(results); //eslint-disable-line
125
- return { ...results,
126
- records: results.records.map(({
127
- record,
128
- id
129
- }) => ({
130
- id,
131
- record: record.toObject()
132
- }))
84
+ const search = (0, _.default)({ ...formatFactoryOptions(),
85
+ url
86
+ });
87
+ await iterate({
88
+ searchOptions
89
+ });
90
+
91
+ function formatFactoryOptions() {
92
+ return { ...factoryOptions,
93
+ maxRecordsPerRequest: 1,
94
+ record: new _marcRecord.MarcRecord(factoryOptions.record, {
95
+ subfieldValues: false
96
+ })
133
97
  };
134
- }
98
+ } // eslint-disable-next-line max-statements
99
+
100
+
101
+ async function iterate({
102
+ searchOptions,
103
+ count = 1
104
+ }) {
105
+ const expectedResults = getFixture(`expectedResults${count}.json`);
106
+
107
+ if (expectedSearchError) {
108
+ // eslint-disable-line functional/no-conditional-statement
109
+ try {
110
+ await search(searchOptions);
111
+ throw new Error('Expected an error');
112
+ } catch (err) {
113
+ (0, _chai.expect)(err).to.be.an('error');
114
+ (0, _chai.expect)(err.message).to.match(new RegExp(expectedSearchError, 'u'));
115
+ return;
116
+ }
117
+ }
118
+
119
+ const results = await search(searchOptions);
120
+ (0, _chai.expect)(formatResults(results)).to.eql(expectedResults);
121
+
122
+ if (results.records.length > 0) {
123
+ return iterate({
124
+ searchOptions: resultsToOptions(results),
125
+ count: count + 1
126
+ });
127
+ }
135
128
 
136
- function resultsToOptions(results) {
137
- return Object.entries(results).filter(([k]) => k === 'records' === false).reduce((acc, [k, v]) => ({ ...acc,
138
- [k]: v
139
- }), {});
129
+ function formatResults(results) {
130
+ // console.log(results); //eslint-disable-line
131
+ return { ...results,
132
+ records: results.records.map(({
133
+ record,
134
+ id
135
+ }) => ({
136
+ id,
137
+ record: record.toObject()
138
+ }))
139
+ };
140
+ }
141
+
142
+ function resultsToOptions(results) {
143
+ return Object.entries(results).filter(([k]) => k === 'records' === false) // If key is 'records' return false
144
+ .reduce((acc, [k, v]) => ({ ...acc,
145
+ [k]: v
146
+ }), {});
147
+ }
140
148
  }
141
149
  }
142
- }
150
+ });
143
151
  //# sourceMappingURL=index.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/candidate-search/index.spec.js"],"names":["callback","path","__dirname","recurse","fixura","reader","READERS","JSON","getFixture","factoryOptions","searchOptions","expectedFactoryError","expectedSearchError","url","isCandidateSearchError","formatFactoryOptions","to","throw","CandidateSearchError","RegExp","search","iterate","maxRecordsPerRequest","record","MarcRecord","subfieldValues","count","expectedResults","Error","err","be","an","message","match","results","formatResults","eql","records","length","resultsToOptions","map","id","toObject","Object","entries","filter","k","reduce","acc","v"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAhCA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,gCAAc;AACZA,EAAAA,QADY;AAEZC,EAAAA,IAAI,EAAE,CAACC,SAAD,EAAY,IAAZ,EAAkB,IAAlB,EAAwB,eAAxB,EAAyC,kBAAzC,EAA6D,OAA7D,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AAP,CAAeV,OAAf,EACJW,MADI,CACG,CAAC,CAACC,CAAD,CAAD,KAASA,CAAC,KAAK,SAAN,KAAoB,KADhC,EAEJC,MAFI,CAEG,CAACC,GAAD,EAAM,CAACF,CAAD,EAAIG,CAAJ,CAAN,MAAkB,EAAC,GAAGD,GAAJ;AAAS,SAACF,CAAD,GAAKG;AAAd,OAAlB,CAFH,EAEwC,EAFxC,CAAP;AAGD;AACF;AACF","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 {expect} from 'chai';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen-http-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport createSearchInterface, {CandidateSearchError} from '.';\n\ngenerateTests({\n callback,\n path: [__dirname, '..', '..', 'test-fixtures', 'candidate-search', 'index'],\n recurse: false,\n fixura: {\n reader: READERS.JSON\n }\n});\n\n// eslint-disable-next-line max-statements\nasync function callback({getFixture, factoryOptions, searchOptions, expectedFactoryError, expectedSearchError}) {\n const url = 'http://foo.bar';\n\n if (expectedFactoryError) {\n if (expectedFactoryError.isCandidateSearchError) {\n expect(() => createSearchInterface({...formatFactoryOptions(), url})).to.throw(CandidateSearchError, new RegExp(expectedFactoryError, 'u'));\n return;\n }\n\n expect(() => createSearchInterface({...formatFactoryOptions(), url})).to.throw(new RegExp(expectedFactoryError, 'u'));\n return;\n }\n\n const search = createSearchInterface({...formatFactoryOptions(), url});\n await iterate({searchOptions});\n\n function formatFactoryOptions() {\n return {\n ...factoryOptions,\n maxRecordsPerRequest: 1,\n record: new MarcRecord(factoryOptions.record, {subfieldValues: false})\n };\n }\n\n // eslint-disable-next-line max-statements\n async function iterate({searchOptions, count = 1}) {\n const expectedResults = getFixture(`expectedResults${count}.json`);\n\n if (expectedSearchError) { // eslint-disable-line functional/no-conditional-statement\n try {\n await search(searchOptions);\n throw new Error('Expected an error');\n } catch (err) {\n expect(err).to.be.an('error');\n expect(err.message).to.match(new RegExp(expectedSearchError, 'u'));\n return;\n }\n }\n\n const results = await search(searchOptions);\n\n expect(formatResults(results)).to.eql(expectedResults);\n\n if (results.records.length > 0) {\n return iterate({\n searchOptions: resultsToOptions(results),\n count: count + 1\n });\n }\n\n function formatResults(results) {\n // console.log(results); //eslint-disable-line\n return {\n ...results,\n records: results.records.map(({record, id}) => ({id, record: record.toObject()}))\n };\n }\n\n function resultsToOptions(results) {\n return Object.entries(results)\n .filter(([k]) => k === 'records' === false)\n .reduce((acc, [k, v]) => ({...acc, [k]: v}), {});\n }\n }\n}\n"],"file":"index.spec.js"}
1
+ {"version":3,"sources":["../../src/candidate-search/index.spec.js"],"names":["describe","callback","path","__dirname","recurse","fixura","reader","READERS","JSON","getFixture","factoryOptions","searchOptions","expectedFactoryError","expectedSearchError","enabled","url","isCandidateSearchError","formatFactoryOptions","to","throw","CandidateSearchError","RegExp","search","iterate","maxRecordsPerRequest","record","MarcRecord","subfieldValues","count","expectedResults","Error","err","be","an","message","match","results","formatResults","eql","records","length","resultsToOptions","map","id","toObject","Object","entries","filter","k","reduce","acc","v"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAhCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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D,OAAvB,EAAgC;AAC9B;AACA,eAAO,EACL,GAAGA,OADE;AAELG,UAAAA,OAAO,EAAEH,OAAO,CAACG,OAAR,CAAgBG,GAAhB,CAAoB,CAAC;AAACjB,YAAAA,MAAD;AAASkB,YAAAA;AAAT,WAAD,MAAmB;AAACA,YAAAA,EAAD;AAAKlB,YAAAA,MAAM,EAAEA,MAAM,CAACmB,QAAP;AAAb,WAAnB,CAApB;AAFJ,SAAP;AAID;;AAED,eAASH,gBAAT,CAA0BL,OAA1B,EAAmC;AACjC,eAAOS,MAAM,CAACC,OAAP,CAAeV,OAAf,EACJW,MADI,CACG,CAAC,CAACC,CAAD,CAAD,KAASA,CAAC,KAAK,SAAN,KAAoB,KADhC,EACuC;AADvC,SAEJC,MAFI,CAEG,CAACC,GAAD,EAAM,CAACF,CAAD,EAAIG,CAAJ,CAAN,MAAkB,EAAC,GAAGD,GAAJ;AAAS,WAACF,CAAD,GAAKG;AAAd,SAAlB,CAFH,EAEwC,EAFxC,CAAP;AAGD;AACF;AACF;AACF,CAhFO,CAAR","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 {expect} from 'chai';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen-http-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport createSearchInterface, {CandidateSearchError} from '.';\n\ndescribe('candidate-search', () => {\n generateTests({\n callback,\n path: [__dirname, '..', '..', 'test-fixtures', 'candidate-search', 'index'],\n recurse: false,\n fixura: {\n reader: READERS.JSON\n }\n });\n\n // eslint-disable-next-line max-statements\n async function callback({getFixture, factoryOptions, searchOptions, expectedFactoryError, expectedSearchError, enabled = true}) {\n const url = 'http://foo.bar';\n\n if (!enabled) {\n return;\n }\n\n if (expectedFactoryError) {\n if (expectedFactoryError.isCandidateSearchError) {\n expect(() => createSearchInterface({...formatFactoryOptions(), url})).to.throw(CandidateSearchError, new RegExp(expectedFactoryError, 'u'));\n return;\n }\n\n expect(() => createSearchInterface({...formatFactoryOptions(), url})).to.throw(new RegExp(expectedFactoryError, 'u'));\n return;\n }\n\n const search = createSearchInterface({...formatFactoryOptions(), url});\n await iterate({searchOptions});\n\n function formatFactoryOptions() {\n return {\n ...factoryOptions,\n maxRecordsPerRequest: 1,\n record: new MarcRecord(factoryOptions.record, {subfieldValues: false})\n };\n }\n\n // eslint-disable-next-line max-statements\n async function iterate({searchOptions, count = 1}) {\n const expectedResults = getFixture(`expectedResults${count}.json`);\n\n if (expectedSearchError) { // eslint-disable-line functional/no-conditional-statement\n try {\n await search(searchOptions);\n throw new Error('Expected an error');\n } catch (err) {\n expect(err).to.be.an('error');\n expect(err.message).to.match(new RegExp(expectedSearchError, 'u'));\n return;\n }\n }\n\n const results = await search(searchOptions);\n\n expect(formatResults(results)).to.eql(expectedResults);\n\n if (results.records.length > 0) {\n return iterate({\n searchOptions: resultsToOptions(results),\n count: count + 1\n });\n }\n\n function formatResults(results) {\n // console.log(results); //eslint-disable-line\n return {\n ...results,\n records: results.records.map(({record, id}) => ({id, record: record.toObject()}))\n };\n }\n\n function resultsToOptions(results) {\n return Object.entries(results)\n .filter(([k]) => k === 'records' === false) // If key is 'records' return false\n .reduce((acc, [k, v]) => ({...acc, [k]: v}), {});\n }\n }\n }\n});\n"],"file":"index.spec.js"}
@@ -4,11 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.bibHostComponents = bibHostComponents;
7
- exports.bibTitle = bibTitle;
7
+ exports.bibMelindaIds = bibMelindaIds;
8
+ exports.bibSourceIds = bibSourceIds;
8
9
  exports.bibStandardIdentifiers = bibStandardIdentifiers;
10
+ exports.bibTitle = bibTitle;
9
11
 
10
12
  var _debug = _interopRequireDefault(require("debug"));
11
13
 
14
+ var _candidateSearchUtils = require("../candidate-search-utils");
15
+
16
+ var _matchingUtils = require("../../matching-utils");
17
+
12
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
19
 
14
20
  /**
@@ -38,8 +44,102 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
38
44
  * for the JavaScript code in this file.
39
45
  *
40
46
  */
41
- // bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05
47
+ function bibSourceIds(record) {
48
+ /* Melinda's SRU-index melinda.sourceid includes source IDs from SID fields in Melinda records
49
+ SID-fields in Melinda have sf $c with local id and sf $b with a code for the local db:
50
+ SID__ $c 123457 $b helka
51
+ SID__ $c (ANDL100020)1077305 $b sata
52
+ SID__ $c VER999999 $ FI-KV
53
+ SID__ $c /10024/508126 $ REPO_THESEUS
54
+ In melinda.sourceid -index case is kept, sourceprefixes in brackets and hyphens are normalized away:
55
+ Note: slashes are not normalized away, but a SRU-search-string including slashes needs to be quoted
56
+ 1234567helka
57
+ 1077305sata
58
+ VER999999FIKV
59
+ /10024/508126REPO_THESEUS
60
+ Note: All Melinda records that have a matching records in a local db do NOT have SID for that local records,
61
+ existence of a SID field depends on how the record has been added to Melinda and how it has been handled
62
+ afterwards. SIDs are also not reliably maintained. A record might or might not have a SID for a local db
63
+ after the matching record is removed from the local db.
64
+ */
65
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:query:source-ids');
66
+ const debugData = debug.extend('data'); //const debugInfo = debug.extend('info');
67
+
68
+ debug(`Creating queries for sourceid's`);
69
+ const fSids = record.get('SID');
70
+ debugData(`SID-fields (${fSids.length}): ${JSON.stringify(fSids)}`);
71
+ return fSids.length > 0 ? toSidQueries(fSids) : [];
72
+
73
+ function toSidQueries(fSids) {
74
+ debug(`Creating actual queries for sourceid's`);
75
+ const sidStrings = getSidStrings(fSids);
76
+
77
+ if (sidStrings.length < 1) {
78
+ debug(`No identifiers found, no queries created.`);
79
+ return [];
80
+ }
81
+
82
+ const sidQueries = (0, _candidateSearchUtils.toQueries)(sidStrings, 'melinda.sourceid');
83
+ return sidQueries;
84
+
85
+ function getSidStrings(fSids) {
86
+ debug(`Getting Sid strings from SID fields`); // Map SID fields to valid sidStrings, filter out empty strings
87
+
88
+ const sidStrings = fSids.map(toSidString).filter(nonEmptySid => nonEmptySid);
89
+ return sidStrings;
90
+
91
+ function toSidString(field) {
92
+ debug(`Getting string from a field`);
93
+ return (0, _matchingUtils.validateSidFieldSubfieldCounts)(field) ? createSidString(field) : '';
94
+
95
+ function createSidString(field) {
96
+ debug(`Creating string from a field`);
97
+ const [sfC] = (0, _matchingUtils.getSubfieldValues)(field, 'c');
98
+ const [sfB] = (0, _matchingUtils.getSubfieldValues)(field, 'b');
99
+ const cleanedSfC = removeSourcePrefix(normalizeSidSubfieldValue(sfC));
100
+ const cleanedSfB = normalizeSidSubfieldValue(sfB);
101
+ debugData(`${JSON.stringify(sfC)} + ${JSON.stringify(sfB)}`);
102
+ return cleanedSfC.concat(cleanedSfB);
103
+ }
104
+
105
+ function removeSourcePrefix(subfieldValue) {
106
+ const sourcePrefixRegex = /^(?<sourcePrefix>\([A-Za-z0-9-]+\))(?<id>.+)$/u;
107
+ const normalizedValue = subfieldValue.replace(sourcePrefixRegex, '$<id>');
108
+ debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);
109
+ return normalizedValue;
110
+ }
111
+
112
+ function normalizeSidSubfieldValue(subfieldValue) {
113
+ debugData(`Normalizing ${subfieldValue}`);
114
+ const normalizeAwayRegex = /[- ]/u;
115
+ return subfieldValue.replace(normalizeAwayRegex, '');
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+
122
+ function bibMelindaIds(record) {
123
+ // Melinda's SRU-index melinda.melindaid includes f001 controlnumbers and old Melinda-IDs from f035z's for all non-deleted Melinda-records
124
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:query:bibMelindaIds');
125
+ const debugData = debug.extend('data');
126
+ debug(`Creating queries for MelindaIds`); // Note: Melinda-ID's for search queries are created just from records f035a's and f035z's
127
+ // Both (FI-MELINDA)- and FCC-prefixed forms are found
128
+ // f001 controlnumber is not currently included, even if record's f003 is FI-MELINDA
129
+
130
+ const melindaIds = (0, _matchingUtils.getMelindaIdsF035)(record);
131
+ debugData(`Unique identifiers (${melindaIds.length}): ${JSON.stringify(melindaIds)}`);
132
+
133
+ if (melindaIds.length < 1) {
134
+ debug(`No identifiers found, no queries created.`);
135
+ return [];
136
+ }
137
+
138
+ return (0, _candidateSearchUtils.toQueries)(melindaIds, 'melinda.melindaid');
139
+ } // bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05
42
140
  // bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?
141
+
142
+
43
143
  function bibHostComponents(record) {
44
144
  const id = getHostId();
45
145
  return id ? [`melinda.partsofhost=${id}`] : [];
@@ -67,13 +167,19 @@ function bibHostComponents(record) {
67
167
 
68
168
  return false;
69
169
  }
70
- }
170
+ } // SRU search dc.title with a search phrase starting with ^ maps currently in Melinda to
171
+ // (probably) to *headings* index TIT
172
+ // Headings index TIT drops articles etc. from the start of the title according to the filing indicator
173
+ // Currently filing indicator is not implemented - if the title starts with an article and the Melinda
174
+ // record is correctly catalogued using a filing indicator -> dc.title search won't match
175
+
71
176
 
72
177
  function bibTitle(record) {
73
178
  const title = getTitle();
74
179
 
75
180
  if (title) {
76
- const formatted = title.replace(/[^\w\s\p{Alphabetic}]/gu, '').trim().slice(0, 30).trim(); // Prevent too many matches by having a minimum length requirement
181
+ const formatted = title.replace(/[^\w\s\p{Alphabetic}]/gu, '') // Clean up concurrent spaces from fe. subfield changes
182
+ .replace(/ +/gu, ' ').trim().slice(0, 30).trim(); // Prevent too many matches by having a minimum length requirement
77
183
 
78
184
  return formatted.length >= 5 ? [`dc.title="^${formatted}*"`] : [];
79
185
  }
@@ -88,7 +194,8 @@ function bibTitle(record) {
88
194
  code
89
195
  }) => ['a', 'b'].includes(code)).map(({
90
196
  value
91
- }) => value).join('');
197
+ }) => value) // In Melinda's index subfield separators are indexed as ' '
198
+ .join(' ');
92
199
  }
93
200
 
94
201
  return false;
@@ -112,24 +219,7 @@ function bibStandardIdentifiers(record) {
112
219
  return [];
113
220
  }
114
221
 
115
- return toQueries(uniqueIdentifiers);
116
-
117
- function toQueries(identifiers) {
118
- // Aleph supports only two queries with or -operator (This is not actually true)
119
- const pairs = toPairs(identifiers);
120
- const queries = pairs.map(([a, b]) => b ? `dc.identifier=${a} or dc.identifier=${b}` : `dc.identifier=${a}`);
121
- debugData(`Pairs (${pairs.length}): ${JSON.stringify(pairs)}`);
122
- debugData(`Queries (${queries.length}): ${JSON.stringify(queries)}`);
123
- return queries;
124
-
125
- function toPairs(array) {
126
- if (array.length === 0) {
127
- return [];
128
- }
129
-
130
- return [array.slice(0, 2)].concat(toPairs(array.slice(2), 2));
131
- }
132
- }
222
+ return (0, _candidateSearchUtils.toQueries)(uniqueIdentifiers, 'dc.identifier');
133
223
 
134
224
  function toIdentifiers({
135
225
  tag,