Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class LexEntryFilterMapProvider : EntryFilterMapProvider<ILexEntry>
// ReSharper disable once ConvertClosureToMethodGroup
.Select(domain => LcmHelpers.GetSemanticDomainCode(domain));
public override Func<string, object>? EntrySensesSemanticDomainsConverter => EntryFilter.NormalizeEmptyToNullString<ICmSemanticDomain>;
public override Expression<Func<ILexEntry, object?>> EntrySensesExampleSentences => e => EmptyToNull(e.AllSenses.SelectMany(s => s.ExamplesOS));
public override Expression<Func<ILexEntry, object?>> EntrySensesExampleSentences => e => e.AllSenses.Select(s => EmptyToNull(s.ExamplesOS));
public override Expression<Func<ILexEntry, string, object?>> EntrySensesExampleSentencesSentence => (entry, ws) =>
entry.AllSenses.SelectMany(s => s.ExamplesOS).Select(example => example.PickText(example.Example, ws));

Expand Down
2 changes: 1 addition & 1 deletion backend/FwLite/LcmCrdt/EntryFilterMapProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class EntryFilterMapProvider : EntryFilterMapProvider<Entry>
public override Func<string, object>? EntrySensesSemanticDomainsConverter =>
//linq2db treats Sense.SemanticDomains as a table, if we use "null" then it'll write the query we want
EntryFilter.NormalizeEmptyToNullString<SemanticDomain>;
public override Expression<Func<Entry, object?>> EntrySensesExampleSentences => e => e.Senses.SelectMany(s => s.ExampleSentences);
public override Expression<Func<Entry, object?>> EntrySensesExampleSentences => e => e.Senses.Select(s => s.ExampleSentences);
public override Expression<Func<Entry, string, object?>> EntrySensesExampleSentencesSentence =>
(e, ws) => e.Senses.SelectMany(s => s.ExampleSentences).Select(example => Json.Value(example.Sentence, ms => ms[ws]));
public override Expression<Func<Entry, object?>> EntrySensesPartOfSpeechId => e => e.Senses.Select(s => s.PartOfSpeechId);
Expand Down
42 changes: 37 additions & 5 deletions backend/FwLite/MiniLcm.Tests/QueryEntryTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public abstract class QueryEntryTestsBase : MiniLcmTestBase
private readonly string Apple = "Apple";
private readonly string Peach = "Peach";
private readonly string Banana = "Banana";
private readonly string Kiwi = "Kiwi";

public override async Task InitializeAsync()
{
Expand Down Expand Up @@ -59,6 +60,27 @@ await Api.CreateEntry(new Entry()
}
]
});
await Api.CreateEntry(new Entry()
{
LexemeForm = { { "en", Kiwi } },
Senses =
[
new()
{
Gloss = { { "en", "Fruit" } },
Definition = { { "en", "Fruit, fuzzy with green flesh" } },
PartOfSpeechId = nounPos.Id,
SemanticDomains = [semanticDomain],
ExampleSentences =
[
new ExampleSentence()
{
Sentence = { { "en", "I like eating Kiwis, they taste good" } }
},
]
}
]
});
}

[Fact]
Expand All @@ -68,18 +90,28 @@ public async Task CanFilterToMissingSenses()
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple);
}

[Fact]
public async Task CanFilterToNotMissingSenses()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses!=null" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Kiwi, Peach, Banana);
}

[Fact]
public async Task CanFilterToMissingPartOfSpeech()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.PartOfSpeechId=null" })).ToArrayAsync();
//does not include entries with no senses
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Peach);
}

[Fact]
public async Task CanFilterToMissingExamples()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.ExampleSentences=null" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo([Apple, Peach]);
//Senses.ExampleSentences=null matches entries which have senses but no examples
//it does not include Apple because it has no senses, to include it a filter Senses=null is needed
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Peach, Banana);
}

[Fact]
Expand All @@ -100,21 +132,21 @@ public async Task CanFilterToMissingSemanticDomainsWithEmptyArray()
public async Task CanFilterSemanticDomainCodeContains()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.SemanticDomains.Code=*Fruit" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Banana);
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Banana, Kiwi);
}

[Fact]
public async Task CanFilterToMissingComplexFormTypes()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "ComplexFormTypes=null" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple, Banana);
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple, Banana, Kiwi);
}

[Fact]
public async Task CanFilterToMissingComplexFormTypesWithEmptyArray()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "ComplexFormTypes=[]" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple, Banana);
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple, Banana, Kiwi);
}

[Fact]
Expand Down Expand Up @@ -163,7 +195,7 @@ public async Task CanFilterGlossEmpty()
public async Task CanFilterGlossEqualsFruit()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.Gloss[en]=Fruit" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Banana);
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Banana, Kiwi);
}

[Fact]
Expand Down
Loading