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
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.add
_ReSharper*
*.suo
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
*ReSharper.user
TestResults/*
Examine.Web.Demo/App_Data/*
*.user
build/Releases/*
packages/*
11 changes: 10 additions & 1 deletion Projects/Examine/LuceneEngine/Providers/BaseLuceneSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ internal ISearchResults TextSearchAllFields(string searchText, bool useWildcards
/// <returns></returns>
[SecuritySafeCritical]
public override ISearchResults Search(ISearchCriteria searchParams)
{
return Search(searchParams, 0);
}

/// <summary>
/// Performs a search with a maximum number of results
/// </summary>
[SecuritySafeCritical]
public ISearchResults Search(ISearchCriteria searchParams, int maxResults)
{
var searcher = GetSearcher();

Expand All @@ -165,7 +174,7 @@ public override ISearchResults Search(ISearchCriteria searchParams)
if (luceneParams == null)
throw new ArgumentException("Provided ISearchCriteria dos not match the allowed ISearchCriteria. Ensure you only use an ISearchCriteria created from the current SearcherProvider");

var pagesResults = new SearchResults(luceneParams.Query, luceneParams.SortFields, searcher);
var pagesResults = new SearchResults(luceneParams.Query, luceneParams.SortFields, searcher, maxResults);
return pagesResults;
}

Expand Down
19 changes: 15 additions & 4 deletions Projects/Examine/LuceneEngine/SearchResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,20 @@ internal SearchResults(Query query, IEnumerable<SortField> sortField, Searcher s
LuceneQuery = query;

LuceneSearcher = searcher;
DoSearch(query, sortField);
DoSearch(query, sortField, 0);
}

[SecuritySafeCritical]
internal SearchResults(Query query, IEnumerable<SortField> sortField, Searcher searcher, int maxResults)
{
LuceneQuery = query;

LuceneSearcher = searcher;
DoSearch(query, sortField, maxResults);
}

[SecuritySafeCritical]
private void DoSearch(Query query, IEnumerable<SortField> sortField)
private void DoSearch(Query query, IEnumerable<SortField> sortField, int maxResults)
{
//This try catch is because analyzers strip out stop words and sometimes leave the query
//with null values. This simply tries to extract terms, if it fails with a null
Expand All @@ -85,15 +94,17 @@ private void DoSearch(Query query, IEnumerable<SortField> sortField)
//swallow this exception, we should continue if this occurs.
}

maxResults = maxResults > 1 ? maxResults : LuceneSearcher.MaxDoc();

if (sortField.Count() == 0)
{
var topDocs = LuceneSearcher.Search(query, null, LuceneSearcher.MaxDoc(), new Sort());
var topDocs = LuceneSearcher.Search(query, null, maxResults, new Sort());
_collector = new AllHitsCollector(topDocs.scoreDocs);
topDocs = null;
}
else
{
var topDocs = LuceneSearcher.Search(query, null, LuceneSearcher.MaxDoc(), new Sort(sortField.ToArray()));
var topDocs = LuceneSearcher.Search(query, null, maxResults, new Sort(sortField.ToArray()));
_collector = new AllHitsCollector(topDocs.scoreDocs);
topDocs = null;
}
Expand Down