Skip to content
Snippets Groups Projects
Commit a4f50c59 authored by PTSEFTON's avatar PTSEFTON
Browse files

Dealing with indexing resolved stuff

parent d98cde56
Branches
No related merge requests found
......@@ -10,5 +10,5 @@
"waitPeriod": 0,
"schema": "./schema.json",
"fields": "./fields.json",
"batch": 1000
"batch": 1
}
......@@ -18,7 +18,7 @@
"name": "ocfl_demo",
"filter": { "is_root": true }
},
"@reverse": { "skip": true },
"hasPart": { "skip": true },
"hasFile": { "skip": true },
"temporalCoverage": { "skip": true },
......@@ -53,10 +53,19 @@
},
"Person": {
"@id" : {
"filter" : { "re" : ".*$"}
},
"@reverse": { "skip": true },
"affiliation": {
"resolve": "multi"
}
},
"birthDate": {
"facet": true,
"validate": "date"
}
}
}
}
\ No newline at end of file
......@@ -138,6 +138,9 @@ class CatalogSolr {
createSolrDocument(jsonld) {
const crate = new ROCrate(jsonld);
this.crate = crate;
// Keep track of things that are resolved and have index config (ignoring filter)
this.resolvedItemsToIndex = {};
crate.index();
const cfBase = this.config['map_all'] || {};
......@@ -174,22 +177,31 @@ class CatalogSolr {
const rootSolr = this.mapItem(cfBase, datasetCf, crate, 'Dataset', rootItem);
const solrDocument = { 'Dataset': [ rootSolr ] };
// TODO INHERET LICENCE IF ITEM DOES NOT HAVE ONE
// |||||||
// VVVVVVV
// loop through each item in the JSON-LD @graph
for ( const item of crate.graph ) {
if( item['@id'] !== rootOrigId ) {
const type = item['@type'];
if( type in cfTypes ) {
// get config for this type of item
const cf = cfTypes[item['@type']];
if( this.filters[type](item) ) {
const solr = this.mapItem(cfBase, cf, crate, type, item)
if( !(type in solrDocument) ) {
solrDocument[type] = [];
var types = this.crate.utils.asArray(item['@type']);
// Look through types in order
for (let type of Object.keys(cfTypes)) {
if( types.includes(type) ) {
// get config for this type of item
const cf = cfTypes[type];
if(this.resolvedItemsToIndex[item["@id"]] || this.filters[type](item) ) {
// Only do ONCE per type
types = [type];
item["@type"] = types;
const solr = this.mapItem(cfBase, cf, crate, type, item)
if( !(type in solrDocument) ) {
solrDocument[type] = [];
}
solrDocument[type].push(solr)
}
solrDocument[type].push(solr)
}
}
}
}
}
......@@ -214,6 +226,19 @@ class CatalogSolr {
// resolve lookups
if( fieldcf['resolve'] ) {
solr[field] = this.resolveValues(crate, fieldcf['resolve'], value);
const vals = this.crate.utils.asArray(solr[field]);
console.log("VALS", vals);
solr[`${field}_id`] = [];
for (let val of vals) {
try {
const value = JSON.parse(val);
solr[`${field}_id`].push(value["@id"]);
}
catch (e) {
console.log("ERROR", e.message, val)
}
}
} else {
if( fieldcf['multi'] ) {
solr[field] = value;
......@@ -253,7 +278,7 @@ class CatalogSolr {
return [ this.resolveAndFlatten(crate, value) ];
}
} else {
if( Array.isArray(value) ) {
if( Array.isArray(value) ) {
return this.resolveAndFlatten(crate, value[0]);
} else {
return this.resolveAndFlatten(crate, value);
......@@ -262,7 +287,7 @@ class CatalogSolr {
}
resolveAndFlatten(crate, value) {
resolveAndFlatten(crate, value, solr) {
if( !('@id' in value ) ) {
return value;
return this.convertError(`no @id found in value ${JSON.stringify(value)}`);
......@@ -271,6 +296,14 @@ class CatalogSolr {
if( !resolved ) {
return this.convertError(`@id ${value['@id']} not found`);
}
const resolvedTypes = this.crate.utils.asArray((resolved["@type"]));
for (let type of Object.keys(this.config['types'])) {
const cf = this.config['type'];
if (resolvedTypes.includes(type)) {
this.resolvedItemsToIndex[resolved["@id"]] = true;
}
}
return JSON.stringify(resolved).replace(/"/g, '\"');
}
......@@ -304,11 +337,12 @@ class CatalogSolr {
return resolved;
}
// primitive validation, just to weed out bad dates at this stage
// primitive normalisation/validation, just to weed out bad dates at this stage
validate(type, value) {
if( type === 'date' ) {
if( value.match(/^\d\d\d\d-\d\d-\d\d?$/) ) {
value = value.replace(/[^\d-]+/, "");
if( value.match(/^(\d\d\d\d)(-\d\d-\d\d?$)?/) ) {
return value;
}
console.log(`Date ${value} did not match`);
......
......@@ -20,6 +20,12 @@
"type": "text_en",
"stored": true,
"multiValued": true
},
{
"name": "author_id",
"type": "text_en",
"stored": true,
"multiValued": true
}
],
"dynamic-field": [
......@@ -28,6 +34,12 @@
"type": "text_en",
"stored": true
},
{
"name": "*_id",
"type": "text_en",
"stored": true,
"multiValued": true
},
{
"name": "*_description",
"type": "text_en",
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment