@natlibfi/melinda-record-matching 4.3.3 → 4.3.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.
Files changed (55) hide show
  1. package/dist/candidate-search/candidate-search-utils.js +1 -1
  2. package/dist/candidate-search/candidate-search-utils.js.map +1 -1
  3. package/dist/candidate-search/choose-queries.js +1 -1
  4. package/dist/candidate-search/choose-queries.js.map +1 -1
  5. package/dist/candidate-search/index.js +1 -1
  6. package/dist/candidate-search/index.js.map +1 -1
  7. package/dist/candidate-search/index.spec.js +1 -1
  8. package/dist/candidate-search/index.spec.js.map +1 -1
  9. package/dist/candidate-search/query-list/bib.js +1 -1
  10. package/dist/candidate-search/query-list/bib.js.map +1 -1
  11. package/dist/candidate-search/query-list/bib.spec.js +1 -1
  12. package/dist/candidate-search/query-list/bib.spec.js.map +1 -1
  13. package/dist/candidate-search/query-list/index.js +1 -1
  14. package/dist/candidate-search/query-list/index.js.map +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.spec.js +1 -1
  18. package/dist/index.spec.js.map +1 -1
  19. package/dist/match-detection/features/bib/all-source-ids.js +1 -1
  20. package/dist/match-detection/features/bib/all-source-ids.js.map +1 -1
  21. package/dist/match-detection/features/bib/index.js +1 -1
  22. package/dist/match-detection/features/bib/index.js.map +1 -1
  23. package/dist/match-detection/features/bib/index.spec.js +1 -1
  24. package/dist/match-detection/features/bib/index.spec.js.map +1 -1
  25. package/dist/match-detection/features/bib/isbn.js +1 -1
  26. package/dist/match-detection/features/bib/isbn.js.map +1 -1
  27. package/dist/match-detection/features/bib/issn.js +1 -1
  28. package/dist/match-detection/features/bib/issn.js.map +1 -1
  29. package/dist/match-detection/features/bib/language.js +1 -1
  30. package/dist/match-detection/features/bib/language.js.map +1 -1
  31. package/dist/match-detection/features/bib/media-type.js +1 -1
  32. package/dist/match-detection/features/bib/media-type.js.map +1 -1
  33. package/dist/match-detection/features/bib/melinda-id.js +1 -1
  34. package/dist/match-detection/features/bib/melinda-id.js.map +1 -1
  35. package/dist/match-detection/features/bib/melinda-identifier-factory.js +1 -1
  36. package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +1 -1
  37. package/dist/match-detection/features/bib/other-standard-identifier.js +1 -1
  38. package/dist/match-detection/features/bib/other-standard-identifier.js.map +1 -1
  39. package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js +1 -1
  40. package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js.map +1 -1
  41. package/dist/match-detection/features/bib/publication-time-allow-cons-years.js +1 -1
  42. package/dist/match-detection/features/bib/publication-time-allow-cons-years.js.map +1 -1
  43. package/dist/match-detection/features/bib/standard-identifier-factory.js +1 -1
  44. package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -1
  45. package/dist/match-detection/features/bib/title-version-original.js +1 -1
  46. package/dist/match-detection/features/bib/title-version-original.js.map +1 -1
  47. package/dist/match-detection/features/bib/title.js +1 -1
  48. package/dist/match-detection/features/bib/title.js.map +1 -1
  49. package/dist/match-detection/index.js +1 -1
  50. package/dist/match-detection/index.js.map +1 -1
  51. package/dist/match-detection/index.spec.js +1 -1
  52. package/dist/match-detection/index.spec.js.map +1 -1
  53. package/dist/matching-utils.js +1 -1
  54. package/dist/matching-utils.js.map +1 -1
  55. package/package.json +24 -24
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.toQueries = toQueries;
7
7
  var _debug = _interopRequireDefault(require("debug"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
9
  function toQueries(identifiers, queryString) {
10
10
  const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:toQueries');
11
11
  const debugData = debug.extend('data');
@@ -1 +1 @@
1
- {"version":3,"file":"candidate-search-utils.js","names":["_debug","_interopRequireDefault","require","obj","__esModule","default","toQueries","identifiers","queryString","debug","createDebugLogger","debugData","extend","quotedIdentifiers","map","identifier","match","pairs","toPairs","queries","a","b","length","JSON","stringify","array","slice","concat"],"sources":["../../src/candidate-search/candidate-search-utils.js"],"sourcesContent":["import 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"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAsC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE/B,SAASG,SAASA,CAACC,WAAW,EAAEC,WAAW,EAAE;EAElD,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,6CAA6C,CAAC;EAC9E,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;EAEtC,MAAMC,iBAAiB,GAAGN,WAAW,CAACO,GAAG,CAACC,UAAU,IAAIA,UAAU,CAACC,KAAK,CAAC,KAAK,CAAC,GAAI,IAAGD,UAAW,GAAE,GAAI,GAAEA,UAAW,EAAC,CAAC;;EAEtH;EACA,MAAME,KAAK,GAAGC,OAAO,CAACL,iBAAiB,CAAC;EACxC,MAAMM,OAAO,GAAGF,KAAK,CAACH,GAAG,CAAC,CAAC,CAACM,CAAC,EAAEC,CAAC,CAAC,KAAKA,CAAC,GAAI,GAAEb,WAAY,IAAGY,CAAE,OAAMZ,WAAY,IAAGa,CAAE,EAAC,GAAI,GAAEb,WAAY,IAAGY,CAAE,EAAC,CAAC;EAE/GT,SAAS,CAAE,UAASM,KAAK,CAACK,MAAO,MAAKC,IAAI,CAACC,SAAS,CAACP,KAAK,CAAE,EAAC,CAAC;EAC9DN,SAAS,CAAE,YAAWQ,OAAO,CAACG,MAAO,MAAKC,IAAI,CAACC,SAAS,CAACL,OAAO,CAAE,EAAC,CAAC;EAEpE,OAAOA,OAAO;AAChB;AAEA,SAASD,OAAOA,CAACO,KAAK,EAAE;EACtB,IAAIA,KAAK,CAACH,MAAM,KAAK,CAAC,EAAE;IACtB,OAAO,EAAE;EACX;EACA,OAAO,CAACG,KAAK,CAACC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACC,MAAM,CAACT,OAAO,CAACO,KAAK,CAACC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/D","ignoreList":[]}
1
+ {"version":3,"file":"candidate-search-utils.js","names":["_debug","_interopRequireDefault","require","e","__esModule","default","toQueries","identifiers","queryString","debug","createDebugLogger","debugData","extend","quotedIdentifiers","map","identifier","match","pairs","toPairs","queries","a","b","length","JSON","stringify","array","slice","concat"],"sources":["../../src/candidate-search/candidate-search-utils.js"],"sourcesContent":["import 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"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAsC,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE/B,SAASG,SAASA,CAACC,WAAW,EAAEC,WAAW,EAAE;EAElD,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,6CAA6C,CAAC;EAC9E,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;EAEtC,MAAMC,iBAAiB,GAAGN,WAAW,CAACO,GAAG,CAACC,UAAU,IAAIA,UAAU,CAACC,KAAK,CAAC,KAAK,CAAC,GAAG,IAAID,UAAU,GAAG,GAAG,GAAGA,UAAU,EAAE,CAAC;;EAEtH;EACA,MAAME,KAAK,GAAGC,OAAO,CAACL,iBAAiB,CAAC;EACxC,MAAMM,OAAO,GAAGF,KAAK,CAACH,GAAG,CAAC,CAAC,CAACM,CAAC,EAAEC,CAAC,CAAC,KAAKA,CAAC,GAAG,GAAGb,WAAW,IAAIY,CAAC,OAAOZ,WAAW,IAAIa,CAAC,EAAE,GAAG,GAAGb,WAAW,IAAIY,CAAC,EAAE,CAAC;EAE/GT,SAAS,CAAC,UAAUM,KAAK,CAACK,MAAM,MAAMC,IAAI,CAACC,SAAS,CAACP,KAAK,CAAC,EAAE,CAAC;EAC9DN,SAAS,CAAC,YAAYQ,OAAO,CAACG,MAAM,MAAMC,IAAI,CAACC,SAAS,CAACL,OAAO,CAAC,EAAE,CAAC;EAEpE,OAAOA,OAAO;AAChB;AAEA,SAASD,OAAOA,CAACO,KAAK,EAAE;EACtB,IAAIA,KAAK,CAACH,MAAM,KAAK,CAAC,EAAE;IACtB,OAAO,EAAE;EACX;EACA,OAAO,CAACG,KAAK,CAACC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACC,MAAM,CAACT,OAAO,CAACO,KAAK,CAACC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/D","ignoreList":[]}
@@ -9,7 +9,7 @@ var _debug = _interopRequireDefault(require("debug"));
9
9
  var _sruClient = _interopRequireWildcard(require("@natlibfi/sru-client"));
10
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
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 && {}.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 }; }
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
13
  class CandidateSearchError extends Error {}
14
14
  exports.CandidateSearchError = CandidateSearchError;
15
15
  async function _default({
@@ -1 +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","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":["import 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":";;;;;;;AAAA,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,EAAA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K,EAAE,MAAM;UACf,IAAI;YACFJ,OAAO,CAAC;cAACL,KAAK,EAAEO;YAAY,CAAC,CAAC;UAChC,CAAC,CAAC,OAAOT,GAAG,EAAE;YACZjB,KAAK,CAAE,qBAAoB,CAAC;YAC5ByB,MAAM,CAACR,GAAG,CAAC;UACb;QACF,CAAC,CAAC,CACDW,EAAE,CAAC,QAAQ,EAAE,MAAM;UAClBxB,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","ignoreList":[]}
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","hasOwnProperty","call","i","set","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":["import 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":";;;;;;;AAAA,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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,GAAG,EAAE;YACZjB,KAAK,CAAC,qBAAqB,CAAC;YAC5ByB,MAAM,CAACR,GAAG,CAAC;UACb;QACF,CAAC,CAAC,CACDW,EAAE,CAAC,QAAQ,EAAE,MAAM;UAClBxB,QAAQ,CAAC,uCAAuC,CAAC;QACnD,CAAC,CAAC;MACN,CAAC,CAAC;IACJ;EACF;EACA,SAASY,iBAAiBA,CAAC;IAACJ,iBAAiB;IAAEb;EAAa,CAAC,EAAE;IAC7DC,KAAK,CAAC,sBAAsBY,iBAAiB,CAACU,MAAM,qBAAqBvB,aAAa,EAAE,CAAC;IACzFG,SAAS,CAAC,GAAGQ,IAAI,CAACC,SAAS,CAACC,iBAAiB,CAAC,EAAE,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,CAAC,GAAGQ,IAAI,CAACC,SAAS,CAACI,mBAAmB,CAAC,EAAE,CAAC;IACnD,OAAOA,mBAAmB;EAC5B;AAEF","ignoreList":[]}
@@ -19,7 +19,7 @@ var _melindaCommons = require("@natlibfi/melinda-commons");
19
19
  var _chooseQueries = _interopRequireDefault(require("./choose-queries"));
20
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); }
21
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 && {}.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; }
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
23
23
  class CandidateSearchError extends Error {}
24
24
 
25
25
  // serverMaxResults : maximum size of total search result available from the server, defaults to Aleph's 20000
@@ -1 +1 @@
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","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":["import 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":";;;;;;;;;;;;AAAA,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;AACA,IAAAO,cAAA,GAAAR,sBAAA,CAAAC,OAAA;AAA6C,SAAAQ,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,SAAAP,wBAAAO,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK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,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,CAACjB,GAAG,CAAC,QAAQ,CAAC;IACpC,OAAOuG,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,CAAAjB,OAAA,GAAAkB,QAAA","ignoreList":[]}
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","hasOwnProperty","call","i","set","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":["import 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":";;;;;;;;;;;;AAAA,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;AACA,IAAAO,cAAA,GAAAR,sBAAA,CAAAC,OAAA;AAA6C,SAAAQ,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAA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,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,CAAC,kBAAkBwB,KAAK,gBAAgBY,KAAK,0CAA0CxC,eAAe,IAAI,CAAC;MAChH,OAAO4B,KAAK;IACd;EACF;EAEA,SAAShB,WAAWA,CAACjB,MAAM,EAAE;IAC3B,MAAM,CAACsF,KAAK,CAAC,GAAGtF,MAAM,CAAChB,GAAG,CAAC,QAAQ,CAAC;IACpC,OAAOsG,KAAK,GAAGA,KAAK,CAAChB,KAAK,GAAG,EAAE;EACjC;EAEA,SAASY,kBAAkBA,CAACT,SAAS,EAAE;IACrC;IACAhE,KAAK,CAAC,sEAAsEgE,SAAS,CAAClD,MAAM,GAAG,CAAC;IAChG,OAAOD,SAAS;EAClB;AACF,CAAC;AAAAxB,OAAA,CAAAhB,OAAA,GAAAiB,QAAA","ignoreList":[]}
@@ -9,7 +9,7 @@ var _ = _interopRequireWildcard(require("."));
9
9
  var _debug = _interopRequireDefault(require("debug"));
10
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
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 && {}.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 }; }
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
13
  const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:test');
14
14
  describe('candidate-search', () => {
15
15
  (0, _fixugenHttpClient.default)({
@@ -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","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":["import {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 }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MACH;IAEF;EACF;AACF,CAAC,CAAC","ignoreList":[]}
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","hasOwnProperty","call","i","set","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":["import {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":";;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAA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C,OAAO,CAAC;UAC7B,MAAMC,YAAY,GAAGtB,GAAG,YAAYuB,qBAAa,GAAGvB,GAAG,CAACwB,OAAO,CAACC,OAAO,GAAGzB,GAAG,CAACyB,OAAO;UACrF,MAAMC,WAAW,GAAG1B,GAAG,YAAYuB,qBAAa,GAAGvB,GAAG,CAAC2B,MAAM,GAAGd,SAAS;UACzEpC,KAAK,CAAC,iBAAiB6C,YAAY,kBAAkBI,WAAW,EAAE,CAAC;UACnE,IAAAzB,YAAM,EAACqB,YAAY,CAAC,CAACpB,EAAE,CAAC0B,KAAK,CAAC,IAAIC,MAAM,CAACpC,mBAAmB,EAAE,GAAG,CAAC,CAAC;UAEnE,IAAIwB,mBAAmB,EAAE;YACvB,IAAAhB,YAAM,EAACyB,WAAW,CAAC,CAACxB,EAAE,CAACkB,EAAE,CAACH,mBAAmB,CAAC;YAC9C;UACF;UACA;QACF;MACF;;MAEA;MACA,IAAI,CAACxB,mBAAmB,EAAE;QACxB,MAAMqC,OAAO,GAAG,MAAMxB,MAAM,CAACf,aAAa,CAAC;QAC3C,IAAAU,YAAM,EAAC8B,aAAa,CAACD,OAAO,CAAC,CAAC,CAAC5B,EAAE,CAAC8B,GAAG,CAACb,eAAe,CAAC;MACxD;MAEA,SAASY,aAAaA,CAACD,OAAO,EAAE;QAC9BrD,KAAK,CAACqD,OAAO,CAAC;QACd,OAAO;UACL,GAAGA,OAAO;UACVG,OAAO,EAAEH,OAAO,CAACG,OAAO,CAACC,GAAG,CAAC,CAAC;YAACpB,MAAM;YAAEqB;UAAE,CAAC,MAAM;YAACA,EAAE;YAAErB,MAAM,EAAEA,MAAM,CAACsB,QAAQ,CAAC;UAAC,CAAC,CAAC;QAClF,CAAC;MACH;IAEF;EACF;AACF,CAAC,CAAC","ignoreList":[]}
@@ -19,7 +19,7 @@ exports.checkUseWordSearch = checkUseWordSearch;
19
19
  var _debug = _interopRequireDefault(require("debug"));
20
20
  var _candidateSearchUtils = require("../candidate-search-utils");
21
21
  var _matchingUtils = require("../../matching-utils");
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
23
23
  const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:query');
24
24
  function bibSourceIds(record) {
25
25
  /* Melinda's SRU-index melinda.sourceid includes source IDs from SID fields in Melinda records
@@ -1 +1 @@
1
- {"version":3,"file":"bib.js","names":["_debug","_interopRequireDefault","require","_candidateSearchUtils","_matchingUtils","obj","__esModule","default","debug","createDebugLogger","bibSourceIds","record","debugData","extend","fSids","get","length","JSON","stringify","toSidQueries","sidStrings","getSidStrings","sidQueries","toQueries","map","toSidString","filter","nonEmptySid","field","validateSidFieldSubfieldCounts","createSidString","sfC","getSubfieldValues","sfB","cleanedSfC","removeSourcePrefix","normalizeSidSubfieldValue","cleanedSfB","concat","subfieldValue","sourcePrefixRegex","normalizedValue","testStringOrNumber","String","replace","normalizeAwayRegex","bibMelindaIds","melindaIds","getMelindaIdsF035","bibHostComponents","id","getHostId","value","subfields","find","code","test","bibTitle","bibTitleAuthorPublisher","onlyTitleLength","bibTitleAuthor","bibTitleAuthorYear","addYear","bibTitleAuthorYearAlternates","origQueryList","alternates","alternateQueries","queryList","Array","from","reverse","queryListType","title","getTitle","formatted","trim","slice","useWordSearch","checkUseWordSearch","queryIsOkAlone","query","newAlternateQueries","addAuthorsToSearch","authorQuery","bibAuthors","undefined","addYearToSearch","addPublisherToSearch","publisherQuery","bibPublishers","yearQuery","bibYear","titleString","includes","join","author","getAuthor","authorString","publisher","getPublisher","publisherString","year","getYear","booleanStartWords","some","word","toLowerCase","startsWith","bibStandardIdentifiers","fields","identifiers","toIdentifiers","uniqueIdentifiers","Set","tag","issnIsbnReqExp","otherIdReqExp","sub"],"sources":["../../../src/candidate-search/query-list/bib.js"],"sourcesContent":["import createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils';\nimport {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} from '../../matching-utils';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query');\n\nexport function bibSourceIds(record) {\n\n /* Melinda's SRU-index melinda.sourceid includes source IDs from SID fields in Melinda records\n SID-fields in Melinda have sf $c with local id and sf $b with a code for the local db:\n\n SID__ $c 123457 $b helka\n SID__ $c (ANDL100020)1077305 $b sata\n SID__ $c VER999999 $ FI-KV\n SID__ $c /10024/508126 $ REPO_THESEUS\n\n In melinda.sourceid -index case is kept, sourceprefixes in brackets and hyphens are normalized away:\n Note: slashes are not normalized away, but a SRU-search-string including slashes needs to be quoted\n\n 1234567helka\n 1077305sata\n VER999999FIKV\n /10024/508126REPO_THESEUS\n\n Note: All Melinda records that have a matching records in a local db do NOT have SID for that local records,\n existence of a SID field depends on how the record has been added to Melinda and how it has been handled\n afterwards. SIDs are also not reliably maintained. A record might or might not have a SID for a local db\n after the matching record is removed from the local db.\n\n */\n\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:source-ids');\n const debugData = debug.extend('data');\n //const debugInfo = debug.extend('info');\n\n debug(`Creating queries for sourceid's`);\n\n const fSids = record.get('SID');\n debugData(`SID-fields (${fSids.length}): ${JSON.stringify(fSids)}`);\n\n return fSids.length > 0 ? toSidQueries(fSids) : [];\n\n function toSidQueries(fSids) {\n debug(`Creating actual queries for sourceid's`);\n\n const sidStrings = getSidStrings(fSids);\n\n if (sidStrings.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n const sidQueries = toQueries(sidStrings, 'melinda.sourceid');\n\n return sidQueries;\n\n function getSidStrings(fSids) {\n debug(`Getting Sid strings from SID fields`);\n\n // Map SID fields to valid sidStrings, filter out empty strings\n const sidStrings = fSids.map(toSidString).filter(nonEmptySid => nonEmptySid);\n return sidStrings;\n\n function toSidString(field) {\n debug(`Getting string from a field`);\n\n return validateSidFieldSubfieldCounts(field) ? createSidString(field) : '';\n\n function createSidString(field) {\n debug(`Creating string from a field`);\n const [sfC] = getSubfieldValues(field, 'c');\n const [sfB] = getSubfieldValues(field, 'b');\n\n const cleanedSfC = removeSourcePrefix(normalizeSidSubfieldValue(sfC));\n const cleanedSfB = normalizeSidSubfieldValue(sfB);\n\n debugData(`${JSON.stringify(sfC)} + ${JSON.stringify(sfB)}`);\n return cleanedSfC.concat(cleanedSfB);\n }\n\n function removeSourcePrefix(subfieldValue) {\n const sourcePrefixRegex = (/^(?<sourcePrefix>\\([A-Za-z0-9-]+\\))(?<id>.+)$/u);\n const normalizedValue = testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(sourcePrefixRegex, '$<id>') : '';\n debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);\n return normalizedValue;\n }\n\n function normalizeSidSubfieldValue(subfieldValue) {\n debugData(`Normalizing ${subfieldValue}`);\n const normalizeAwayRegex = (/[- ]/u);\n return testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(normalizeAwayRegex, '') : '';\n }\n\n }\n }\n }\n}\n\nexport function bibMelindaIds(record) {\n // Melinda's SRU-index melinda.melindaid includes f001 controlnumbers and old Melinda-IDs from f035z's for all non-deleted Melinda-records\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibMelindaIds');\n const debugData = debug.extend('data');\n debug(`Creating queries for MelindaIds`);\n\n // Note: Melinda-ID's for search queries are created just from records f035a's and f035z's\n // Both (FI-MELINDA)- and FCC-prefixed forms are found\n // f001 controlnumber is not currently included, even if record's f003 is FI-MELINDA\n const melindaIds = getMelindaIdsF035(record);\n\n debugData(`Unique identifiers (${melindaIds.length}): ${JSON.stringify(melindaIds)}`);\n\n if (melindaIds.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(melindaIds, 'melinda.melindaid');\n}\n\n\n// bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05\n// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?\nexport function bibHostComponents(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents');\n const debugData = debug.extend('data');\n debug(`Creating queries for hostIds`);\n\n const id = getHostId();\n debugData(`Found id: ${JSON.stringify(id)}`);\n\n return testStringOrNumber(id) ? [`melinda.partsofhost=${id}`] : [];\n\n function getHostId() {\n const [field] = record.get(/^773$/u);\n\n if (field) {\n const {value} = field.subfields.find(({code}) => code === 'w') || {};\n\n if (testStringOrNumber(value) && (/^\\(FI-MELINDA\\)/u).test(String(value))) {\n return String(value).replace(/^\\(FI-MELINDA\\)/u, '');\n }\n\n if (testStringOrNumber(value) && (/^\\(FIN01\\)/u).test(String(value))) {\n return String(value).replace(/^\\(FIN01\\)/u, '');\n }\n\n return false;\n }\n return false;\n }\n}\n\n// SRU search dc.title with a search phrase starting with ^ maps currently in Melinda to\n// (probably) to *headings* index TIT\n// - Aleph cannot currently handle headings searches starting with a boolean - in these cases use word search\n\n// Headings index TIT drops articles etc. from the start of the title according to the filing indicator\n// Currently filing indicator is not implemented - if the title starts with an article and the Melinda\n// record is correctly catalogued using a filing indicator -> dc.title search won't match\n\nexport function bibTitle(record) {\n // We get author/publisher only when formatted title is shorter than 5 chars\n return bibTitleAuthorPublisher({record, onlyTitleLength: 5});\n}\n\nexport function bibTitleAuthor(record) {\n debug('bibTitleAuthor');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100});\n}\n\nexport function bibTitleAuthorYear(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true});\n}\n\nexport function bibTitleAuthorYearAlternates(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n const origQueryList = bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true, alternates: true, alternateQueries: []});\n debug(`${JSON.stringify(origQueryList)}`);\n return {queryList: Array.from(origQueryList).reverse(), queryListType: 'alternates'};\n}\n\nexport function bibTitleAuthorPublisher({record, onlyTitleLength, addYear = false, alternates = false, alternateQueries = []}) {\n debug(`bibTitleAuthorPublisher, onlyTitleLength: ${onlyTitleLength}, addYear: ${addYear}, alternates: ${alternates}`);\n const title = getTitle();\n if (testStringOrNumber(title)) {\n const formatted = String(title)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n // use word search for titles starting with a boolean\n const useWordSearch = checkUseWordSearch(formatted);\n // Prevent too many matches / SRU crashing by having a minimum length\n // Note that currently this fails matching if there are no matches from previous matchers\n if (formatted.length >= onlyTitleLength && !alternates) {\n return [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n const queryIsOkAlone = formatted.length >= 5;\n\n // use word search without ending * also in combination searches to avoid SRU-server crashes [MRA-189]\n const query = `dc.title=\"${useWordSearch || !queryIsOkAlone ? '' : '^'}${formatted}${queryIsOkAlone ? '*' : ''}\"`;\n debug(`query: ${query}`);\n const newAlternateQueries = alternates ? [...alternateQueries, query] : alternateQueries;\n\n return addAuthorsToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries: newAlternateQueries});\n }\n\n return [];\n\n function addAuthorsToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n debug('addAuthorsToSearch');\n const [authorQuery] = bibAuthors(record);\n if (authorQuery !== undefined) {\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${authorQuery} AND ${query}`] : alternateQueries;\n return addYearToSearch({query: `${authorQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [`${authorQuery} AND ${query}`];\n }\n return addPublisherToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries});\n //return [];\n }\n\n function addPublisherToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n const [publisherQuery] = bibPublishers(record);\n if (publisherQuery !== undefined) {\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${publisherQuery} AND ${query}`] : alternateQueries;\n return addYearToSearch({query: `${publisherQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [`${publisherQuery} AND ${query}`];\n }\n if (queryIsOkAlone && !addYear) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return addYearToSearch({query, queryIsOkAlone, alternates, alternateQueries});\n }\n\n function addYearToSearch({query, queryIsOkAlone = false, alternates = false, alternateQueries = []}) {\n const [yearQuery] = bibYear(record);\n if (yearQuery !== undefined) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${yearQuery} AND ${query}`] : alternateQueries;\n return alternates ? newAlternateQueries : [`${yearQuery} AND ${query}`];\n }\n if (queryIsOkAlone) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return [];\n }\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n const titleString = field.subfields\n //.filter(({code}) => ['a', 'b', 'n', 'p'].includes(code))\n .filter(({code}) => ['a', 'b'].includes(code))\n //.filter(({code}) => ['a'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return titleString;\n }\n return false;\n }\n}\n\nexport function bibAuthors(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibAuthors');\n const debugData = debug.extend('data');\n debug(`Creating query for the first author`);\n //debugData(record);\n\n const author = getAuthor(record);\n\n if (testStringOrNumber(author)) {\n const formatted = String(author)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n // use word search for authors starting with a boolean\n const useWordSearch = checkUseWordSearch(formatted);\n // Prevent too many matches by having a minimum length\n debugData(`Author string: ${formatted}`);\n if (formatted.length >= 5) {\n return [`dc.author=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n return [];\n }\n\n return [];\n\n function getAuthor(record) {\n //debugData(record);\n // eslint-disable-next-line prefer-named-capture-group\n const [field] = record.get(/^(100)|(110)|(111)|(700)|(710)|(711)$/u);\n //debugData(field);\n\n if (field) {\n const authorString = field.subfields\n .filter(({code}) => ['a'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return authorString;\n }\n return false;\n }\n}\n\nexport function bibPublishers(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibPublishers');\n const debugData = debug.extend('data');\n debug(`Creating query for the first publisher`);\n //debugData(record);\n\n const publisher = getPublisher(record);\n if (testStringOrNumber(publisher)) {\n const formatted = String(publisher)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n debugData(`Publisher string: ${formatted}`);\n // use non-wildcard word search from dc.publisher\n return [`dc.publisher=\"${formatted}\"`];\n }\n\n return [];\n\n function getPublisher(record) {\n //debugData(record);\n const [field] = record.get(/^(?:260)|(?:264)$/u);\n //debugData(field);\n\n if (field) {\n const publisherString = field.subfields\n .filter(({code}) => ['b'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return publisherString;\n }\n return false;\n }\n}\n\nexport function bibYear(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibYear');\n const debugData = debug.extend('data');\n debug(`Creating query for the publishing year`);\n debugData(record);\n\n const year = getYear(record);\n if (year) {\n return [`dc.date=\"${year}\"`];\n }\n return [];\n\n function getYear(record) {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n return testStringOrNumber(value) ? String(value).slice(7, 11) : undefined;\n }\n}\n\nexport function checkUseWordSearch(formatted) {\n // Note: add a space to startWords to catch just actual boolean words\n const booleanStartWords = ['and ', 'or ', 'nor ', 'not '];\n return booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));\n}\n\nexport function bibStandardIdentifiers(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');\n const debugData = debug.extend('data');\n debug(`Creating queries for standard identifiers`);\n\n // DEVELOP: should we query also f015 and f028?\n\n const fields = record.get(/^(?<def>020|022|024)$/u);\n const identifiers = [].concat(...fields.map(toIdentifiers));\n const uniqueIdentifiers = [...new Set(identifiers)];\n\n debugData(`Standard identifier fields: ${JSON.stringify(fields)}`);\n debugData(`Identifiers (${identifiers.length}): ${JSON.stringify(identifiers)}`);\n debugData(`Unique identifiers (${uniqueIdentifiers.length}): ${JSON.stringify(uniqueIdentifiers)}`);\n\n if (uniqueIdentifiers.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(uniqueIdentifiers, 'dc.identifier');\n\n function toIdentifiers({tag, subfields}) {\n const issnIsbnReqExp = (/^[A-Za-z0-9-]+$/u);\n const otherIdReqExp = (/^[A-Za-z0-9-:]+$/u);\n\n if (tag === '022') {\n return subfields\n .filter(sub => ['a', 'z', 'y'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n if (tag === '020') {\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && otherIdReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;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AC,GAAG,EAAE,GAAG,CAAC,CAACxB,QAAQ,CAACwB,GAAG,CAAC9D,IAAI,CAAC,IAAI,IAAAb,iCAAkB,EAAC2E,GAAG,CAACjE,KAAK,CAAC,IAAI+D,cAAc,CAAC3D,IAAI,CAACb,MAAM,CAAC0E,GAAG,CAACjE,KAAK,CAAC,CAAC,CAAC,CACvH5B,GAAG,CAAC,CAAC;QAAC4B;MAAK,CAAC,KAAKT,MAAM,CAACS,KAAK,CAAC,CAAC;IACpC;IAEA,OAAOC,SAAS,CACb3B,MAAM,CAAC2F,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACxB,QAAQ,CAACwB,GAAG,CAAC9D,IAAI,CAAC,IAAI,IAAAb,iCAAkB,EAAC2E,GAAG,CAACjE,KAAK,CAAC,IAAIgE,aAAa,CAAC5D,IAAI,CAACb,MAAM,CAAC0E,GAAG,CAACjE,KAAK,CAAC,CAAC,CAAC,CACtH5B,GAAG,CAAC,CAAC;MAAC4B;IAAK,CAAC,KAAKT,MAAM,CAACS,KAAK,CAAC,CAAC;EACpC;AACF","ignoreList":[]}
1
+ {"version":3,"file":"bib.js","names":["_debug","_interopRequireDefault","require","_candidateSearchUtils","_matchingUtils","e","__esModule","default","debug","createDebugLogger","bibSourceIds","record","debugData","extend","fSids","get","length","JSON","stringify","toSidQueries","sidStrings","getSidStrings","sidQueries","toQueries","map","toSidString","filter","nonEmptySid","field","validateSidFieldSubfieldCounts","createSidString","sfC","getSubfieldValues","sfB","cleanedSfC","removeSourcePrefix","normalizeSidSubfieldValue","cleanedSfB","concat","subfieldValue","sourcePrefixRegex","normalizedValue","testStringOrNumber","String","replace","normalizeAwayRegex","bibMelindaIds","melindaIds","getMelindaIdsF035","bibHostComponents","id","getHostId","value","subfields","find","code","test","bibTitle","bibTitleAuthorPublisher","onlyTitleLength","bibTitleAuthor","bibTitleAuthorYear","addYear","bibTitleAuthorYearAlternates","origQueryList","alternates","alternateQueries","queryList","Array","from","reverse","queryListType","title","getTitle","formatted","trim","slice","useWordSearch","checkUseWordSearch","queryIsOkAlone","query","newAlternateQueries","addAuthorsToSearch","authorQuery","bibAuthors","undefined","addYearToSearch","addPublisherToSearch","publisherQuery","bibPublishers","yearQuery","bibYear","titleString","includes","join","author","getAuthor","authorString","publisher","getPublisher","publisherString","year","getYear","booleanStartWords","some","word","toLowerCase","startsWith","bibStandardIdentifiers","fields","identifiers","toIdentifiers","uniqueIdentifiers","Set","tag","issnIsbnReqExp","otherIdReqExp","sub"],"sources":["../../../src/candidate-search/query-list/bib.js"],"sourcesContent":["import createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils';\nimport {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} from '../../matching-utils';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query');\n\nexport function bibSourceIds(record) {\n\n /* Melinda's SRU-index melinda.sourceid includes source IDs from SID fields in Melinda records\n SID-fields in Melinda have sf $c with local id and sf $b with a code for the local db:\n\n SID__ $c 123457 $b helka\n SID__ $c (ANDL100020)1077305 $b sata\n SID__ $c VER999999 $ FI-KV\n SID__ $c /10024/508126 $ REPO_THESEUS\n\n In melinda.sourceid -index case is kept, sourceprefixes in brackets and hyphens are normalized away:\n Note: slashes are not normalized away, but a SRU-search-string including slashes needs to be quoted\n\n 1234567helka\n 1077305sata\n VER999999FIKV\n /10024/508126REPO_THESEUS\n\n Note: All Melinda records that have a matching records in a local db do NOT have SID for that local records,\n existence of a SID field depends on how the record has been added to Melinda and how it has been handled\n afterwards. SIDs are also not reliably maintained. A record might or might not have a SID for a local db\n after the matching record is removed from the local db.\n\n */\n\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:source-ids');\n const debugData = debug.extend('data');\n //const debugInfo = debug.extend('info');\n\n debug(`Creating queries for sourceid's`);\n\n const fSids = record.get('SID');\n debugData(`SID-fields (${fSids.length}): ${JSON.stringify(fSids)}`);\n\n return fSids.length > 0 ? toSidQueries(fSids) : [];\n\n function toSidQueries(fSids) {\n debug(`Creating actual queries for sourceid's`);\n\n const sidStrings = getSidStrings(fSids);\n\n if (sidStrings.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n const sidQueries = toQueries(sidStrings, 'melinda.sourceid');\n\n return sidQueries;\n\n function getSidStrings(fSids) {\n debug(`Getting Sid strings from SID fields`);\n\n // Map SID fields to valid sidStrings, filter out empty strings\n const sidStrings = fSids.map(toSidString).filter(nonEmptySid => nonEmptySid);\n return sidStrings;\n\n function toSidString(field) {\n debug(`Getting string from a field`);\n\n return validateSidFieldSubfieldCounts(field) ? createSidString(field) : '';\n\n function createSidString(field) {\n debug(`Creating string from a field`);\n const [sfC] = getSubfieldValues(field, 'c');\n const [sfB] = getSubfieldValues(field, 'b');\n\n const cleanedSfC = removeSourcePrefix(normalizeSidSubfieldValue(sfC));\n const cleanedSfB = normalizeSidSubfieldValue(sfB);\n\n debugData(`${JSON.stringify(sfC)} + ${JSON.stringify(sfB)}`);\n return cleanedSfC.concat(cleanedSfB);\n }\n\n function removeSourcePrefix(subfieldValue) {\n const sourcePrefixRegex = (/^(?<sourcePrefix>\\([A-Za-z0-9-]+\\))(?<id>.+)$/u);\n const normalizedValue = testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(sourcePrefixRegex, '$<id>') : '';\n debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);\n return normalizedValue;\n }\n\n function normalizeSidSubfieldValue(subfieldValue) {\n debugData(`Normalizing ${subfieldValue}`);\n const normalizeAwayRegex = (/[- ]/u);\n return testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(normalizeAwayRegex, '') : '';\n }\n\n }\n }\n }\n}\n\nexport function bibMelindaIds(record) {\n // Melinda's SRU-index melinda.melindaid includes f001 controlnumbers and old Melinda-IDs from f035z's for all non-deleted Melinda-records\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibMelindaIds');\n const debugData = debug.extend('data');\n debug(`Creating queries for MelindaIds`);\n\n // Note: Melinda-ID's for search queries are created just from records f035a's and f035z's\n // Both (FI-MELINDA)- and FCC-prefixed forms are found\n // f001 controlnumber is not currently included, even if record's f003 is FI-MELINDA\n const melindaIds = getMelindaIdsF035(record);\n\n debugData(`Unique identifiers (${melindaIds.length}): ${JSON.stringify(melindaIds)}`);\n\n if (melindaIds.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(melindaIds, 'melinda.melindaid');\n}\n\n\n// bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05\n// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?\nexport function bibHostComponents(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents');\n const debugData = debug.extend('data');\n debug(`Creating queries for hostIds`);\n\n const id = getHostId();\n debugData(`Found id: ${JSON.stringify(id)}`);\n\n return testStringOrNumber(id) ? [`melinda.partsofhost=${id}`] : [];\n\n function getHostId() {\n const [field] = record.get(/^773$/u);\n\n if (field) {\n const {value} = field.subfields.find(({code}) => code === 'w') || {};\n\n if (testStringOrNumber(value) && (/^\\(FI-MELINDA\\)/u).test(String(value))) {\n return String(value).replace(/^\\(FI-MELINDA\\)/u, '');\n }\n\n if (testStringOrNumber(value) && (/^\\(FIN01\\)/u).test(String(value))) {\n return String(value).replace(/^\\(FIN01\\)/u, '');\n }\n\n return false;\n }\n return false;\n }\n}\n\n// SRU search dc.title with a search phrase starting with ^ maps currently in Melinda to\n// (probably) to *headings* index TIT\n// - Aleph cannot currently handle headings searches starting with a boolean - in these cases use word search\n\n// Headings index TIT drops articles etc. from the start of the title according to the filing indicator\n// Currently filing indicator is not implemented - if the title starts with an article and the Melinda\n// record is correctly catalogued using a filing indicator -> dc.title search won't match\n\nexport function bibTitle(record) {\n // We get author/publisher only when formatted title is shorter than 5 chars\n return bibTitleAuthorPublisher({record, onlyTitleLength: 5});\n}\n\nexport function bibTitleAuthor(record) {\n debug('bibTitleAuthor');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100});\n}\n\nexport function bibTitleAuthorYear(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true});\n}\n\nexport function bibTitleAuthorYearAlternates(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n const origQueryList = bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true, alternates: true, alternateQueries: []});\n debug(`${JSON.stringify(origQueryList)}`);\n return {queryList: Array.from(origQueryList).reverse(), queryListType: 'alternates'};\n}\n\nexport function bibTitleAuthorPublisher({record, onlyTitleLength, addYear = false, alternates = false, alternateQueries = []}) {\n debug(`bibTitleAuthorPublisher, onlyTitleLength: ${onlyTitleLength}, addYear: ${addYear}, alternates: ${alternates}`);\n const title = getTitle();\n if (testStringOrNumber(title)) {\n const formatted = String(title)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n // use word search for titles starting with a boolean\n const useWordSearch = checkUseWordSearch(formatted);\n // Prevent too many matches / SRU crashing by having a minimum length\n // Note that currently this fails matching if there are no matches from previous matchers\n if (formatted.length >= onlyTitleLength && !alternates) {\n return [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n const queryIsOkAlone = formatted.length >= 5;\n\n // use word search without ending * also in combination searches to avoid SRU-server crashes [MRA-189]\n const query = `dc.title=\"${useWordSearch || !queryIsOkAlone ? '' : '^'}${formatted}${queryIsOkAlone ? '*' : ''}\"`;\n debug(`query: ${query}`);\n const newAlternateQueries = alternates ? [...alternateQueries, query] : alternateQueries;\n\n return addAuthorsToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries: newAlternateQueries});\n }\n\n return [];\n\n function addAuthorsToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n debug('addAuthorsToSearch');\n const [authorQuery] = bibAuthors(record);\n if (authorQuery !== undefined) {\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${authorQuery} AND ${query}`] : alternateQueries;\n return addYearToSearch({query: `${authorQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [`${authorQuery} AND ${query}`];\n }\n return addPublisherToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries});\n //return [];\n }\n\n function addPublisherToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n const [publisherQuery] = bibPublishers(record);\n if (publisherQuery !== undefined) {\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${publisherQuery} AND ${query}`] : alternateQueries;\n return addYearToSearch({query: `${publisherQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [`${publisherQuery} AND ${query}`];\n }\n if (queryIsOkAlone && !addYear) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return addYearToSearch({query, queryIsOkAlone, alternates, alternateQueries});\n }\n\n function addYearToSearch({query, queryIsOkAlone = false, alternates = false, alternateQueries = []}) {\n const [yearQuery] = bibYear(record);\n if (yearQuery !== undefined) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${yearQuery} AND ${query}`] : alternateQueries;\n return alternates ? newAlternateQueries : [`${yearQuery} AND ${query}`];\n }\n if (queryIsOkAlone) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return [];\n }\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n const titleString = field.subfields\n //.filter(({code}) => ['a', 'b', 'n', 'p'].includes(code))\n .filter(({code}) => ['a', 'b'].includes(code))\n //.filter(({code}) => ['a'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return titleString;\n }\n return false;\n }\n}\n\nexport function bibAuthors(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibAuthors');\n const debugData = debug.extend('data');\n debug(`Creating query for the first author`);\n //debugData(record);\n\n const author = getAuthor(record);\n\n if (testStringOrNumber(author)) {\n const formatted = String(author)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n // use word search for authors starting with a boolean\n const useWordSearch = checkUseWordSearch(formatted);\n // Prevent too many matches by having a minimum length\n debugData(`Author string: ${formatted}`);\n if (formatted.length >= 5) {\n return [`dc.author=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n return [];\n }\n\n return [];\n\n function getAuthor(record) {\n //debugData(record);\n // eslint-disable-next-line prefer-named-capture-group\n const [field] = record.get(/^(100)|(110)|(111)|(700)|(710)|(711)$/u);\n //debugData(field);\n\n if (field) {\n const authorString = field.subfields\n .filter(({code}) => ['a'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return authorString;\n }\n return false;\n }\n}\n\nexport function bibPublishers(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibPublishers');\n const debugData = debug.extend('data');\n debug(`Creating query for the first publisher`);\n //debugData(record);\n\n const publisher = getPublisher(record);\n if (testStringOrNumber(publisher)) {\n const formatted = String(publisher)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n debugData(`Publisher string: ${formatted}`);\n // use non-wildcard word search from dc.publisher\n return [`dc.publisher=\"${formatted}\"`];\n }\n\n return [];\n\n function getPublisher(record) {\n //debugData(record);\n const [field] = record.get(/^(?:260)|(?:264)$/u);\n //debugData(field);\n\n if (field) {\n const publisherString = field.subfields\n .filter(({code}) => ['b'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return publisherString;\n }\n return false;\n }\n}\n\nexport function bibYear(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibYear');\n const debugData = debug.extend('data');\n debug(`Creating query for the publishing year`);\n debugData(record);\n\n const year = getYear(record);\n if (year) {\n return [`dc.date=\"${year}\"`];\n }\n return [];\n\n function getYear(record) {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n return testStringOrNumber(value) ? String(value).slice(7, 11) : undefined;\n }\n}\n\nexport function checkUseWordSearch(formatted) {\n // Note: add a space to startWords to catch just actual boolean words\n const booleanStartWords = ['and ', 'or ', 'nor ', 'not '];\n return booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));\n}\n\nexport function bibStandardIdentifiers(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');\n const debugData = debug.extend('data');\n debug(`Creating queries for standard identifiers`);\n\n // DEVELOP: should we query also f015 and f028?\n\n const fields = record.get(/^(?<def>020|022|024)$/u);\n const identifiers = [].concat(...fields.map(toIdentifiers));\n const uniqueIdentifiers = [...new Set(identifiers)];\n\n debugData(`Standard identifier fields: ${JSON.stringify(fields)}`);\n debugData(`Identifiers (${identifiers.length}): ${JSON.stringify(identifiers)}`);\n debugData(`Unique identifiers (${uniqueIdentifiers.length}): ${JSON.stringify(uniqueIdentifiers)}`);\n\n if (uniqueIdentifiers.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(uniqueIdentifiers, 'dc.identifier');\n\n function toIdentifiers({tag, subfields}) {\n const issnIsbnReqExp = (/^[A-Za-z0-9-]+$/u);\n const otherIdReqExp = (/^[A-Za-z0-9-:]+$/u);\n\n if (tag === '022') {\n return subfields\n .filter(sub => ['a', 'z', 'y'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n if (tag === '020') {\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && otherIdReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAA8H,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE9H,MAAMG,KAAK,GAAG,IAAAC,cAAiB,EAAC,0DAA0D,CAAC;AAEpF,SAASC,YAAYA,CAACC,MAAM,EAAE;EAEnC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;EAQE,MAAMH,KAAK,GAAG,IAAAC,cAAiB,EAAC,qEAAqE,CAAC;EACtG,MAAMG,SAAS,GAAGJ,KAAK,CAACK,MAAM,CAAC,MAAM,CAAC;EACtC;;EAEAL,KAAK,CAAC,iCAAiC,CAAC;EAExC,MAAMM,KAAK,GAAGH,MAAM,CAACI,GAAG,CAAC,KAAK,CAAC;EAC/BH,SAAS,CAAC,eAAeE,KAAK,CAACE,MAAM,MAAMC,IAAI,CAACC,SAAS,CAACJ,KAAK,CAAC,EAAE,CAAC;EAEnE,OAAOA,KAAK,CAACE,MAAM,GAAG,CAAC,GAAGG,YAAY,CAACL,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F,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAACxB,QAAQ,CAACwB,GAAG,CAAC9D,IAAI,CAAC,IAAI,IAAAb,iCAAkB,EAAC2E,GAAG,CAACjE,KAAK,CAAC,IAAI+D,cAAc,CAAC3D,IAAI,CAACb,MAAM,CAAC0E,GAAG,CAACjE,KAAK,CAAC,CAAC,CAAC,CAC5H5B,GAAG,CAAC,CAAC;QAAC4B;MAAK,CAAC,KAAKT,MAAM,CAACS,KAAK,CAAC,CAAC;IACpC;IAEA,IAAI8D,GAAG,KAAK,KAAK,EAAE;MACjB,OAAO7D,SAAS,CACb3B,MAAM,CAAC2F,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACxB,QAAQ,CAACwB,GAAG,CAAC9D,IAAI,CAAC,IAAI,IAAAb,iCAAkB,EAAC2E,GAAG,CAACjE,KAAK,CAAC,IAAI+D,cAAc,CAAC3D,IAAI,CAACb,MAAM,CAAC0E,GAAG,CAACjE,KAAK,CAAC,CAAC,CAAC,CACvH5B,GAAG,CAAC,CAAC;QAAC4B;MAAK,CAAC,KAAKT,MAAM,CAACS,KAAK,CAAC,CAAC;IACpC;IAEA,OAAOC,SAAS,CACb3B,MAAM,CAAC2F,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACxB,QAAQ,CAACwB,GAAG,CAAC9D,IAAI,CAAC,IAAI,IAAAb,iCAAkB,EAAC2E,GAAG,CAACjE,KAAK,CAAC,IAAIgE,aAAa,CAAC5D,IAAI,CAACb,MAAM,CAAC0E,GAAG,CAACjE,KAAK,CAAC,CAAC,CAAC,CACtH5B,GAAG,CAAC,CAAC;MAAC4B;IAAK,CAAC,KAAKT,MAAM,CAACS,KAAK,CAAC,CAAC;EACpC;AACF","ignoreList":[]}
@@ -8,7 +8,7 @@ var generators = _interopRequireWildcard(require("./bib"));
8
8
  var _debug = _interopRequireDefault(require("debug"));
9
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
10
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.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; }
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
12
  const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents:test');
13
13
  const debugData = debug.extend('data');
14
14
  describe('candidate-search/query-list/bib/', () => {
@@ -1 +1 @@
1
- {"version":3,"file":"bib.spec.js","names":["_fixugen","_interopRequireDefault","require","_fixura","_chai","_marcRecord","generators","_interopRequireWildcard","_debug","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","obj","debug","createDebugLogger","debugData","extend","describe","generateTests","path","__dirname","useMetadataFile","fixura","reader","READERS","JSON","callback","type","inputRecord","expectedQuery","expectedQueryListType","enabled","generate","record","MarcRecord","subfieldValues","result","stringify","queryListType","expect","queryList","to","eql"],"sources":["../../../src/candidate-search/query-list/bib.spec.js"],"sourcesContent":["import generateTests from '@natlibfi/fixugen';\nimport {READERS} from '@natlibfi/fixura';\nimport {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport * as generators from './bib';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents:test');\nconst debugData = debug.extend('data');\n\ndescribe('candidate-search/query-list/bib/', () => {\n generateTests({\n path: [__dirname, '..', '..', '..', 'test-fixtures', 'candidate-search', 'query-list', 'bib'],\n useMetadataFile: true,\n fixura: {\n reader: READERS.JSON\n },\n callback: ({type, inputRecord, expectedQuery, expectedQueryListType, enabled = true}) => {\n const generate = generators[type];\n const record = new MarcRecord(inputRecord, {subfieldValues: false});\n\n if (!enabled) {\n return;\n }\n\n const result = generate(record);\n debugData(`Result: ${JSON.stringify(result)}`);\n\n if (result.queryListType) {\n expect(result.queryList).to.eql(expectedQuery);\n expect(result.queryListType).to.eql(expectedQueryListType);\n return;\n }\n expect(result).to.eql(expectedQuery);\n }\n });\n});\n"],"mappings":";;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAC,uBAAA,CAAAL,OAAA;AACA,IAAAM,MAAA,GAAAP,sBAAA,CAAAC,OAAA;AAAsC,SAAAO,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,M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M,GAAG,IAAIC,sBAAU,CAACN,WAAW,EAAE;QAACO,cAAc,EAAE;MAAK,CAAC,CAAC;MAEnE,IAAI,CAACJ,OAAO,EAAE;QACZ;MACF;MAEA,MAAMK,MAAM,GAAGJ,QAAQ,CAACC,MAAM,CAAC;MAC/BlB,SAAS,CAAE,WAAUU,IAAI,CAACY,SAAS,CAACD,MAAM,CAAE,EAAC,CAAC;MAE9C,IAAIA,MAAM,CAACE,aAAa,EAAE;QACxB,IAAAC,YAAM,EAACH,MAAM,CAACI,SAAS,CAAC,CAACC,EAAE,CAACC,GAAG,CAACb,aAAa,CAAC;QAC9C,IAAAU,YAAM,EAACH,MAAM,CAACE,aAAa,CAAC,CAACG,EAAE,CAACC,GAAG,CAACZ,qBAAqB,CAAC;QAC1D;MACF;MACA,IAAAS,YAAM,EAACH,MAAM,CAAC,CAACK,EAAE,CAACC,GAAG,CAACb,aAAa,CAAC;IACtC;EACF,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"bib.spec.js","names":["_fixugen","_interopRequireDefault","require","_fixura","_chai","_marcRecord","generators","_interopRequireWildcard","_debug","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","debug","createDebugLogger","debugData","extend","describe","generateTests","path","__dirname","useMetadataFile","fixura","reader","READERS","JSON","callback","type","inputRecord","expectedQuery","expectedQueryListType","enabled","generate","record","MarcRecord","subfieldValues","result","stringify","queryListType","expect","queryList","to","eql"],"sources":["../../../src/candidate-search/query-list/bib.spec.js"],"sourcesContent":["import generateTests from '@natlibfi/fixugen';\nimport {READERS} from '@natlibfi/fixura';\nimport {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport * as generators from './bib';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents:test');\nconst debugData = debug.extend('data');\n\ndescribe('candidate-search/query-list/bib/', () => {\n generateTests({\n path: [__dirname, '..', '..', '..', 'test-fixtures', 'candidate-search', 'query-list', 'bib'],\n useMetadataFile: true,\n fixura: {\n reader: READERS.JSON\n },\n callback: ({type, inputRecord, expectedQuery, expectedQueryListType, enabled = true}) => {\n const generate = generators[type];\n const record = new MarcRecord(inputRecord, {subfieldValues: false});\n\n if (!enabled) {\n return;\n }\n\n const result = generate(record);\n debugData(`Result: ${JSON.stringify(result)}`);\n\n if (result.queryListType) {\n expect(result.queryList).to.eql(expectedQuery);\n expect(result.queryListType).to.eql(expectedQueryListType);\n return;\n }\n expect(result).to.eql(expectedQuery);\n }\n });\n});\n"],"mappings":";;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAC,uBAAA,CAAAL,OAAA;AACA,IAAAM,MAAA,GAAAP,sBAAA,CAAAC,OAAA;AAAsC,SAAAO,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAA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,CAACN,WAAW,EAAE;QAACO,cAAc,EAAE;MAAK,CAAC,CAAC;MAEnE,IAAI,CAACJ,OAAO,EAAE;QACZ;MACF;MAEA,MAAMK,MAAM,GAAGJ,QAAQ,CAACC,MAAM,CAAC;MAC/BlB,SAAS,CAAC,WAAWU,IAAI,CAACY,SAAS,CAACD,MAAM,CAAC,EAAE,CAAC;MAE9C,IAAIA,MAAM,CAACE,aAAa,EAAE;QACxB,IAAAC,YAAM,EAACH,MAAM,CAACI,SAAS,CAAC,CAACC,EAAE,CAACC,GAAG,CAACb,aAAa,CAAC;QAC9C,IAAAU,YAAM,EAACH,MAAM,CAACE,aAAa,CAAC,CAACG,EAAE,CAACC,GAAG,CAACZ,qBAAqB,CAAC;QAC1D;MACF;MACA,IAAAS,YAAM,EAACH,MAAM,CAAC,CAACK,EAAE,CAACC,GAAG,CAACb,aAAa,CAAC;IACtC;EACF,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.searchTypes = exports.default = void 0;
7
7
  var bib = _interopRequireWildcard(require("./bib"));
8
8
  var _debug = _interopRequireDefault(require("debug"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
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
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 && {}.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
12
  const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:index');
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["bib","_interopRequireWildcard","require","_debug","_interopRequireDefault","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","debug","createDebugLogger","debugData","extend","searchTypes","exports","standardIdentifiers","hostComponents","title","titleAuthor","titleAuthorYear","titleAuthorYearAlternates","melindaId","sourceIds","_default","record","searchSpec","extractors","JSON","stringify","map","generateQueryExtractor","cb","flat","type","Error"],"sources":["../../../src/candidate-search/query-list/index.js"],"sourcesContent":["\n\nimport * as bib from './bib';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:index');\nconst debugData = debug.extend('data');\n\nexport const searchTypes = {\n bib: {\n standardIdentifiers: 'bibStandardIdentifiers',\n hostComponents: 'bibHostComponents',\n title: 'bibTitle', // title ( + first author + first publisher if needed)\n titleAuthor: 'bibTitleAuthor', // title + first author (or first publisher if no author)\n titleAuthorYear: 'bibTitleAuthorYear', // title + first author (or first publisher if no author), publishing year\n titleAuthorYearAlternates: 'bibTitleAuthorYearAlternates', // title + first author (or first publisher if no author), publishing year\n melindaId: 'bibMelindaIds',\n sourceIds: 'bibSourceIds'\n //DEVELOP: bibContent: 'bibContent'\n }\n};\n\nexport default (record, searchSpec) => {\n const extractors = {...bib};\n debugData(`extractors: ${JSON.stringify(extractors)}`);\n debugData(`searchSpec: ${JSON.stringify(searchSpec)}`);\n\n return searchSpec\n .map(generateQueryExtractor)\n .map(cb => cb(record))\n .flat();\n\n function generateQueryExtractor(type) {\n if (extractors[type]) {\n //debugData(`${JSON.stringify(extractors[type])}`);\n return extractors[type];\n }\n\n throw new Error(`Unknown search type: ${type}`);\n }\n};\n"],"mappings":";;;;;;AAEA,IAA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,CAAA,EAAAM,CAAA,GAAAA,CAAA;AAEtC,MAAMW,KAAK,GAAG,IAAAC,cAAiB,EAAC,0DAA0D,CAAC;AAC3F,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;AAE/B,MAAMC,WAAW,GAAAC,OAAA,CAAAD,WAAA,GAAG;EACzB9B,GAAG,EAAE;IACHgC,mBAAmB,EAAE,wBAAwB;IAC7CC,cAAc,EAAE,mBAAmB;IACnCC,KAAK,EAAE,UAAU;IAAE;IACnBC,WAAW,EAAE,gBAAgB;IAAE;IAC/BC,eAAe,EAAE,oBAAoB;IAAE;IACvCC,yBAAyB,EAAE,8BAA8B;IAAE;IAC3DC,SAAS,EAAE,eAAe;IAC1BC,SAAS,EAAE;IACX;EACF;AACF,CAAC;AAAC,IAAAC,QAAA,GAEaA,CAACC,MAAM,EAAEC,UAAU,KAAK;EACrC,MAAMC,UAAU,GAAG;IAAC,GAAG3C;EAAG,CAAC;EAC3B4B,SAAS,CAAE,eAAcgB,IAAI,CAACC,SAAS,CAACF,UAAU,CAAE,EAAC,CAAC;EACtDf,SAAS,CAAE,eAAcgB,IAAI,CAACC,SAAS,CAACH,UAAU,CAAE,EAAC,CAAC;EAEtD,OAAOA,UAAU,CACdI,GAAG,CAACC,sBAAsB,CAAC,CAC3BD,GAAG,CAACE,EAAE,IAAIA,EAAE,CAACP,MAAM,CAAC,CAAC,CACrBQ,IAAI,CAAC,CAAC;EAET,SAASF,sBAAsBA,CAACG,IAAI,EAAE;IACpC,IAAIP,UAAU,CAACO,IAAI,CAAC,EAAE;MACpB;MACA,OAAOP,UAAU,CAACO,IAAI,CAAC;IACzB;IAEA,MAAM,IAAIC,KAAK,CAAE,wBAAuBD,IAAK,EAAC,CAAC;EACjD;AACF,CAAC;AAAAnB,OAAA,CAAAxB,OAAA,GAAAiC,QAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["bib","_interopRequireWildcard","require","_debug","_interopRequireDefault","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","debug","createDebugLogger","debugData","extend","searchTypes","exports","standardIdentifiers","hostComponents","title","titleAuthor","titleAuthorYear","titleAuthorYearAlternates","melindaId","sourceIds","_default","record","searchSpec","extractors","JSON","stringify","map","generateQueryExtractor","cb","flat","type","Error"],"sources":["../../../src/candidate-search/query-list/index.js"],"sourcesContent":["\n\nimport * as bib from './bib';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:index');\nconst debugData = debug.extend('data');\n\nexport const searchTypes = {\n bib: {\n standardIdentifiers: 'bibStandardIdentifiers',\n hostComponents: 'bibHostComponents',\n title: 'bibTitle', // title ( + first author + first publisher if needed)\n titleAuthor: 'bibTitleAuthor', // title + first author (or first publisher if no author)\n titleAuthorYear: 'bibTitleAuthorYear', // title + first author (or first publisher if no author), publishing year\n titleAuthorYearAlternates: 'bibTitleAuthorYearAlternates', // title + first author (or first publisher if no author), publishing year\n melindaId: 'bibMelindaIds',\n sourceIds: 'bibSourceIds'\n //DEVELOP: bibContent: 'bibContent'\n }\n};\n\nexport default (record, searchSpec) => {\n const extractors = {...bib};\n debugData(`extractors: ${JSON.stringify(extractors)}`);\n debugData(`searchSpec: ${JSON.stringify(searchSpec)}`);\n\n return searchSpec\n .map(generateQueryExtractor)\n .map(cb => cb(record))\n .flat();\n\n function generateQueryExtractor(type) {\n if (extractors[type]) {\n //debugData(`${JSON.stringify(extractors[type])}`);\n return extractors[type];\n }\n\n throw new Error(`Unknown search type: ${type}`);\n }\n};\n"],"mappings":";;;;;;AAEA,IAAAA,GAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAsC,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAA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,OAAA,CAAAD,WAAA,GAAG;EACzB7B,GAAG,EAAE;IACH+B,mBAAmB,EAAE,wBAAwB;IAC7CC,cAAc,EAAE,mBAAmB;IACnCC,KAAK,EAAE,UAAU;IAAE;IACnBC,WAAW,EAAE,gBAAgB;IAAE;IAC/BC,eAAe,EAAE,oBAAoB;IAAE;IACvCC,yBAAyB,EAAE,8BAA8B;IAAE;IAC3DC,SAAS,EAAE,eAAe;IAC1BC,SAAS,EAAE;IACX;EACF;AACF,CAAC;AAAC,IAAAC,QAAA,GAEaA,CAACC,MAAM,EAAEC,UAAU,KAAK;EACrC,MAAMC,UAAU,GAAG;IAAC,GAAG1C;EAAG,CAAC;EAC3B2B,SAAS,CAAC,eAAegB,IAAI,CAACC,SAAS,CAACF,UAAU,CAAC,EAAE,CAAC;EACtDf,SAAS,CAAC,eAAegB,IAAI,CAACC,SAAS,CAACH,UAAU,CAAC,EAAE,CAAC;EAEtD,OAAOA,UAAU,CACdI,GAAG,CAACC,sBAAsB,CAAC,CAC3BD,GAAG,CAACE,EAAE,IAAIA,EAAE,CAACP,MAAM,CAAC,CAAC,CACrBQ,IAAI,CAAC,CAAC;EAET,SAASF,sBAAsBA,CAACG,IAAI,EAAE;IACpC,IAAIP,UAAU,CAACO,IAAI,CAAC,EAAE;MACpB;MACA,OAAOP,UAAU,CAACO,IAAI,CAAC;IACzB;IAEA,MAAM,IAAIC,KAAK,CAAC,wBAAwBD,IAAI,EAAE,CAAC;EACjD;AACF,CAAC;AAAAnB,OAAA,CAAAvB,OAAA,GAAAgC,QAAA","ignoreList":[]}
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ var matchDetection = _matchDetection;
13
13
  exports.matchDetection = _matchDetection;
14
14
  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); }
15
15
  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 && {}.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; }
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
17
  //import inspect from 'util';
18
18
  var _default = ({
19
19
  detection: detectionOptions,