Skip to content

Commit 1dcc22a

Browse files
committed
repository search and discovery rework
Rethink repository front page discovery around location based discovery. commit b50add2cc2bb01247f24eb7e4bc3ced49c85bfb0 Author: Marco La Rosa <m@lr.id.au> Date: Mon Oct 16 10:43:53 2023 +1100 styling commit 82fdb7c8ae1a76076deed037c7067262496adcad Author: Marco La Rosa <m@lr.id.au> Date: Thu Sep 21 14:34:52 2023 +1000 styling commit b011ab079bfee32bb773603b35e80873424ad057 Author: Marco La Rosa <m@lr.id.au> Date: Thu Sep 21 14:31:41 2023 +1000 revise styling commit 7e418450503be44f930aca04fb3e9ef3e9c8fdd2 Author: Marco La Rosa <m@lr.id.au> Date: Thu Sep 21 14:31:26 2023 +1000 add @Turf utilities commit 989794265bebb6d4d097855ac7505e53d2c8f582 Author: Marco La Rosa <m@lr.id.au> Date: Thu Sep 21 14:30:41 2023 +1000 rework geometry parsing commit b6b2b3180e2c0c5eb8cf8448da1b8aa8ee459f89 Author: Marco La Rosa <m@lr.id.au> Date: Thu Sep 21 11:11:27 2023 +1000 revising metadata display commit ddeeb40913964375ad635296ed7facf3e632b9fc Author: Marco La Rosa <m@lr.id.au> Date: Thu Sep 21 11:11:07 2023 +1000 load item profile when getting crate commit 0cedcf37252bb597f417f4ae4246a7838623d439 Author: Marco La Rosa <m@lr.id.au> Date: Thu Sep 21 11:03:03 2023 +1000 revise item profile commit d5cbdd0885254344b7942c6076a18806df9c1d3e Author: Marco La Rosa <m@lr.id.au> Date: Thu Sep 21 08:52:16 2023 +1000 reset options on item delete commit e99111eff4602246827c34986a1247afa3331586 Author: Marco La Rosa <m@lr.id.au> Date: Thu Sep 21 08:46:24 2023 +1000 bugfix index name commit 7893d2f35cc51c53b38eee0623297e9d05206b09 Author: Marco La Rosa <m@lr.id.au> Date: Thu Sep 21 08:42:06 2023 +1000 only index points for now What does it means to show an area on the map to denote a manuscript? commit 17b9512fcf6763822de3549497db3b4d5d079f35 Author: Marco La Rosa <m@lr.id.au> Date: Thu Sep 21 08:35:14 2023 +1000 cleanup commit 48fae1811de7553c24d4b253a6ceef5911ba7e6c Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 15:57:56 2023 +1000 mount popup data into popup options and wire up open event commit 1167e81 Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 12:21:21 2023 +1000 update dependencies commit 2eea93c Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 12:21:05 2023 +1000 set unique key on all markers commit 5487c30 Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 11:54:54 2023 +1000 marker and popup styling commit 346c9b0 Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 11:54:24 2023 +1000 define repository as target location commit 44ae6a6 Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 11:53:37 2023 +1000 pass configuration through commit d51e99d Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 11:52:18 2023 +1000 bugfixing * expect configuration to be passed in and pass that through to setRepositoryItemMetadata when depositing * liberal use of try catch commit b511e0b Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 11:50:31 2023 +1000 enable setting store to pull data from - workspace or repository commit 8ebb909 Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 09:48:30 2023 +1000 developing manuscript search component commit d6db749 Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 09:48:14 2023 +1000 rework content being returned to ui commit 69fc55c Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 09:45:56 2023 +1000 add mapboxToken to config commit 55d3f72 Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 09:45:44 2023 +1000 bugfix indexItem signature commit c987c34 Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 09:45:27 2023 +1000 don't delete indices commit 750fc16 Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 09:45:09 2023 +1000 add mapboxgl commit 317fc3c Author: Marco La Rosa <m@lr.id.au> Date: Wed Sep 20 07:33:18 2023 +1000 make the input clearable commit 46c7232 Author: Marco La Rosa <m@lr.id.au> Date: Tue Sep 19 15:44:42 2023 +1000 review repository search component now with added map! commit f0892cf Author: Marco La Rosa <m@lr.id.au> Date: Tue Sep 19 15:44:28 2023 +1000 install pluralize commit 08657d8 Author: Marco La Rosa <m@lr.id.au> Date: Tue Sep 19 15:43:59 2023 +1000 implement lookup and search handlers commit f595bc9 Author: Marco La Rosa <m@lr.id.au> Date: Tue Sep 19 15:43:22 2023 +1000 fix the indexing code * index to manuscripts index * index geojson features correctly
1 parent 8dac498 commit 1dcc22a

19 files changed

+6822
-4331
lines changed

api/package-lock.json

+963-947
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

+9-8
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
},
1616
"devDependencies": {
1717
"@babel/cli": "^7.22.15",
18-
"@babel/core": "^7.22.17",
19-
"@babel/node": "^7.22.15",
18+
"@babel/core": "^7.22.20",
19+
"@babel/node": "^7.22.19",
2020
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
2121
"@babel/plugin-syntax-import-assertions": "^7.22.5",
22-
"@babel/preset-env": "^7.22.15",
22+
"@babel/preset-env": "^7.22.20",
2323
"babel-jest": "^29.7.0",
2424
"babel-loader": "^9.1.3",
2525
"chance": "^1.1.11",
@@ -29,20 +29,20 @@
2929
"nodemon": "^3.0.1"
3030
},
3131
"dependencies": {
32-
"@aws-sdk/client-ses": "^3.410.0",
32+
"@aws-sdk/client-ses": "^3.414.0",
3333
"@coedl/nocfl-js": "^2.0.0",
3434
"@describo/data-packs": "^0.10.0",
3535
"@elastic/elasticsearch": "^8.9.0",
3636
"@fastify/compress": "^6.4.0",
37-
"@fastify/cors": "^8.3.0",
37+
"@fastify/cors": "^8.4.0",
3838
"@fastify/one-line-logger": "^1.2.0",
39-
"@fastify/sensible": "^5.2.0",
39+
"@fastify/sensible": "^5.3.0",
4040
"@paradisec-platform/fastify-tus-s3-plugin": "^1.0.0",
4141
"cross-fetch": "^4.0.0",
4242
"date-fns": "^2.30.0",
4343
"elastic-builder": "^2.22.0",
44-
"fastify": "^4.23.0",
45-
"fastify-socket.io": "^4.0.0",
44+
"fastify": "^4.23.2",
45+
"fastify-socket.io": "^5.0.0",
4646
"foo-foo-mq": "^8.0.1",
4747
"form-data": "^4.0.0",
4848
"fs-extra": "^11.1.1",
@@ -60,6 +60,7 @@
6060
"saxon-js": "^2.5.0",
6161
"sequelize": "^6.33.0",
6262
"sequelize-cli": "^6.6.1",
63+
"socket.io": "^4.7.2",
6364
"uuid": "^9.0.1",
6465
"validator": "^13.11.0",
6566
"winston": "^3.10.0"

api/src/common/elastic-index.js

+42-59
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getStoreHandle } from "./index.js";
22
import lodashPkg from "lodash";
3-
const { isArray, isString, isPlainObject, flattenDeep } = lodashPkg;
3+
const { isArray, isString, isPlainObject, flattenDeep, compact } = lodashPkg;
44
import fsExtraPkg from "fs-extra";
55
const { createReadStream } = fsExtraPkg;
66
import { Client } from "@elastic/elasticsearch";
@@ -10,16 +10,9 @@ import { ROCrate } from "ro-crate";
1010
import FormData from "form-data";
1111
import fetch from "cross-fetch";
1212

13-
const typesToExcludeFromIndex = ["File", "GeoShape", "GeoCoordinates", "Language"];
14-
15-
export async function indexItem({ configuration, item, crate }) {
16-
// let configuration = await loadConfiguration();
17-
// console.log(configuration);
18-
// console.log(item);
19-
// console.log(crate);
20-
21-
// get the complete tei file and run it through the webservice to extract the text
13+
const typesToExcludeFromIndex = ["File", "GeoShape", "GeoCoordinates"];
2214

15+
export async function indexItem({ location = "workspace", configuration, item, crate }) {
2316
crate = new ROCrate(crate, { array: true, link: true });
2417
// let document = crate.getTree({ valueObject: false });
2518

@@ -29,18 +22,29 @@ export async function indexItem({ configuration, item, crate }) {
2922

3023
// setup the metadata index
3124
try {
32-
// await client.indices.delete({ index: "metadata" });
33-
await client.indices.get({ index: "metadata" });
25+
// await client.indices.delete({ index: "manuscripts" });
26+
await client.indices.get({ index: "manuscripts" });
3427
} catch (error) {
3528
await client.indices.create({
36-
index: "metadata",
29+
index: "manuscripts",
30+
mappings: {
31+
properties: {
32+
location: {
33+
type: "geo_shape",
34+
},
35+
// languageSuggest: {
36+
// type: "completion",
37+
// },
38+
},
39+
},
3740
settings: { "index.mapping.ignore_malformed": true },
3841
});
3942
}
4043

44+
// index the item metadata and content
4145
const indexIdentifier = `/${item.type}/${item.identifier}`;
4246
try {
43-
let store = await getStoreHandle({ id: item.identifier, type: "item" });
47+
let store = await getStoreHandle({ location, id: item.identifier, type: "item" });
4448
const teiFileContent = await store.get({
4549
target: `${item.identifier}-tei-complete.xml`,
4650
});
@@ -51,10 +55,11 @@ export async function indexItem({ configuration, item, crate }) {
5155
const document = assembleIndexRecord({ crate });
5256
document.text = teiText;
5357
await client.index({
54-
index: "metadata",
58+
index: "manuscripts",
5559
id: indexIdentifier,
5660
document,
5761
});
62+
// console.log(document);
5863
} catch (error) {
5964
console.log(error);
6065
}
@@ -83,7 +88,7 @@ export async function deleteItemFromIndex({ item, configuration }) {
8388

8489
const indexIdentifier = `/${item.type}/${item.identifier}`;
8590
await client.delete({
86-
index: "metadata",
91+
index: "manuscripts",
8792
id: indexIdentifier,
8893
});
8994
}
@@ -112,7 +117,7 @@ export function assembleIndexRecord({ crate }) {
112117
access: crate.rootDataset?.licence?.[0].name?.[0] ?? "Restricted",
113118
location: geography,
114119
};
115-
// console.log(record);
120+
// record.languageSuggest = [...record.subjectLanguage, ...record.contentLanguage];
116121
return record;
117122
}
118123

@@ -133,49 +138,27 @@ export function extractGeography({ crate }) {
133138
'{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[58.07810783386231,29.095852076791065],[58.07810783386231,-19.12303093039881],[11.671857833862305,-19.12303093039881],[11.671857833862305,29.095852076791065]]]}}',
134139
],
135140
});
136-
const geography = entities.map((entity) => {
137-
if (entity?.geojson?.length) {
138-
let geojson = JSON.parse(entity.geojson[0]);
139-
140-
let coordinates = geojson?.geometry?.coordinates.map((e) => {
141-
if (isString(e)) return parseFloat(e);
142-
if (isArray(e)) {
143-
return [
144-
e.map((c) => {
145-
return parseFloat(c);
146-
}),
147-
];
148-
}
149-
});
150-
// console.log(JSON.stringify(coordinates, null, 2));
151-
return coordinates;
141+
let coordinates = flattenDeep(entities.map((e) => JSON.parse(e.geojson).geometry)).map(
142+
(feature) => {
143+
feature.coordinates = parseValuesAsFloat(feature.coordinates);
144+
if (feature.type.match(/polygon/i)) {
145+
feature.coordinates[0].push(feature.coordinates[0][0]);
146+
}
147+
return feature;
152148
}
153-
});
154-
155-
// console.log(JSON.stringify(geography, null, 2));
156-
157-
return geography;
158-
159-
// const feature = {
160-
// type: "Feature",
161-
// properties: { name: "Yorta Yorta" },
162-
// geometry: { type: "Point", coordinates: [145.26357989848, -36.093929709321] },
163-
// };
164-
165-
// const feature = {
166-
// type: "Feature",
167-
// geometry: {
168-
// type: "Polygon",
169-
// coordinates: [
170-
// [
171-
// [144.56249892711642, -27.126287638023676],
172-
// [144.56249892711642, -29.486150057382325],
173-
// [138.27831923961642, -29.486150057382325],
174-
// [138.27831923961642, -27.126287638023676],
175-
// ],
176-
// ],
177-
// },
178-
// };
149+
);
150+
// console.log("2", JSON.stringify(coordinates, null, 2));
151+
coordinates = compact(coordinates);
152+
return coordinates;
153+
154+
function parseValuesAsFloat(arr) {
155+
return arr.map((v) => {
156+
if (isArray(v)) {
157+
return parseValuesAsFloat(v);
158+
}
159+
return parseFloat(v);
160+
});
161+
}
179162
}
180163

181164
// TODO this method does not have tests

api/src/lib/admin.js

+23-9
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export async function publishObject({ user, type, identifier, configuration }) {
190190

191191
// try indexing the content and fail early if the metadata is bad
192192
try {
193-
await indexItem({ item: { identifier, type }, crate: crate.toJSON() });
193+
await indexItem({ configuration, item: { identifier, type }, crate: crate.toJSON() });
194194
} catch (error) {
195195
throw new Error(
196196
`Metadata is invalid and can't be indexed. It needs to be fixed in order to publish the object.`
@@ -274,6 +274,7 @@ export async function objectRequiresMoreWork({ type, identifier }) {
274274
}
275275

276276
export async function depositObjectIntoRepository({
277+
configuration,
277278
type,
278279
identifier,
279280
version = { metadata: false, images: false, documents: false },
@@ -334,7 +335,11 @@ export async function depositObjectIntoRepository({
334335
msg: `Copying ${type} resources to the repository`,
335336
date: new Date(),
336337
});
337-
await objectRepository.copy({ batch: resources });
338+
try {
339+
await objectRepository.copy({ batch: resources });
340+
} catch (error) {
341+
console.error(error);
342+
}
338343

339344
// delete the files from the workspace entry
340345
io.emit(`deposit-${type}`, {
@@ -351,7 +356,11 @@ export async function depositObjectIntoRepository({
351356
item = item[0];
352357

353358
// setup the metadata in the db
354-
await setRepositoryItemMetadata({ item, store: objectRepository });
359+
try {
360+
await setRepositoryItemMetadata({ configuration, item, store: objectRepository });
361+
} catch (error) {
362+
console.error(error);
363+
}
355364
}
356365

357366
export async function restoreObjectIntoWorkspace({ type, identifier, io = { emit: () => {} } }) {
@@ -386,11 +395,11 @@ export async function restoreObjectIntoWorkspace({ type, identifier, io = { emit
386395
let resources = await objectRepository.listResources();
387396
resources = resources
388397
.filter((resource) => !resource.Key.match(/nocfl.*/))
389-
// .filter((resource) => {
390-
// return !resource.Key.match(
391-
// /.*\.v\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z).*/
392-
// );
393-
// })
398+
.filter((resource) => {
399+
return !resource.Key.match(
400+
/.*\.v\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z).*/
401+
);
402+
})
394403
.map((resource) => {
395404
return {
396405
target: resource.Key,
@@ -440,7 +449,12 @@ export async function setRepositoryItemMetadata({ configuration, item, store })
440449
await item.save();
441450

442451
// index the item data in the repository
443-
await indexItem({ configuration, item: { identifier, type }, crate: crate.toJSON() });
452+
await indexItem({
453+
location: "repository",
454+
configuration,
455+
item: { identifier, type },
456+
crate: crate.toJSON(),
457+
});
444458
} catch (error) {
445459
console.log(error);
446460
log.error(`There was an issue depositing '${type}:${identifier}: ${error.message}`);

api/src/routes/admin.js

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ async function putDepositObjectHandler(req, res) {
176176
date: new Date(),
177177
});
178178
await depositObjectIntoRepository({
179+
configuration: req.session.configuration,
179180
type,
180181
identifier,
181182
version,

0 commit comments

Comments
 (0)