Move solr field mappings for data sources && add quotes

This commit is contained in:
Serafeim Chatzopoulos 2024-06-28 14:30:09 +03:00
parent 716964b78b
commit a8f3c1dd72
3 changed files with 29 additions and 26 deletions

View File

@ -67,7 +67,7 @@ public class DataSourceRequest {
private String[] contentTypes;
@Parameter(
description = "Retrieve data sources connected to the organization with OpenAIRE id",
description = "Retrieve data sources connected to the organization (with OpenAIRE id)",
array = @ArraySchema(schema = @Schema(type = "string"))
)
private String[] relOrganizationId;

View File

@ -11,14 +11,10 @@ import java.util.Map;
@Mapper(componentModel = "spring")
public interface DataSourceRequestMapper {
Map<String, String> sortFieldMapping = Map.ofEntries(
Map.entry("relevance", "score")
);
@Mapping(target = "start", expression = "java( calculateStart(src.getPage(), src.getPageSize()) )")
@Mapping(target = "rows", source = "pageSize")
@Mapping(target = "debugQuery", source = "debugQuery")
@Mapping(target = "sort", expression = "java( eu.openaire.api.mappers.Utils.formatSortByParam(src.getSortBy(), sortFieldMapping) )")
@Mapping(target = "sort", expression = "java( eu.openaire.api.mappers.Utils.formatSortByParam(src.getSortBy(), SolrFieldsMapper.dataSourceSortMapping) )")
SolrQueryParams toSolrQuery(DataSourceRequest src);
@Named("calculateStart")
@ -29,24 +25,7 @@ public interface DataSourceRequestMapper {
@AfterMapping
default void paramsCustomMapping(DataSourceRequest src, @MappingTarget SolrQueryParams solrQueryParams) {
final Map<String, String> solrFieldMapping = Map.ofEntries(
// search field mapping
Map.entry("search", "__all:(%s)"),
Map.entry("officialName", "datasourceofficialname:(%s)"),
Map.entry("englishName", "datasourceenglishname:(%s)"),
// filter query field mapping
Map.entry("id", "__indexrecordidentifier:(%s)"),
Map.entry("pid", "pid:(%s)"),
Map.entry("subjects", "datasourceodsubjects:(%s)"),
Map.entry("dataSourceTypeName", "datasourcetypename:(%s)"),
Map.entry("contentTypes", "datasourceodcontenttypes:(%s)"),
Map.entry("relOrganizationId", "relorganizationid:(%s)"),
// filter by related entity fields
Map.entry("relCommunityId", "communityid:(%s)"),
Map.entry("relCollectedFromDatasourceId", "collectedfromdatasourceid:(%s)")
);
final Map<String, String> solrFieldMapping = SolrFieldsMapper.dataSourceFieldMapping;
var qList = new ArrayList<String>();
@ -84,7 +63,7 @@ public interface DataSourceRequestMapper {
}
if (!Utils.isNullOrEmpty(src.getSubjects())) {
fqList.add(String.format(solrFieldMapping.get("subjects"), Utils.escapeAndJoin(src.getSubjects(), "OR", false)));
fqList.add(String.format(solrFieldMapping.get("subjects"), Utils.escapeAndJoin(src.getSubjects(), "OR", true)));
}
if (!Utils.isNullOrEmpty(src.getDataSourceTypeName())) {
@ -92,7 +71,7 @@ public interface DataSourceRequestMapper {
}
if (!Utils.isNullOrEmpty(src.getContentTypes())) {
fqList.add(String.format(solrFieldMapping.get("contentTypes"), Utils.escapeAndJoin(src.getContentTypes(), "OR", false)));
fqList.add(String.format(solrFieldMapping.get("contentTypes"), Utils.escapeAndJoin(src.getContentTypes(), "OR", true)));
}
// related entity fields

View File

@ -4,6 +4,7 @@ import java.util.Map;
public class SolrFieldsMapper {
// mappings for the organization entity
public static final Map<String, String> organizationFieldsMapping = Map.ofEntries(
// search field mapping
Map.entry("search", "__all:(%s)"),
@ -25,5 +26,28 @@ public class SolrFieldsMapper {
Map.entry("relevance", "score")
);
// mappings for the datasource entity
public static final Map<String, String> dataSourceFieldMapping = Map.ofEntries(
// search field mapping
Map.entry("search", "__all:(%s)"),
Map.entry("officialName", "datasourceofficialname:(%s)"),
Map.entry("englishName", "datasourceenglishname:(%s)"),
// filter query field mapping
Map.entry("id", "__indexrecordidentifier:(%s)"),
Map.entry("pid", "pid:(%s)"),
Map.entry("subjects", "datasourceodsubjects:(%s)"),
Map.entry("dataSourceTypeName", "datasourcetypename:(%s)"),
Map.entry("contentTypes", "datasourceodcontenttypes:(%s)"),
// filter by related entity fields
Map.entry("relOrganizationId", "relorganizationid:(%s)"),
Map.entry("relCommunityId", "communityid:(%s)"),
Map.entry("relCollectedFromDatasourceId", "collectedfromdatasourceid:(%s)")
);
public static final Map<String, String> dataSourceSortMapping = Map.ofEntries(
Map.entry("relevance", "score")
);
}