From 16776dfad8e0ebfdd4acedc8a26eaf31c5bc4d28 Mon Sep 17 00:00:00 2001 From: Mike Goatly <4577868+mikegoatly@users.noreply.github.com> Date: Fri, 11 Feb 2022 22:47:14 +0000 Subject: [PATCH] Adjacent words: prevent the same token matching with itself (#44) --- azure-pipelines.yml | 2 +- src/Lifti.Core/Lifti.Core.csproj | 1 - src/Lifti.Core/Querying/IntegerExtensions.cs | 2 +- .../AdjacentWordsQueryOperatorTests.cs | 17 +++++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1088c8c6..f3fbae4d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,7 +10,7 @@ trigger: variables: majorVersion: 3 minorVersion: 0 - patchVersion: 0 + patchVersion: 1 project: src/Lifti.Core/Lifti.Core.csproj testProject: test/Lifti.Tests/Lifti.Tests.csproj buildConfiguration: 'Release' diff --git a/src/Lifti.Core/Lifti.Core.csproj b/src/Lifti.Core/Lifti.Core.csproj index 7adcd343..00d70da4 100644 --- a/src/Lifti.Core/Lifti.Core.csproj +++ b/src/Lifti.Core/Lifti.Core.csproj @@ -15,7 +15,6 @@ Lifti.Core Mike Goatly - First version of the new rewrite Lifti.Core 8.0 enable diff --git a/src/Lifti.Core/Querying/IntegerExtensions.cs b/src/Lifti.Core/Querying/IntegerExtensions.cs index 6046b2eb..9bb35678 100644 --- a/src/Lifti.Core/Querying/IntegerExtensions.cs +++ b/src/Lifti.Core/Querying/IntegerExtensions.cs @@ -4,7 +4,7 @@ internal static class IntegerExtensions { internal static bool IsPositiveAndLessThanOrEqualTo(this int value, int target) { - return value >= 0 && value <= target; + return value > 0 && value <= target; } } } diff --git a/test/Lifti.Tests/Querying/QueryParts/AdjacentWordsQueryOperatorTests.cs b/test/Lifti.Tests/Querying/QueryParts/AdjacentWordsQueryOperatorTests.cs index 2c6df1f2..d8028f6c 100644 --- a/test/Lifti.Tests/Querying/QueryParts/AdjacentWordsQueryOperatorTests.cs +++ b/test/Lifti.Tests/Querying/QueryParts/AdjacentWordsQueryOperatorTests.cs @@ -44,5 +44,22 @@ public void ShouldOnlyReturnMatchesForAppropriateField() }, config => config.AllowingInfiniteRecursion()); } + + [Fact] + public void ShouldNotCombineSameTokensTogether() + { + var sut = new AdjacentWordsQueryOperator( + new[] { + new FakeQueryPart( + ScoredToken(7, ScoredFieldMatch(1D, 1, 8, 20, 100))), + new FakeQueryPart( + ScoredToken(7, ScoredFieldMatch(1D, 1, 8, 20, 100))) + }); + + var results = sut.Evaluate(() => new FakeIndexNavigator(), QueryContext.Empty); + + // The first and second query parts should not combine together + results.Matches.Should().BeEmpty(); + } } }