Skip to content

Commit

Permalink
Use nested type for publication author. Modify publication author sea…
Browse files Browse the repository at this point in the history
…rch queries.
  • Loading branch information
sarkikos committed Mar 19, 2024
1 parent 54e2e50 commit 9ae78d1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,45 @@ private static IEnumerable<Func<QueryContainerDescriptor<Publication>, QueryCont
.Query(parameters.AuthorsText)));
}

if (!string.IsNullOrWhiteSpace(parameters.AuthorFirstNames))
if (!string.IsNullOrWhiteSpace(parameters.AuthorFirstNames) && string.IsNullOrWhiteSpace(parameters.AuthorLastName))
{
subQueries.Add(t =>
t.Match(query => query.Field(f => f.Authors.Suffix(nameof(Author.FirstNames)))
.Query(parameters.AuthorFirstNames)));
// Only first names
subQueries.Add(
q => q.Nested(
query => query
.Path(p => p.Authors)
.Query(
q => q.Match(m => m
.Field(f => f.Authors.Suffix(nameof(Author.FirstNames)))
.Query(parameters.AuthorFirstNames)))));
}

if (!string.IsNullOrWhiteSpace(parameters.AuthorLastName))
else if (string.IsNullOrWhiteSpace(parameters.AuthorFirstNames) && !string.IsNullOrWhiteSpace(parameters.AuthorLastName))
{
subQueries.Add(t =>
t.Match(query => query.Field(f => f.Authors.Suffix(nameof(Author.LastName)))
.Query(parameters.AuthorLastName)));
// Only last name
subQueries.Add(
q => q.Nested(
query => query
.Path(p => p.Authors)
.Query(
q => q.Match(m => m
.Field(f => f.Authors.Suffix(nameof(Author.LastName)))
.Query(parameters.AuthorLastName)))));
}
else if (!string.IsNullOrWhiteSpace(parameters.AuthorFirstNames) && !string.IsNullOrWhiteSpace(parameters.AuthorLastName))
{
// Both first names and last name
subQueries.Add(
q => q.Nested(
query => query
.Path(p => p.Authors)
.Query(
q => q.Bool(b => b
.Must(mu => mu
.Match(m => m
.Field(f => f.Authors.Suffix(nameof(Author.FirstNames))).Query(parameters.AuthorFirstNames)
), mu => mu
.Match(m => m
.Field(f => f.Authors.Suffix(nameof(Author.LastName))).Query(parameters.AuthorLastName)))))));
}

if (!string.IsNullOrWhiteSpace(parameters.ConferenceName))
Expand Down
1 change: 1 addition & 0 deletions aspnetcore/src/Service.Models/Publication/Publication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Publication
/// <summary>
/// Tekijät
/// </summary>
[Nested]
public List<Author>? Authors { get; set; }

/// <summary>
Expand Down

0 comments on commit 9ae78d1

Please sign in to comment.