Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
## JSON LD Solr Indexer
---
**NOTES:**
- Currently spec'd to work only with Datacrate JSON-LD.
TODO:
- build schema of solr with config file
- Generalise to use any json-ld
- Make createCatalogSolr as part of the library
- Test with other types of json-ld's
---
Example implementation:
### Generate JSON-LDs
```
node generate-datacrates.js -d ./test-data/generated/ -n 100
```
or
```
npm run generate
```
### Commit to SOLR
Modify config.json to suit your needs.
Use
```
node ./commit-to-solr.js --config ./config.json
```
or
```
npm run commit
```
### Detail
```JavaScript
const fieldConfig = require('./fields.json');
let catalog = new CatalogSolr();
catalog.setConfig(fieldConfig);
const graph = _.each(ca['@graph'], (g) => {
return catalog.ensureObjArray(g);
});
const solrObject = {};
_.each(fieldConfig, (field, name) => {
let graphElement = _.filter(graph, (g) => {
return _.find(g['@type'], (gg) => gg === name) ? g : undefined;
});
if (graphElement) {
_.each(graphElement, (ge) => {
if (Array.isArray(solrObject[name])) {
solrObject[name].push(catalog.getGraphElement(fieldConfig[name], graph, ge));
} else {
solrObject[name] = [catalog.getGraphElement(fieldConfig[name], graph, ge)];
}
});
}
});
```