diff --git a/src/SemanticSearch/RdfClient.cs b/src/SemanticSearch/RdfClient.cs
index 71be2ca3f7cec857628bf0d3e39a43d407a9fde8..49c1d946c97be64c3060bb39ddece3cc770b1be2 100644
--- a/src/SemanticSearch/RdfClient.cs
+++ b/src/SemanticSearch/RdfClient.cs
@@ -13,7 +13,7 @@ namespace Coscine.SemanticSearch
///
/// Provides all necessary queries to the RDF database to create a mapping of metadata graphs into a document.
///
- public class RdfClient
+ public class RdfClient
{
public const string LABEL_LITERAL_RULE = "instance";
public const string LABEL_ADDITIONAL_RULE = "graph";
@@ -62,6 +62,10 @@ namespace Coscine.SemanticSearch
}} LIMIT 1";
_queryString.SetUri("uri", new Uri(graphName));
var results = _connector.QueryWithResultSet(_queryString);
+ if (results.Count == 0)
+ {
+ return null;
+ }
return results.First().Value("applicationProfile").ToString();
}
@@ -192,7 +196,7 @@ namespace Coscine.SemanticSearch
// Expected correct URI format for Projects: https://purl.org/coscine/projects/{ProjectGUID}
var projectRoleModel = new ProjectRoleModel();
- return projectRoleModel.GetAllWhere(p => p.UserId.Equals(Guid.Parse(user)) && p.Project.Deleted == false).Select(p => $"https://purl.org/coscine/projects/{p.ProjectId}").ToList();
+ return projectRoleModel.GetAllWhere(p => p.UserId.Equals(Guid.Parse(user)) && p.Project.Deleted == false).Select(p => $"https://purl.org/coscine/projects/{p.ProjectId}").ToList();
}
///
@@ -329,7 +333,7 @@ namespace Coscine.SemanticSearch
}} ORDER BY ?order";
_queryString.SetUri("uri", new Uri(graphName));
var results = _connector.QueryWithResultSet(_queryString);
-
+
return results.ToDictionary(
x => x.Value("class").ToString(),
x =>
@@ -466,13 +470,13 @@ namespace Coscine.SemanticSearch
foreach (var graph in documents.Keys)
{
jObjects.Add(graph, CreateFields(documents[graph], profile, indexMapper));
- }
- }
+ }
+ }
else if (documents.Count() > 0)
{
jObjects.Add(graphName, CreateFields(documents[graphName], profile, indexMapper));
}
-
+
return jObjects;
}
@@ -503,11 +507,17 @@ namespace Coscine.SemanticSearch
try
{
jObject.Merge(_dataTypeParser.Parse(label, triple.Object, indexMapper, profile));
- } catch (NotIndexableException e)
+ }
+ catch (NotIndexableException e)
{
Console.WriteLine($"Property {property} could not be indexed. Reason: {e.Reason}");
continue;
}
+ catch (FormatException e)
+ {
+ Console.WriteLine($"Property {property} could not be indexed. Reason: {e.Message}");
+ continue;
+ }
}
return jObject;
}
diff --git a/src/SemanticSearch/RdfSearchMapper.cs b/src/SemanticSearch/RdfSearchMapper.cs
index 2d10e94099a2ad1e0f73202f9048a0cf1f4fd6b2..38d5ff4741d200e7d5d06587f4b2cbf5bac067df 100644
--- a/src/SemanticSearch/RdfSearchMapper.cs
+++ b/src/SemanticSearch/RdfSearchMapper.cs
@@ -100,18 +100,28 @@ namespace Coscine.SemanticSearch
{
_indexMapper = new ElasticsearchIndexMapper(_rdfClient, await _searchClient.GetMappingAsync());
var applicationProfileId = _rdfClient.GetApplicationProfileOfMetadata(graphName);
- SpecificApplicationProfile profile = new SpecificApplicationProfile(_rdfClient, applicationProfileId);
+ // Null should mean that no document exists to the graph
+ if (applicationProfileId == null)
+ {
+ // Graph may only be deleted from the RDF database after the mapping has been deleted in the search engine!
+ // first the graph is only marked as deleted because additional rules have to be executed because they have effects on other graphs and still need the data of the graph to be deleted
+ _rdfClient.MarkGraphAsDeleted(graphName);
+ }
+ else
+ {
+ SpecificApplicationProfile profile = new SpecificApplicationProfile(_rdfClient, applicationProfileId);
- // Graph may only be deleted from the RDF database after the mapping has been deleted in the search engine!
- // first the graph is only marked as deleted because additional rules have to be executed because they have effects on other graphs and still need the data of the graph to be deleted
- _rdfClient.MarkGraphAsDeleted(graphName);
+ // Graph may only be deleted from the RDF database after the mapping has been deleted in the search engine!
+ // first the graph is only marked as deleted because additional rules have to be executed because they have effects on other graphs and still need the data of the graph to be deleted
+ _rdfClient.MarkGraphAsDeleted(graphName);
- // construct additional triples for specific application profile
- var documents = _rdfClient.CreateFieldsFromAdditionalRule(graphName, profile, _indexMapper, true);
- // only the changes of the other documents are considered because the graph will be deleted
- documents.Remove(graphName);
+ // construct additional triples for specific application profile
+ var documents = _rdfClient.CreateFieldsFromAdditionalRule(graphName, profile, _indexMapper, true);
+ // only the changes of the other documents are considered because the graph will be deleted
+ documents.Remove(graphName);
- await _searchClient.DeleteDocumentAsync(graphName, documents);
+ await _searchClient.DeleteDocumentAsync(graphName, documents);
+ }
}
/************** INITIAL INDEX ************/
@@ -125,7 +135,7 @@ namespace Coscine.SemanticSearch
_indexMapper = new ElasticsearchIndexMapper(_rdfClient);
var content = _indexMapper.CreateIndex(ElasticsearchIndexMapper.DEFAULT_ALIAS_NAME);
- await _searchClient.CreateIndexAsync(content, GetCurrentIndex());
+ await _searchClient.CreateIndexAsync(content, GetCurrentIndex());
_indexMapper.ReplaceMapping(await _searchClient.GetMappingAsync());
@@ -160,7 +170,7 @@ namespace Coscine.SemanticSearch
var oldIndex = GetCurrentIndex();
_version++; // increase version
_rdfClient.SetCurrentIndexVersion(_version);
- var newIndex = GetCurrentIndex();
+ var newIndex = GetCurrentIndex();
_searchClient.ChangeIndex(newIndex);
_indexMapper.ReplaceMapping(await _searchClient.GetMappingAsync());
@@ -194,6 +204,10 @@ namespace Coscine.SemanticSearch
private IDictionary CreateDocument(string graphName, bool changeOtherDocs)
{
var applicationProfileId = _rdfClient.GetApplicationProfileOfMetadata(graphName);
+ if (applicationProfileId == null)
+ {
+ return new Dictionary { { graphName, new JObject() } };
+ }
SpecificApplicationProfile profile = new SpecificApplicationProfile(_rdfClient, applicationProfileId);
// create properties
diff --git a/src/SemanticSearch/SemanticSearch.csproj b/src/SemanticSearch/SemanticSearch.csproj
index 4e0564f974486358441510a8d86035c8f4da203a..03b9f48f2ef4d0dabef225c2b9483cc35638d7d6 100644
--- a/src/SemanticSearch/SemanticSearch.csproj
+++ b/src/SemanticSearch/SemanticSearch.csproj
@@ -5,7 +5,7 @@
true
Coscine.SemanticSearch
Coscine.SemanticSearch
- 1.2.0
+ 1.2.1
RWTH Aachen University