Commits (3)
......@@ -13,7 +13,7 @@ namespace Coscine.SemanticSearch
/// <summary>
/// Provides all necessary queries to the RDF database to create a mapping of metadata graphs into a document.
/// </summary>
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();
}
/// <summary>
......@@ -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;
}
......
......@@ -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<string, JObject> CreateDocument(string graphName, bool changeOtherDocs)
{
var applicationProfileId = _rdfClient.GetApplicationProfileOfMetadata(graphName);
if (applicationProfileId == null)
{
return new Dictionary<string, JObject> { { graphName, new JObject() } };
}
SpecificApplicationProfile profile = new SpecificApplicationProfile(_rdfClient, applicationProfileId);
// create properties
......
......@@ -5,7 +5,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Coscine.SemanticSearch</AssemblyName>
<RootNamespace>Coscine.SemanticSearch</RootNamespace>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
</PropertyGroup>
<PropertyGroup>
<Authors>RWTH Aachen University</Authors>
......