mirror of
https://github.com/Biarity/Sieve.git
synced 2024-12-04 19:16:24 +01:00
Fix issue where the order of Filter expressions changed the result.
The following filter criteria should result in the same output, but does not: "CategoryId==1,(CategoryId|LikeCount)==50" "(CategoryId|LikeCount)==50,CategoryId==1" Cause is an optimization which removes or statements if one term was already added in another statement. This optimization causes a wrong result.
This commit is contained in:
parent
d86e35f77c
commit
4cac27c22d
@ -44,11 +44,8 @@ namespace Sieve.Models
|
|||||||
{
|
{
|
||||||
Filter = subfilters + filterOpAndVal
|
Filter = subfilters + filterOpAndVal
|
||||||
};
|
};
|
||||||
if (!value.Any(f => f.Names.Any(n => filterTerm.Names.Any(n2 => n2 == n))))
|
|
||||||
{
|
|
||||||
value.Add(filterTerm);
|
value.Add(filterTerm);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var filterTerm = new TFilterTerm
|
var filterTerm = new TFilterTerm
|
||||||
|
@ -352,6 +352,24 @@ namespace SieveUnitTests
|
|||||||
Assert.AreEqual(3, entry.Id);
|
Assert.AreEqual(3, entry.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DataTestMethod]
|
||||||
|
[DataRow("CategoryId==1,(CategoryId|LikeCount)==50")]
|
||||||
|
[DataRow("(CategoryId|LikeCount)==50,CategoryId==1")]
|
||||||
|
public void CombinedAndOrFilterIndependentOfOrder(string filter)
|
||||||
|
{
|
||||||
|
var model = new SieveModel()
|
||||||
|
{
|
||||||
|
Filters = filter,
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = _processor.Apply(model, _posts);
|
||||||
|
var entry = result.FirstOrDefault();
|
||||||
|
var resultCount = result.Count();
|
||||||
|
|
||||||
|
Assert.IsNotNull(entry);
|
||||||
|
Assert.AreEqual(1, resultCount);
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void OrValueFilteringWorks()
|
public void OrValueFilteringWorks()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user