Skip to content

Commit

Permalink
.gitignore file and an overload for Search in BaseLuceneSearcher
Browse files Browse the repository at this point in the history
Added a new .gitignore file, tried to match the old .hgignore but
updated the syntax. Added an overload for Search in the
BaseLuceneSearcher to take a maxResults parameter to limit the number of
results returned from Lucene.
  • Loading branch information
sniffdk committed Jul 8, 2013
1 parent 63d2961 commit faaa9e5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
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

0 comments on commit faaa9e5

Please sign in to comment.