Skip to content

Commit

Permalink
Merge pull request #127 from CSCfi/CSCTTV-3801-publication-type-filte…
Browse files Browse the repository at this point in the history
…ring

CSCTTV-3801 publication filtering by reference data code values
  • Loading branch information
sarkikos authored Apr 8, 2024
2 parents c303d4b + 16403c8 commit cb0e2c0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,22 @@ private static IEnumerable<Func<QueryContainerDescriptor<Publication>, QueryCont
.Value(parameters.AuthorOrcId)));
}

if (parameters.TypeCode is not null)
// Searching with type code requires exact match.
if (!string.IsNullOrWhiteSpace(parameters.TypeCode))
{
filters.Add(t =>
t.Term(s => s.Field(f => f.Type)
.Value(parameters.TypeCode)));
filters.Add(t => t.Term(term => term
.Field(f => f.Type!.Code)
.Value(parameters.TypeCode)
));
}

if (parameters.PublisherOpenAccess is not null)

// Searching with publisher open access code requires exact match.
if (!string.IsNullOrWhiteSpace(parameters.PublisherOpenAccess))
{
filters.Add(t =>
t.Term(s => s.Field(f => f.PublisherOpenAccess)
.Value(parameters.PublisherOpenAccess)));
filters.Add(t => t.Term(term => term
.Field(f => f.PublisherOpenAccess!.Code)
.Value(parameters.PublisherOpenAccess)
));
}

if (parameters.Issn is not null)
Expand Down Expand Up @@ -274,11 +278,13 @@ private static IEnumerable<Func<QueryContainerDescriptor<Publication>, QueryCont
.Value(parameters.Doi)));
}

if (parameters.Status is not null)
// Searching with status requires exact match.
if (!string.IsNullOrWhiteSpace(parameters.Status))
{
filters.Add(t =>
t.Term(s => s.Field(f => f.Status)
.Value(parameters.Status)));
filters.Add(t => t.Term(term => term
.Field(f => f.Status!.Code)
.Value(parameters.Status)
));
}

return filters;
Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/src/Interface/Maps/PublicationProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public PublicationProfile()
AllowNullDestinationValues = true;

CreateMap<GetPublicationsQueryParameters, PublicationSearchParameters>()
.ForMember(dst => dst.TypeCode, opt => opt.MapFrom(src => src.Type!.ToLower()));
.ForMember(dst => dst.TypeCode, opt => opt.MapFrom(src => src.Type!));

CreateMap<Service.Models.Publication.Publication, Publication>()
.ForMember(dst => dst.PublicationYear, opt => opt.MapFrom(src => src.PublicationYear.HasValue ? src.PublicationYear.Value.ToString(DateTimeYearFormat) : null))
Expand Down
1 change: 0 additions & 1 deletion aspnetcore/src/Service.Models/ReferenceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public class ReferenceData
{
[Keyword]
public string? Code { get; set; }

public string? NameFi { get; set; }
public string? NameSv { get; set; }
public string? NameEn { get; set; }
Expand Down

0 comments on commit cb0e2c0

Please sign in to comment.