Add filter by publication date
This commit is contained in:
parent
0c256ea06f
commit
8453eaef06
|
@ -9,6 +9,9 @@ import jakarta.validation.constraints.Pattern;
|
|||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -34,9 +37,16 @@ public class ResearchProductsRequest {
|
|||
private String[] originalId;
|
||||
|
||||
@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;
|
||||
|
||||
@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")))
|
||||
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")))
|
||||
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")))
|
||||
private String[] publisher;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import eu.openaire.api.mappers.Utils;
|
|||
import eu.openaire.api.solr.SolrQueryParams;
|
||||
import org.mapstruct.*;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
@ -60,7 +61,8 @@ public interface ResearchProductsRequestMapper {
|
|||
Map.entry("isInDiamondJournal", "isindiamondjournal:(%s)"),
|
||||
Map.entry("isPubliclyFunded", "publiclyfunded:(%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);
|
||||
}
|
||||
|
||||
// if (!Utils.isNullOrEmpty(src.getKeywords())) {
|
||||
// qList.add(String.format(solrFieldMapping.get("keywords"), Utils.escapeInput(src.getKeywords())));
|
||||
// }
|
||||
|
||||
// form query string
|
||||
if (!qList.isEmpty()) {
|
||||
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)));
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue