@data-fair/catalog-onegeo-suite 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/imports.ts CHANGED
@@ -154,7 +154,7 @@ export const getResource = async ({ catalogConfig, importConfig, resourceId, tmp
154
154
  },
155
155
  keywords: catalog._source['metadata-fr'].keyword,
156
156
  updatedAt: catalog._source['metadata-fr'].lastUpdateDate ?? undefined,
157
- image: catalog._source['metadata-fr'].image.find((x: { type: string, url: string | null }) => { return x.type === 'thumbnail' && !!x.url }).url ?? null,
157
+ image: catalog._source['metadata-fr'].image.find((x: { type: string, url: string | null }) => { return x.type === 'thumbnail' && !!x.url })?.url ?? null,
158
158
  origin
159
159
  }
160
160
  }
package/lib/list.ts CHANGED
@@ -10,13 +10,28 @@ const formatsList = [
10
10
  'CSV', 'ODS', 'Excel non structuré', 'Microsoft Excel',
11
11
  'ZIP', 'Shapefile (zip)', 'SHAPE-ZIP', 'GeoJSON', 'JSON', 'XML', 'GML', 'KML']
12
12
 
13
+ const extensionTable: Record<string, string> = {
14
+ CSV: '.csv',
15
+ GeoJSON: '.geojson',
16
+ JSON: '.json',
17
+ 'Shapefile (zip)': '.zip',
18
+ 'SHAPE-ZIP': '.zip',
19
+ ZIP: '.zip',
20
+ GML: '.gml',
21
+ KML: '.kml',
22
+ XML: '.xml',
23
+ ODS: '.ods',
24
+ 'Excel non structuré': '.xlsx',
25
+ 'Microsoft Excel': '.xls',
26
+ }
27
+
13
28
  const getBestFormat = (formats: string[]) => {
14
29
  return [...formats].sort((a, b) =>
15
30
  (formatsList.indexOf(a) === -1 ? formatsList.length : formatsList.indexOf(a)) -
16
31
  (formatsList.indexOf(b) === -1 ? formatsList.length : formatsList.indexOf(b))
17
32
  )
18
33
  }
19
- const baseReqDataset = (input: string = '*', size: number = 50, from: number = 1) => {
34
+ const baseReqDataset = (input: string = '*', size: number = 100, from: number = 1) => {
20
35
  return {
21
36
  from: (from - 1) * size,
22
37
  size: Math.min(size, 10000),
@@ -55,12 +70,64 @@ const baseReqDataset = (input: string = '*', size: number = 50, from: number = 1
55
70
  }
56
71
  }
57
72
 
73
+ const countReq = (input: string = '*') => {
74
+ return {
75
+ size: 0,
76
+ track_total_hits:
77
+ false,
78
+ query:
79
+ {
80
+ bool: {
81
+ must: [{
82
+ bool: {
83
+ should: [{
84
+ query_string: {
85
+ query: input || '*',
86
+ fields: ['data_and_metadata', 'metadata-fr.title^5', 'metadata-fr.abstract^3', 'content-fr.title^5', 'content-fr.excerpt^3', 'content-fr.plaintext'],
87
+ analyzer: 'my_search_analyzer',
88
+ fuzziness: 'AUTO',
89
+ minimum_should_match: '90%',
90
+ default_operator: 'AND',
91
+ boost: 5
92
+ }
93
+ }]
94
+ }
95
+ }, { term: { is_metadata: true } }, {
96
+ bool: {
97
+ should: [
98
+ ...apiList.filter((x: any) => x).map((x: any) => ({ term: { 'metadata-fr.link.service.keyword': x } })),
99
+ ...formatsList.filter((x: any) => x).map((x: any) => ({ term: { 'metadata-fr.link.formats.keyword': x } }))
100
+ ],
101
+ }
102
+ }],
103
+ must_not:
104
+ [{ term: { 'content-fr.status.keyword': 'draft' } }],
105
+ filter:
106
+ {
107
+ terms: {
108
+ 'type.keyword':
109
+ ['dataset', 'nonGeographicDataset']
110
+ }
111
+ }
112
+ }
113
+ },
114
+ aggs: {
115
+ unique_datasets: {
116
+ cardinality: {
117
+ field: 'uuid.keyword',
118
+ precision_threshold:
119
+ 40000
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+
58
126
  export const list = async ({ catalogConfig, params }: ListContext<OneGeoSuiteConfig, OneGeoCapabilities>): ReturnType<CatalogPlugin['list']> => {
59
127
  const url = catalogConfig.url
60
128
  const listResources = async (params: Record<any, any>) => {
61
- let catalogs = (await axios.post(new URL('fr/indexer/elastic/_search/', url).href, baseReqDataset(params.q, params.size, params.page))).data
62
- const count = catalogs.hits.total.value
63
- catalogs = catalogs.hits.hits
129
+ const catalogs = (await axios.post(new URL('fr/indexer/elastic/_search/', url).href, baseReqDataset(params.q || '*', params.size, params.page))).data.hits.hits
130
+ const count = (await axios.post(new URL('fr/indexer/elastic/_search/', 'https://www.datasud.fr').href, countReq(params.q))).data.aggregations.unique_datasets.value
64
131
  const res = []
65
132
 
66
133
  for (const catalog of catalogs) {
@@ -78,11 +145,21 @@ export const list = async ({ catalogConfig, params }: ListContext<OneGeoSuiteCon
78
145
  return apiList.indexOf(x.service) - apiList.indexOf(y.service)
79
146
  })
80
147
 
148
+ const formatsSet: Set<string> = new Set()
149
+
150
+ for (const source of sources) {
151
+ for (const format of source.formats) {
152
+ if (formatsList.includes(format)) formatsSet.add(format)
153
+ }
154
+ }
155
+ let formats = (new Array(...formatsSet)).sort((a: string, b: string) => { return formatsList.indexOf(a) - formatsList.indexOf(b) })
156
+ formats = formats.map(x => extensionTable[x]?.slice(1) ?? x)
157
+
81
158
  res.push({
82
159
  id: `${catalog._id}`,
83
160
  title: catalog._source['metadata-fr'].title,
84
161
  description: sources[0].description,
85
- format: '',
162
+ format: formats.slice(0, 3).join(', ') + (formats.length ? '..' : ''),
86
163
  type: 'resource'
87
164
  } as ResourceList[number])
88
165
  }
@@ -90,7 +167,6 @@ export const list = async ({ catalogConfig, params }: ListContext<OneGeoSuiteCon
90
167
  }
91
168
  // List datasets
92
169
  const [resources, count] = await listResources(params)
93
-
94
170
  return {
95
171
  count,
96
172
  results: resources,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@data-fair/catalog-onegeo-suite",
3
3
  "description": "OneGeoSuite plugin for the Data Fair catalogs service.",
4
- "version": "0.1.1",
4
+ "version": "0.1.3",
5
5
  "main": "index.ts",
6
6
  "type": "module",
7
7
  "scripts": {
@@ -32,7 +32,7 @@ export const schema = {
32
32
  "layout": {
33
33
  "cols": 6,
34
34
  "getItems": {
35
- "url": "${context.catalogConfig}/fr/indexer/elastic/_search/?q=_id:${context.resourceId}",
35
+ "url": "${context.catalogConfig.url}/fr/indexer/elastic/_search/?q=_id:${context.resourceId}",
36
36
  "itemsResults": "(function() { const links = data.hits.hits[0]._source['metadata-fr'].link; return links.filter(l => l.formats.find(f => ['CSV', 'ODS', 'Excel non structuré', 'Microsoft Excel','ZIP', 'Shapefile (zip)', 'GeoJSON', 'JSON', 'XML', 'GML', 'KML'].includes(f)) || ['WS', 'AFS', 'WFS'].includes(l.service)).map((l, i) => [l, i] ); })()",
37
37
  "itemTitle": "item[0].service?? 'Local N°' + (item[1] + 1)",
38
38
  "itemValue": "item[0].service?? item[0].url"
@@ -46,7 +46,7 @@ export const schema = {
46
46
  "if": "parent.data.service != null",
47
47
  "cols": 6,
48
48
  "getItems": {
49
- "url": "${context.catalogConfig}/fr/indexer/elastic/_search/?q=${parent.data.service}&q=_id:${context.resourceId}",
49
+ "url": "${context.catalogConfig.url}/fr/indexer/elastic/_search/?q=${parent.data.service}&q=_id:${context.resourceId}",
50
50
  "itemsResults": "(function(){const service = data.hits.hits[0]._source['metadata-fr'].link.find(x => x.service === parent.data.service || x.url === parent.data.service); let formats = service.formats; if (['WS', 'WFS', 'AFS'].includes(service.service) && !formats.includes('CSV')) {formats.push('CSV');} return formats; })()"
51
51
  }
52
52
  }
@@ -24,7 +24,7 @@
24
24
  "layout": {
25
25
  "cols": 6,
26
26
  "getItems": {
27
- "url": "${context.catalogConfig}/fr/indexer/elastic/_search/?q=_id:${context.resourceId}",
27
+ "url": "${context.catalogConfig.url}/fr/indexer/elastic/_search/?q=_id:${context.resourceId}",
28
28
  "itemsResults": "(function() { const links = data.hits.hits[0]._source['metadata-fr'].link; return links.filter(l => l.formats.find(f => ['CSV', 'ODS', 'Excel non structuré', 'Microsoft Excel','ZIP', 'Shapefile (zip)', 'GeoJSON', 'JSON', 'XML', 'GML', 'KML'].includes(f)) || ['WS', 'AFS', 'WFS'].includes(l.service)).map((l, i) => [l, i] ); })()",
29
29
  "itemTitle": "item[0].service?? 'Local N°' + (item[1] + 1)",
30
30
  "itemValue": "item[0].service?? item[0].url"
@@ -38,7 +38,7 @@
38
38
  "if": "parent.data.service != null",
39
39
  "cols": 6,
40
40
  "getItems": {
41
- "url": "${context.catalogConfig}/fr/indexer/elastic/_search/?q=${parent.data.service}&q=_id:${context.resourceId}",
41
+ "url": "${context.catalogConfig.url}/fr/indexer/elastic/_search/?q=${parent.data.service}&q=_id:${context.resourceId}",
42
42
  "itemsResults": "(function(){const service = data.hits.hits[0]._source['metadata-fr'].link.find(x => x.service === parent.data.service || x.url === parent.data.service); let formats = service.formats; if (['WS', 'WFS', 'AFS'].includes(service.service) && !formats.includes('CSV')) {formats.push('CSV');} return formats; })()"
43
43
  }
44
44
  }