diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..d88075d92 --- /dev/null +++ b/.gitignore @@ -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/* \ No newline at end of file diff --git a/Projects/Examine/LuceneEngine/Providers/BaseLuceneSearcher.cs b/Projects/Examine/LuceneEngine/Providers/BaseLuceneSearcher.cs index ccdfb3afe..cdef1fa6b 100644 --- a/Projects/Examine/LuceneEngine/Providers/BaseLuceneSearcher.cs +++ b/Projects/Examine/LuceneEngine/Providers/BaseLuceneSearcher.cs @@ -156,6 +156,15 @@ internal ISearchResults TextSearchAllFields(string searchText, bool useWildcards /// [SecuritySafeCritical] public override ISearchResults Search(ISearchCriteria searchParams) + { + return Search(searchParams, 0); + } + + /// + /// Performs a search with a maximum number of results + /// + [SecuritySafeCritical] + public ISearchResults Search(ISearchCriteria searchParams, int maxResults) { var searcher = GetSearcher(); @@ -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; } diff --git a/Projects/Examine/LuceneEngine/SearchResults.cs b/Projects/Examine/LuceneEngine/SearchResults.cs index 86e3d7ace..5c2297db0 100644 --- a/Projects/Examine/LuceneEngine/SearchResults.cs +++ b/Projects/Examine/LuceneEngine/SearchResults.cs @@ -56,11 +56,20 @@ internal SearchResults(Query query, IEnumerable sortField, Searcher s LuceneQuery = query; LuceneSearcher = searcher; - DoSearch(query, sortField); + DoSearch(query, sortField, 0); + } + + [SecuritySafeCritical] + internal SearchResults(Query query, IEnumerable sortField, Searcher searcher, int maxResults) + { + LuceneQuery = query; + + LuceneSearcher = searcher; + DoSearch(query, sortField, maxResults); } [SecuritySafeCritical] - private void DoSearch(Query query, IEnumerable sortField) + private void DoSearch(Query query, IEnumerable 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 @@ -85,15 +94,17 @@ private void DoSearch(Query query, IEnumerable 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; }