Add filter by publication date

This commit is contained in:
Serafeim Chatzopoulos 2024-06-12 15:44:45 +03:00
parent 0c256ea06f
commit 8453eaef06
2 changed files with 31 additions and 7 deletions

View File

@ -9,6 +9,9 @@ import jakarta.validation.constraints.Pattern;
import lombok.Data; import lombok.Data;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Getter @Getter
@Setter @Setter
@ -34,9 +37,16 @@ public class ResearchProductsRequest {
private String[] originalId; private String[] originalId;
@Parameter(description = "The type of the research product", array = @ArraySchema(schema = @Schema(type = "string", allowableValues = {"publication", "dataset", "software", "other"}))) @Parameter(description = "The type of the research product", array = @ArraySchema(schema = @Schema(type = "string", allowableValues = {"publication", "dataset", "software", "other"})))
// @Pattern(regexp = "^(publication|dataset|software|other)$", message = "type should be one of 'publication', 'dataset', 'software', 'other'")
private String[] type; private String[] type;
@Parameter(description = "Gets the research products whose publication date is greater than or equal the given date. Please provide a date formatted as YYYY-MM-DD", schema = @Schema(type = "string", format = "date"))
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date fromPublicationDate;
@Parameter(description = "Gets the research products whose publication date is less than or equal the given date. Please provide a date formatted as YYYY-MM-DD", schema = @Schema(type = "string", format = "date"))
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date toPublicationDate;
@Parameter(description = "List of subjects associated to the research product", array = @ArraySchema(schema = @Schema(type = "string"))) @Parameter(description = "List of subjects associated to the research product", array = @ArraySchema(schema = @Schema(type = "string")))
private String[] subjects; private String[] subjects;
@ -49,7 +59,6 @@ public class ResearchProductsRequest {
@Parameter(description = "The ORCiD of the authors involved in producing this research product", array = @ArraySchema(schema = @Schema(type = "string"))) @Parameter(description = "The ORCiD of the authors involved in producing this research product", array = @ArraySchema(schema = @Schema(type = "string")))
private String[] authorOrcid; private String[] authorOrcid;
@Parameter(description = "The name of the entity that holds, archives, publishes prints, distributes, releases, issues, or produces the resource.", array = @ArraySchema(schema = @Schema(type = "string"))) @Parameter(description = "The name of the entity that holds, archives, publishes prints, distributes, releases, issues, or produces the resource.", array = @ArraySchema(schema = @Schema(type = "string")))
private String[] publisher; private String[] publisher;

View File

@ -5,6 +5,7 @@ import eu.openaire.api.mappers.Utils;
import eu.openaire.api.solr.SolrQueryParams; import eu.openaire.api.solr.SolrQueryParams;
import org.mapstruct.*; import org.mapstruct.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
@ -60,7 +61,8 @@ public interface ResearchProductsRequestMapper {
Map.entry("isInDiamondJournal", "isindiamondjournal:(%s)"), Map.entry("isInDiamondJournal", "isindiamondjournal:(%s)"),
Map.entry("isPubliclyFunded", "publiclyfunded:(%s)"), Map.entry("isPubliclyFunded", "publiclyfunded:(%s)"),
Map.entry("isGreen", "isgreen:(%s)"), Map.entry("isGreen", "isgreen:(%s)"),
Map.entry("openAccessColor", "openaccesscolor:(%s)") Map.entry("openAccessColor", "openaccesscolor:(%s)"),
Map.entry("publicationDate", "resultdateofacceptance:[%s TO %s]")
); );
@ -94,10 +96,6 @@ public interface ResearchProductsRequestMapper {
qList.add(hasProjectField); qList.add(hasProjectField);
} }
// if (!Utils.isNullOrEmpty(src.getKeywords())) {
// qList.add(String.format(solrFieldMapping.get("keywords"), Utils.escapeInput(src.getKeywords())));
// }
// form query string // form query string
if (!qList.isEmpty()) { if (!qList.isEmpty()) {
solrQueryParams.setQ(String.join(" AND ", qList)); solrQueryParams.setQ(String.join(" AND ", qList));
@ -221,6 +219,23 @@ public interface ResearchProductsRequestMapper {
fqList.add(String.format(solrFieldMapping.get("openAccessColor"), Utils.escapeAndJoin(src.getOpenAccessColor(), "OR", false))); fqList.add(String.format(solrFieldMapping.get("openAccessColor"), Utils.escapeAndJoin(src.getOpenAccessColor(), "OR", false)));
} }
// publication date
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
if (src.getFromPublicationDate() != null && src.getToPublicationDate() != null) {
fqList.add(String.format(solrFieldMapping.get("publicationDate"), formatter.format(src.getFromPublicationDate()), formatter.format(src.getToPublicationDate())));
} else {
if (src.getFromPublicationDate() != null) {
fqList.add(String.format(solrFieldMapping.get("publicationDate"), formatter.format(src.getFromPublicationDate()), "*"));
}
if (src.getToPublicationDate() != null) {
fqList.add(String.format(solrFieldMapping.get("publicationDate"), "*", formatter.format(src.getToPublicationDate())));
}
}
solrQueryParams.setFq(fqList); solrQueryParams.setFq(fqList);
} }