Skip to content

Commit

Permalink
Merge pull request #255 from matthewcare/fix-paging
Browse files Browse the repository at this point in the history
Fix paging when Skip == 1
  • Loading branch information
Shazwazza authored Oct 20, 2021
2 parents 7042580 + d35efda commit e02ab46
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Examine.Lucene/Search/LuceneSearchExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ISearchResults Execute()
}
}

var maxResults = Math.Min((_options.Skip == 0 ? 1 : _options.Skip) * _options.Take, MaxDoc);
var maxResults = Math.Min((_options.Skip + 1) * _options.Take, MaxDoc);
maxResults = maxResults >= 1 ? maxResults : QueryOptions.DefaultMaxResults;

ICollector topDocsCollector;
Expand Down
40 changes: 40 additions & 0 deletions src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2427,5 +2427,45 @@ public void Paging_With_Skip_Take()
Assert.AreEqual(0, results.Count);
}
}

[TestCase(0, 1, 1)]
[TestCase(0, 2, 2)]
[TestCase(0, 3, 3)]
[TestCase(0, 4, 4)]
[TestCase(0, 5, 5)]
[TestCase(0, 100, 5)]
[TestCase(1, 1, 1)]
[TestCase(1, 2, 2)]
[TestCase(1, 3, 3)]
[TestCase(1, 4, 4)]
[TestCase(1, 5, 4)]
[TestCase(2, 2, 2)]
[TestCase(2, 5, 3)]
public void Given_SkipTake_Returns_ExpectedTotals(int skip, int take, int expectedResults)
{
const int indexSize = 5;
var analyzer = new StandardAnalyzer(LuceneInfo.CurrentVersion);
using (var luceneDir = new RandomIdRAMDirectory())
using (var indexer = GetTestIndex(luceneDir, analyzer))
{
var items = Enumerable.Range(0, indexSize).Select(x => ValueSet.FromObject(x.ToString(), "content",
new { nodeName = "umbraco", headerText = "world", writerName = "administrator" }));

indexer.IndexItems(items);

var searcher = indexer.Searcher;

//Arrange

var sc = searcher.CreateQuery("content").Field("writerName", "administrator");

//Act

var results = sc.Execute(QueryOptions.SkipTake(skip, take));

Assert.AreEqual(indexSize, results.TotalItemCount);
Assert.AreEqual(expectedResults, results.Count());
}
}
}
}

0 comments on commit e02ab46

Please sign in to comment.