Skip to content

Commit

Permalink
Don't ever use MaxDocs, avoid a query and ensure that max docs used i…
Browse files Browse the repository at this point in the history
…s small enough
  • Loading branch information
Shazwazza committed Aug 21, 2024
1 parent 45849a1 commit 3760023
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 134 deletions.
2 changes: 2 additions & 0 deletions src/Examine.Core/Search/QueryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace Examine.Search
public class QueryOptions
{
public const int DefaultMaxResults = 500;

public static QueryOptions SkipTake(int skip, int? take = null) => new QueryOptions(skip, take ?? DefaultMaxResults);

public static QueryOptions Default { get; } = new QueryOptions(0, DefaultMaxResults);

public QueryOptions(int skip, int? take = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Examine.Lucene/LuceneIndexOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class LuceneIndexOptions : IndexOptions
{
public bool NrtEnabled { get; set; } = true;

public double NrtTargetMaxStaleSec { get; set; } = 5.0;
public double NrtTargetMaxStaleSec { get; set; } = 60.0;

public double NrtTargetMinStaleSec { get; set; } = 1.0;

Expand Down
2 changes: 2 additions & 0 deletions src/Examine.Lucene/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Examine.Lucene.Directories.SyncedFileSystemDirectoryFactory.SyncedFileSystemDirectoryFactory(System.IO.DirectoryInfo localDir, System.IO.DirectoryInfo mainDir, Examine.Lucene.Directories.ILockFactory lockFactory, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, bool tryFixMainIndexIfCorrupt) -> void
Examine.Lucene.LuceneIndexOptions.NrtEnabled.get -> bool
Examine.Lucene.LuceneIndexOptions.NrtEnabled.set -> void
Examine.Lucene.LuceneIndexOptions.NrtTargetMaxStaleSec.get -> double
Examine.Lucene.LuceneIndexOptions.NrtTargetMaxStaleSec.set -> void
Examine.Lucene.LuceneIndexOptions.NrtTargetMinStaleSec.get -> double
Expand Down
29 changes: 6 additions & 23 deletions src/Examine.Lucene/Search/LuceneSearchExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,6 @@ internal LuceneSearchExecutor(QueryOptions options, Query query, IEnumerable<Sor
_searchContext = searchContext ?? throw new ArgumentNullException(nameof(searchContext));
}

private int MaxDoc
{
get
{
return 100;
////if (_maxDoc == null)
////{
//// using (ISearcherReference searcher = _searchContext.GetSearcher())
//// {
//// // TODO: Getting the IndexSearcher here will call .Acquire() on the SearcherManager again
//// _maxDoc = searcher.IndexSearcher.IndexReader.MaxDoc;
//// }
////}
////return _maxDoc.Value;
}
}

public ISearchResults Execute()
{
var extractTermsSupported = CheckQueryForExtractTerms(_luceneQuery);
Expand Down Expand Up @@ -80,17 +63,17 @@ public ISearchResults Execute()
}
}

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

SortField[] sortFields = _sortField as SortField[] ?? _sortField.ToArray();
var sortFields = _sortField as SortField[] ?? _sortField.ToArray();
Sort sort = null;
FieldDoc scoreDocAfter = null;
Filter filter = null;

using (ISearcherReference searcher = _searchContext.GetSearcher())
using (var searcher = _searchContext.GetSearcher())
{
var maxResults = (_options.Skip + 1) * _options.Take;
maxResults = maxResults >= 1 ? maxResults : QueryOptions.DefaultMaxResults;
int numHits = maxResults;

if (sortFields.Length > 0)
{
sort = new Sort(sortFields);
Expand Down
Loading

0 comments on commit 3760023

Please sign in to comment.