@natlibfi/melinda-record-matching 4.3.2-alpha.2 → 4.3.2-alpha.4

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.
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CandidateSearchError = void 0;
7
+ exports.default = _default;
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+ var _sruClient = _interopRequireWildcard(require("@natlibfi/sru-client"));
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); }
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; }
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ /**
14
+ *
15
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
16
+ *
17
+ * Melinda record matching modules for Javascript
18
+ *
19
+ * Copyright (C) 2023 University Of Helsinki (The National Library Of Finland)
20
+ *
21
+ * This file is part of melinda-record-matching-js
22
+ *
23
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
24
+ * it under the terms of the GNU Lesser General Public License as
25
+ * published by the Free Software Foundation, either version 3 of the
26
+ * License, or (at your option) any later version.
27
+ *
28
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
29
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
30
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31
+ * GNU Lesser General Public License for more details.
32
+ *
33
+ * You should have received a copy of the GNU Affero General Public License
34
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
35
+ *
36
+ * @licend The above is the entire license notice
37
+ * for the JavaScript code in this file.
38
+ *
39
+ */
40
+
41
+ class CandidateSearchError extends Error {}
42
+ exports.CandidateSearchError = CandidateSearchError;
43
+ async function _default({
44
+ url,
45
+ queryList,
46
+ queryListType,
47
+ maxCandidates = 50
48
+ }) {
49
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:choose-queries');
50
+ const debugData = debug.extend('data');
51
+ const debugDev = debug.extend('dev');
52
+ debugData(`Url: ${url}`);
53
+ debugData(`QueryList: ${queryList}`);
54
+ debugData(`queryListType: ${queryListType}`);
55
+ const client = (0, _sruClient.default)({
56
+ url,
57
+ maxRecordsPerRequest: 0,
58
+ version: '2.0',
59
+ retrieveAll: false
60
+ });
61
+ debugDev(`QueryList (type: ${queryListType}) ${JSON.stringify(queryList)}`);
62
+ try {
63
+ const {
64
+ queriesWithTotals
65
+ } = await getQueryTotals({
66
+ queryList,
67
+ queryOffset: 0,
68
+ queriesWithTotals: []
69
+ });
70
+ debugDev(`QueryResult: ${JSON.stringify(queriesWithTotals)}`);
71
+ const filteredQueryResult = filterQueryResult({
72
+ queriesWithTotals,
73
+ maxCandidates
74
+ });
75
+ debugDev(`filteredQueryResult: ${JSON.stringify(filteredQueryResult)}`);
76
+ return filteredQueryResult;
77
+ } catch (err) {
78
+ throw new CandidateSearchError(err);
79
+ }
80
+ async function getQueryTotals({
81
+ queryList,
82
+ queryOffset = 0,
83
+ queriesWithTotals = []
84
+ }) {
85
+ const query = queryList[queryOffset];
86
+ debug(`Running query ${JSON.stringify(query)} (${queryOffset}) for total`);
87
+ if (query) {
88
+ const {
89
+ total
90
+ } = await retrieveTotal();
91
+ const newQueriesWithTotals = [...queriesWithTotals, {
92
+ query,
93
+ total
94
+ }];
95
+ debug(`Query ${queryOffset} ${query} done.`);
96
+ debug(`There are (${queryList.length - (queryOffset + 1)} queries left)`);
97
+ return getQueryTotals({
98
+ queryList,
99
+ queryOffset: queryOffset + 1,
100
+ queriesWithTotals: newQueriesWithTotals
101
+ });
102
+ }
103
+ debug(`All ${queryList.length} queries done, there's no query for ${queryOffset}`);
104
+ return {
105
+ queriesWithTotals
106
+ };
107
+ function retrieveTotal() {
108
+ return new Promise((resolve, reject) => {
109
+ // eslint-disable-next-line functional/no-let
110
+ let totalRecords = 0;
111
+ debug(`Searching total amount of candidates for query: ${query}`);
112
+ client.searchRetrieve(query).on('error', err => {
113
+ // eslint-disable-next-line functional/no-conditional-statements
114
+ if (err instanceof _sruClient.SruSearchError) {
115
+ debug(`SRU SruSearchError for query: ${query}: ${err}`);
116
+ reject(new CandidateSearchError(`SRU SruSearchError for query: ${query}: ${err}`));
117
+ }
118
+ debug(`SRU error for query: ${query}: ${err}`);
119
+ reject(new CandidateSearchError(`SRU error for query: ${query}: ${err}`));
120
+ }).on('total', total => {
121
+ debug(`Got total: ${total}`);
122
+ totalRecords += total;
123
+ }).on('end', () => {
124
+ try {
125
+ resolve({
126
+ total: totalRecords
127
+ });
128
+ } catch (err) {
129
+ debug(`Error caught on END`);
130
+ reject(err);
131
+ }
132
+ }).on('record', () => {
133
+ debugDev(`RECORD: We should no get records here`);
134
+ });
135
+ });
136
+ }
137
+ }
138
+ function filterQueryResult({
139
+ queriesWithTotals,
140
+ maxCandidates
141
+ }) {
142
+ debug(`Filtering queries (${queriesWithTotals.length}), maxCandidates: ${maxCandidates}`);
143
+ debugData(`${JSON.stringify(queriesWithTotals)}`);
144
+ // Drop queries where total result is 0 or greater than given maxCandidates
145
+ const filteredQueryResult = queriesWithTotals.filter(queryWithTotal => queryWithTotal.total !== 0 && queryWithTotal.total < maxCandidates);
146
+ debugData(`${JSON.stringify(filteredQueryResult)}`);
147
+ return filteredQueryResult;
148
+ }
149
+ }
150
+ //# sourceMappingURL=choose-queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choose-queries.js","names":["_debug","_interopRequireDefault","require","_sruClient","_interopRequireWildcard","_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","url","queryList","queryListType","maxCandidates","debug","createDebugLogger","debugData","extend","debugDev","client","createClient","maxRecordsPerRequest","version","retrieveAll","JSON","stringify","queriesWithTotals","getQueryTotals","queryOffset","filteredQueryResult","filterQueryResult","err","query","total","retrieveTotal","newQueriesWithTotals","length","Promise","resolve","reject","totalRecords","searchRetrieve","on","SruSearchError","filter","queryWithTotal"],"sources":["../../src/candidate-search/choose-queries.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) 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';\n\nexport class CandidateSearchError extends Error {}\n\nexport default async function ({url, queryList, queryListType, maxCandidates = 50}) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:choose-queries');\n const debugData = debug.extend('data');\n const debugDev = debug.extend('dev');\n\n debugData(`Url: ${url}`);\n debugData(`QueryList: ${queryList}`);\n debugData(`queryListType: ${queryListType}`);\n\n const client = createClient({\n url,\n maxRecordsPerRequest: 0,\n version: '2.0',\n retrieveAll: false\n });\n\n debugDev(`QueryList (type: ${queryListType}) ${JSON.stringify(queryList)}`);\n try {\n const {queriesWithTotals} = await getQueryTotals({queryList, queryOffset: 0, queriesWithTotals: []});\n debugDev(`QueryResult: ${JSON.stringify(queriesWithTotals)}`);\n const filteredQueryResult = filterQueryResult({queriesWithTotals, maxCandidates});\n debugDev(`filteredQueryResult: ${JSON.stringify(filteredQueryResult)}`);\n return filteredQueryResult;\n } catch (err) {\n throw new CandidateSearchError(err);\n }\n\n async function getQueryTotals({queryList, queryOffset = 0, queriesWithTotals = []}) {\n\n const query = queryList[queryOffset];\n debug(`Running query ${JSON.stringify(query)} (${queryOffset}) for total`);\n\n if (query) {\n const {total} = await retrieveTotal();\n\n const newQueriesWithTotals = [...queriesWithTotals, {query, total}];\n debug(`Query ${queryOffset} ${query} done.`);\n debug(`There are (${queryList.length - (queryOffset + 1)} queries left)`);\n return getQueryTotals({queryList, queryOffset: queryOffset + 1, queriesWithTotals: newQueriesWithTotals});\n }\n\n debug(`All ${queryList.length} queries done, there's no query for ${queryOffset}`);\n return {queriesWithTotals};\n\n function retrieveTotal() {\n return new Promise((resolve, reject) => {\n // eslint-disable-next-line functional/no-let\n let totalRecords = 0;\n\n debug(`Searching total amount of candidates for query: ${query}`);\n\n client.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 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', () => {\n try {\n resolve({total: totalRecords});\n } catch (err) {\n debug(`Error caught on END`);\n reject(err);\n }\n })\n .on('record', () => {\n debugDev(`RECORD: We should no get records here`);\n });\n });\n }\n }\n function filterQueryResult({queriesWithTotals, maxCandidates}) {\n debug(`Filtering queries (${queriesWithTotals.length}), maxCandidates: ${maxCandidates}`);\n debugData(`${JSON.stringify(queriesWithTotals)}`);\n // Drop queries where total result is 0 or greater than given maxCandidates\n const filteredQueryResult = queriesWithTotals.filter((queryWithTotal) => queryWithTotal.total !== 0 && queryWithTotal.total < maxCandidates);\n debugData(`${JSON.stringify(filteredQueryResult)}`);\n return filteredQueryResult;\n }\n\n}\n"],"mappings":";;;;;;;AA4BA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAC,uBAAA,CAAAF,OAAA;AAAkE,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,SAAAF,wBAAAE,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,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAA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QAAQ,CAAE,uCAAsC,CAAC;QACnD,CAAC,CAAC;MACN,CAAC,CAAC;IACJ;EACF;EACA,SAASY,iBAAiBA,CAAC;IAACJ,iBAAiB;IAAEb;EAAa,CAAC,EAAE;IAC7DC,KAAK,CAAE,sBAAqBY,iBAAiB,CAACU,MAAO,qBAAoBvB,aAAc,EAAC,CAAC;IACzFG,SAAS,CAAE,GAAEQ,IAAI,CAACC,SAAS,CAACC,iBAAiB,CAAE,EAAC,CAAC;IACjD;IACA,MAAMG,mBAAmB,GAAGH,iBAAiB,CAACkB,MAAM,CAAEC,cAAc,IAAKA,cAAc,CAACZ,KAAK,KAAK,CAAC,IAAIY,cAAc,CAACZ,KAAK,GAAGpB,aAAa,CAAC;IAC5IG,SAAS,CAAE,GAAEQ,IAAI,CAACC,SAAS,CAACI,mBAAmB,CAAE,EAAC,CAAC;IACnD,OAAOA,mBAAmB;EAC5B;AAEF"}
@@ -16,6 +16,7 @@ var _marcRecord = require("@natlibfi/marc-record");
16
16
  var _marcRecordSerializers = require("@natlibfi/marc-record-serializers");
17
17
  var _queryList = _interopRequireWildcard(require("./query-list"));
18
18
  var _melindaCommons = require("@natlibfi/melinda-commons");
19
+ var _chooseQueries = _interopRequireDefault(require("./choose-queries"));
19
20
  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); }
20
21
  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; }
21
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -51,7 +52,7 @@ class CandidateSearchError extends Error {}
51
52
 
52
53
  // serverMaxResults : maximum size of total search result available from the server, defaults to Aleph's 20000
53
54
  exports.CandidateSearchError = CandidateSearchError;
54
- var _default = ({
55
+ var _default = async ({
55
56
  record,
56
57
  searchSpec,
57
58
  url,
@@ -76,6 +77,16 @@ var _default = ({
76
77
  const queryListResult = (0, _queryList.default)(record, searchSpec);
77
78
  const queryList = queryListResult[0]?.queryList ? queryListResult[0].queryList : queryListResult;
78
79
  const queryListType = queryListResult[0]?.queryListType ? queryListResult[0].queryListType : undefined;
80
+
81
+ // if generateQueryList errored we should throw 422
82
+ if (queryList.length === 0) {
83
+ debug(`Empty list`);
84
+ throw new CandidateSearchError(`Generated query list contains no queries`);
85
+ }
86
+ if (queryListType && queryListType !== 'alternates') {
87
+ debug(`Unknown queryListType`);
88
+ throw new CandidateSearchError(`Generated query list has invalid type`);
89
+ }
79
90
  const client = (0, _sruClient.default)({
80
91
  url,
81
92
  maxRecordsPerRequest: adjustedMaxRecordsPerRequest,
@@ -83,30 +94,29 @@ var _default = ({
83
94
  retrieveAll: false
84
95
  });
85
96
  debug(`Searching matches for ${inputRecordId}`);
86
- const chosenQueryList = choseQueries(queryList, queryListType);
87
-
88
- // eslint-disable-next-line require-await
89
- function choseQueries(queryList, queryListType) {
97
+ const chosenQueryList = await filterQueryList({
98
+ queryList,
99
+ queryListType
100
+ });
101
+ debug(`Chosen queries: ${JSON.stringify(chosenQueryList)}`);
102
+ async function filterQueryList({
103
+ queryList,
104
+ queryListType,
105
+ maxCandidates
106
+ }) {
90
107
  debug(`Generated queryList (type: ${queryListType}) ${JSON.stringify(queryList)}`);
91
-
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
108
  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 [];
109
+ const queryListResult = await (0, _chooseQueries.default)({
110
+ url,
111
+ queryList,
112
+ queryListType,
113
+ maxCandidates
114
+ });
115
+ debug(`queryListResult: ${JSON.stringify(queryListResult)}`);
116
+ return queryListResult.map(elem => elem.query);
106
117
  }
107
118
  return queryList;
108
119
  }
109
-
110
120
  // state.totalRecords : amount of candidate records available to the current query (undefined, if there was no queries left)
111
121
  // state.query : current query (undefined if there was no queries left)
112
122
  // state.searchCounter : sequence for current search for current query (undefined, if there we no queries left)
@@ -115,8 +125,12 @@ var _default = ({
115
125
  // state.queryCounter : sequence for current query
116
126
  // state.maxedQueries : queries that resulted in more than serverMaxResults hits
117
127
 
128
+ return {
129
+ search
130
+ };
131
+
118
132
  // eslint-disable-next-line max-statements
119
- return async ({
133
+ async function search({
120
134
  queryOffset = 0,
121
135
  resultSetOffset = 1,
122
136
  totalRecords = 0,
@@ -124,13 +138,7 @@ var _default = ({
124
138
  queryCandidateCounter = 0,
125
139
  queryCounter = 0,
126
140
  maxedQueries = []
127
- }) => {
128
- /*
129
- if (queryListType === 'alternates') {
130
- debug('Alternates - stop here');
131
- return {records: [], failures: [], queriesLeft: 0, queryCounter, maxedQueries};
132
- }
133
- */
141
+ }) {
134
142
  const query = chosenQueryList[queryOffset];
135
143
  debug(`Running query ${JSON.stringify(query)} (${queryOffset})`);
136
144
  if (query) {
@@ -259,31 +267,7 @@ var _default = ({
259
267
  });
260
268
  });
261
269
  }
262
- };
263
-
264
- /*
265
- async function retrieveTotal(query) {
266
- debug(`Searching for candidateTotals with query: ${query}`);
267
- totalClient.searchRetrieve(query)
268
- .on('error', err => {
269
- // eslint-disable-next-line functional/no-conditional-statements
270
- if (err instanceof SruSearchError) {
271
- debug(`SRU SruSearchError for query: ${query}: ${err}`);
272
- throw new CandidateSearchError(`SRU SruSearchError for getting total for query: ${query}: ${err}`);
273
- }
274
- debug(`SRU error for query: ${query}: ${err}`);
275
- throw new CandidateSearchError(`SRU error for getting total for query: ${query}: ${err}`);
276
- })
277
- .on('total', total => {
278
- debug(`Got total: ${total}`);
279
- return {query, total};
280
- })
281
- .on('end', end => {
282
- debug(`End ${JSON.stringify(end)}`);
283
- });
284
270
  }
285
- */
286
-
287
271
  function checkMaxedQuery(query, total, serverMaxResult) {
288
272
  if (total >= serverMaxResult) {
289
273
  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","queryListResult","generateQueryList","queryList","queryListType","undefined","client","createClient","version","retrieveAll","chosenQueryList","choseQueries","length","queryOffset","resultSetOffset","totalRecords","searchCounter","queryCandidateCounter","queryCounter","maxedQueries","query","records","failures","nextOffset","total","retrieveRecords","newTotalRecords","newQueryCounter","newSearchCounter","newQueryCandidateCounter","maxedQuery","checkMaxedQuery","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-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\n /*\n if (queryListType === 'alternates') {\n debug('Alternates - stop here');\n return {records: [], failures: [], queriesLeft: 0, queryCounter, maxedQueries};\n }\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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AAK,CAAE,sEAAqE6D,SAAS,CAACzC,MAAO,GAAE,CAAC;IAChG,OAAOP,SAAS;EAClB;AAEF,CAAC;AAAAxB,OAAA,CAAAlB,OAAA,GAAAmB,QAAA"}
1
+ {"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","_sruClient","_interopRequireWildcard","_marcRecord","_marcRecordSerializers","_queryList","_melindaCommons","_chooseQueries","_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","length","client","createClient","version","retrieveAll","chosenQueryList","filterQueryList","chooseQueries","map","elem","query","search","queryOffset","resultSetOffset","totalRecords","searchCounter","queryCandidateCounter","queryCounter","maxedQueries","records","failures","nextOffset","total","retrieveRecords","newTotalRecords","newQueryCounter","newSearchCounter","newQueryCandidateCounter","maxedQuery","checkMaxedQuery","newMaxedQueries","concat","queriesLeft","Promise","resolve","reject","promises","searchRetrieve","startRecord","on","err","SruSearchError","recordPromises","allSettled","filtered","filter","status","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';\nimport chooseQueries from './choose-queries';\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 async ({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 // if generateQueryList errored we should throw 422\n if (queryList.length === 0) {\n debug(`Empty list`);\n throw new CandidateSearchError(`Generated query list contains no queries`);\n }\n if (queryListType && queryListType !== 'alternates') {\n debug(`Unknown queryListType`);\n throw new CandidateSearchError(`Generated query list has invalid type`);\n }\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 = await filterQueryList({queryList, queryListType});\n debug(`Chosen queries: ${JSON.stringify(chosenQueryList)}`);\n\n async function filterQueryList({queryList, queryListType, maxCandidates}) {\n debug(`Generated queryList (type: ${queryListType}) ${JSON.stringify(queryList)}`);\n\n if (queryListType === 'alternates' && queryList.length > 1) {\n const queryListResult = await chooseQueries({url, queryList, queryListType, maxCandidates});\n debug(`queryListResult: ${JSON.stringify(queryListResult)}`);\n return queryListResult.map(elem => elem.query);\n }\n return queryList;\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 return {search};\n\n // eslint-disable-next-line max-statements\n async function search({queryOffset = 0, resultSetOffset = 1, totalRecords = 0, searchCounter = 0, queryCandidateCounter = 0, queryCounter = 0, 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 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"],"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,CAA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;gBAAEI,EAAE,EAAED;cAAQ,CAAC;YAC3C,CAAC,CAAC,OAAOhB,GAAG,EAAE;cACZ;cACA,MAAMkB,SAAS,GAAGC,kBAAkB,CAACT,SAAS,CAAC;cAC/C9D,SAAS,CAAE,6BAA4BoD,GAAG,CAACoB,OAAQ,SAAQF,SAAU,WAAUR,SAAU,EAAC,CAAC;cAC3F;cACA,MAAM,IAAIW,qBAAa,CAAC,GAAG,EAAE;gBAACD,OAAO,EAAG,6BAA4BpB,GAAG,CAACoB,OAAQ,EAAC;gBAAEH,EAAE,EAAEC,SAAS,IAAI,WAAW;gBAAEI,IAAI,EAAEZ;cAAS,CAAC,CAAC;YACpI;UACF;QACF,CAAC,CAAC;MACN,CAAC,CAAC;IACJ;EACF;EAEA,SAASrB,eAAeA,CAACnB,KAAK,EAAEY,KAAK,EAAExC,eAAe,EAAE;IACtD,IAAIwC,KAAK,IAAIxC,eAAe,EAAE;MAC5BI,KAAK,CAAE,kBAAiBwB,KAAM,gBAAeY,KAAM,0CAAyCxC,eAAgB,IAAG,CAAC;MAChH,OAAO4B,KAAK;IACd;EACF;EAEA,SAAShB,WAAWA,CAACjB,MAAM,EAAE;IAC3B,MAAM,CAACsF,KAAK,CAAC,GAAGtF,MAAM,CAAClB,GAAG,CAAC,QAAQ,CAAC;IACpC,OAAOwG,KAAK,GAAGA,KAAK,CAAChB,KAAK,GAAG,EAAE;EACjC;EAEA,SAASY,kBAAkBA,CAACT,SAAS,EAAE;IACrC;IACAhE,KAAK,CAAE,sEAAqEgE,SAAS,CAAClD,MAAO,GAAE,CAAC;IAChG,OAAOD,SAAS;EAClB;AACF,CAAC;AAAAxB,OAAA,CAAAlB,OAAA,GAAAmB,QAAA"}
@@ -48,6 +48,8 @@ describe('candidate-search', () => {
48
48
  reader: _fixura.READERS.JSON
49
49
  }
50
50
  });
51
+
52
+ // eslint-disable-next-line max-statements
51
53
  async function callback({
52
54
  getFixture,
53
55
  factoryOptions,
@@ -61,23 +63,38 @@ describe('candidate-search', () => {
61
63
  return;
62
64
  }
63
65
  if (expectedFactoryError) {
66
+ debug(`We're expecting an error`);
64
67
  if (expectedFactoryError.isCandidateSearchError) {
65
- (0, _chai.expect)(() => (0, _.default)({
68
+ try {
69
+ const result = (0, _.default)({
70
+ ...formatFactoryOptions(),
71
+ url
72
+ });
73
+ debug(result);
74
+ } catch (err) {
75
+ (0, _chai.expect)(err).to.equal(new _.CandidateSearchError(expectedFactoryError));
76
+ }
77
+ return;
78
+ }
79
+ try {
80
+ const result = (0, _.default)({
66
81
  ...formatFactoryOptions(),
67
82
  url
68
- })).to.throw(_.CandidateSearchError, new RegExp(expectedFactoryError, 'u'));
69
- return;
83
+ });
84
+ debug(result);
85
+ } catch (err) {
86
+ (0, _chai.expect)(err).to.equal(new Error(expectedFactoryError));
70
87
  }
71
- (0, _chai.expect)(() => (0, _.default)({
72
- ...formatFactoryOptions(),
73
- url
74
- })).to.throw(new RegExp(expectedFactoryError, 'u'));
75
88
  return;
76
89
  }
77
- const search = (0, _.default)({
90
+ const {
91
+ search
92
+ } = await (0, _.default)({
78
93
  ...formatFactoryOptions(),
79
94
  url
80
95
  });
96
+ // eslint-disable-next-line no-console
97
+ console.log(search);
81
98
  await iterate({
82
99
  searchOptions,
83
100
  expectedSearchError
@@ -1 +1 @@
1
- {"version":3,"file":"index.spec.js","names":["_chai","require","_fixura","_fixugenHttpClient","_interopRequireDefault","_marcRecord","_melindaCommons","_","_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","describe","generateTests","callback","path","__dirname","recurse","fixura","reader","READERS","JSON","getFixture","factoryOptions","searchOptions","expectedFactoryError","expectedSearchError","enabled","url","isCandidateSearchError","expect","createSearchInterface","formatFactoryOptions","to","throw","CandidateSearchError","RegExp","search","iterate","stringify","maxRecordsPerRequest","maxServerResults","undefined","record","MarcRecord","subfieldValues","expectedErrorStatus","count","expectedResults","Error","err","be","an","errorMessage","MatchingError","payload","message","errorStatus","status","match","results","formatResults","eql","records","map","id","toObject"],"sources":["../../src/candidate-search/index.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-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 {expect} from 'chai';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen-http-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as MatchingError} from '@natlibfi/melinda-commons';\nimport createSearchInterface, {CandidateSearchError} from '.';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:test');\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 async function callback({getFixture, factoryOptions, searchOptions, expectedFactoryError = false, expectedSearchError = false, 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, expectedSearchError});\n\n function formatFactoryOptions() {\n debug(`Using factoryOptions: ${JSON.stringify(factoryOptions)}`);\n return {\n ...factoryOptions,\n maxRecordsPerRequest: factoryOptions.maxRecordsPerRequest || 1,\n maxServerResults: factoryOptions.maxServerResults || undefined,\n record: new MarcRecord(factoryOptions.record, {subfieldValues: false})\n };\n }\n\n async function iterate({searchOptions, expectedSearchError, expectedErrorStatus, count = 1}) {\n const expectedResults = getFixture(`expectedResults${count}.json`);\n\n if (expectedSearchError) { // eslint-disable-line functional/no-conditional-statements\n try {\n await search(searchOptions);\n throw new Error('Expected an error');\n } catch (err) {\n debug(`Got an error: ${err}`);\n expect(err).to.be.an('error');\n const errorMessage = err instanceof MatchingError ? err.payload.message : err.message;\n const errorStatus = err instanceof MatchingError ? err.status : undefined;\n debug(`errorMessage: ${errorMessage}, errorStatus: ${errorStatus}`);\n expect(errorMessage).to.match(new RegExp(expectedSearchError, 'u'));\n\n if (expectedErrorStatus) {\n expect(errorStatus).to.be(expectedErrorStatus);\n return;\n }\n return;\n }\n }\n\n // eslint-disable-next-line functional/no-conditional-statements\n if (!expectedSearchError) {\n const results = await search(searchOptions);\n expect(formatResults(results)).to.eql(expectedResults);\n }\n\n function formatResults(results) {\n debug(results);\n return {\n ...results,\n records: results.records.map(({record, id}) => ({id, record: record.toObject()}))\n };\n }\n\n }\n }\n});\n"],"mappings":";;AA4BA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,eAAA,GAAAL,OAAA;AACA,IAAAM,CAAA,GAAAC,uBAAA,CAAAP,OAAA;AACA,IAAAQ,M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,SAAS;UACzEhC,KAAK,CAAE,iBAAgB2C,YAAa,kBAAiBI,WAAY,EAAC,CAAC;UACnE,IAAA3B,YAAM,EAACuB,YAAY,CAAC,CAACpB,EAAE,CAAC0B,KAAK,CAAC,IAAIvB,MAAM,CAACV,mBAAmB,EAAE,GAAG,CAAC,CAAC;UAEnE,IAAIoB,mBAAmB,EAAE;YACvB,IAAAhB,YAAM,EAAC2B,WAAW,CAAC,CAACxB,EAAE,CAACkB,EAAE,CAACL,mBAAmB,CAAC;YAC9C;UACF;UACA;QACF;MACF;;MAEA;MACA,IAAI,CAACpB,mBAAmB,EAAE;QACxB,MAAMkC,OAAO,GAAG,MAAMvB,MAAM,CAACb,aAAa,CAAC;QAC3C,IAAAM,YAAM,EAAC+B,aAAa,CAACD,OAAO,CAAC,CAAC,CAAC3B,EAAE,CAAC6B,GAAG,CAACd,eAAe,CAAC;MACxD;MAEA,SAASa,aAAaA,CAACD,OAAO,EAAE;QAC9BlD,KAAK,CAACkD,OAAO,CAAC;QACd,OAAO;UACL,GAAGA,OAAO;UACVG,OAAO,EAAEH,OAAO,CAACG,OAAO,CAACC,GAAG,CAAC,CAAC;YAACrB,MAAM;YAAEsB;UAAE,CAAC,MAAM;YAACA,EAAE;YAAEtB,MAAM,EAAEA,MAAM,CAACuB,QAAQ,CAAC;UAAC,CAAC,CAAC;QAClF,CAAC;MACH;IAEF;EACF;AACF,CAAC,CAAC"}
1
+ {"version":3,"file":"index.spec.js","names":["_chai","require","_fixura","_fixugenHttpClient","_interopRequireDefault","_marcRecord","_melindaCommons","_","_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","describe","generateTests","callback","path","__dirname","recurse","fixura","reader","READERS","JSON","getFixture","factoryOptions","searchOptions","expectedFactoryError","expectedSearchError","enabled","url","isCandidateSearchError","result","createSearchInterface","formatFactoryOptions","err","expect","to","equal","CandidateSearchError","Error","search","console","log","iterate","stringify","maxRecordsPerRequest","maxServerResults","undefined","record","MarcRecord","subfieldValues","expectedErrorStatus","count","expectedResults","be","an","errorMessage","MatchingError","payload","message","errorStatus","status","match","RegExp","results","formatResults","eql","records","map","id","toObject"],"sources":["../../src/candidate-search/index.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-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 {expect} from 'chai';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen-http-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as MatchingError} from '@natlibfi/melinda-commons';\nimport createSearchInterface, {CandidateSearchError} from '.';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:test');\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 = false, expectedSearchError = false, enabled = true}) {\n const url = 'http://foo.bar';\n\n if (!enabled) {\n return;\n }\n\n if (expectedFactoryError) {\n debug(`We're expecting an error`);\n if (expectedFactoryError.isCandidateSearchError) {\n try {\n const result = createSearchInterface({...formatFactoryOptions(), url});\n debug(result);\n } catch (err) {\n expect(err).to.equal(new CandidateSearchError(expectedFactoryError));\n }\n return;\n }\n\n try {\n const result = createSearchInterface({...formatFactoryOptions(), url});\n debug(result);\n } catch (err) {\n expect(err).to.equal(new Error(expectedFactoryError));\n }\n return;\n }\n\n const {search} = await createSearchInterface({...formatFactoryOptions(), url});\n // eslint-disable-next-line no-console\n console.log(search);\n await iterate({searchOptions, expectedSearchError});\n\n function formatFactoryOptions() {\n debug(`Using factoryOptions: ${JSON.stringify(factoryOptions)}`);\n return {\n ...factoryOptions,\n maxRecordsPerRequest: factoryOptions.maxRecordsPerRequest || 1,\n maxServerResults: factoryOptions.maxServerResults || undefined,\n record: new MarcRecord(factoryOptions.record, {subfieldValues: false})\n };\n }\n\n async function iterate({searchOptions, expectedSearchError, expectedErrorStatus, count = 1}) {\n const expectedResults = getFixture(`expectedResults${count}.json`);\n\n if (expectedSearchError) { // eslint-disable-line functional/no-conditional-statements\n try {\n await search(searchOptions);\n throw new Error('Expected an error');\n } catch (err) {\n debug(`Got an error: ${err}`);\n expect(err).to.be.an('error');\n const errorMessage = err instanceof MatchingError ? err.payload.message : err.message;\n const errorStatus = err instanceof MatchingError ? err.status : undefined;\n debug(`errorMessage: ${errorMessage}, errorStatus: ${errorStatus}`);\n expect(errorMessage).to.match(new RegExp(expectedSearchError, 'u'));\n\n if (expectedErrorStatus) {\n expect(errorStatus).to.be(expectedErrorStatus);\n return;\n }\n return;\n }\n }\n\n // eslint-disable-next-line functional/no-conditional-statements\n if (!expectedSearchError) {\n const results = await search(searchOptions);\n expect(formatResults(results)).to.eql(expectedResults);\n }\n\n function formatResults(results) {\n debug(results);\n return {\n ...results,\n records: results.records.map(({record, id}) => ({id, record: record.toObject()}))\n };\n }\n\n }\n }\n});\n"],"mappings":";;AA4BA,IAAAA,KAAA,GAAAC,OAAA;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qB;UAAE,CAAC,MAAM;YAACA,EAAE;YAAErB,MAAM,EAAEA,MAAM,CAACsB,QAAQ,CAAC;UAAC,CAAC,CAAC;QAClF,CAAC;MACH;IAEF;EACF;AACF,CAAC,CAAC"}
@@ -204,15 +204,16 @@ function bibTitleAuthorYearAlternates(record) {
204
204
  debug('bibTitleAuthorYearAlternates');
205
205
  // We use onlyTitleLength that is longer than our formatted length to
206
206
  // get an author or an publisher always
207
-
207
+ const origQueryList = bibTitleAuthorPublisher({
208
+ record,
209
+ onlyTitleLength: 100,
210
+ addYear: true,
211
+ alternates: true,
212
+ alternateQueries: []
213
+ });
214
+ debug(`${JSON.stringify(origQueryList)}`);
208
215
  return {
209
- queryList: bibTitleAuthorPublisher({
210
- record,
211
- onlyTitleLength: 100,
212
- addYear: true,
213
- alternates: true,
214
- alternateQueries: []
215
- }),
216
+ queryList: Array.from(origQueryList).reverse(),
216
217
  queryListType: 'alternates'
217
218
  };
218
219
  }