Skip to content

Commit

Permalink
Full support for Skip and Take
Browse files Browse the repository at this point in the history
  • Loading branch information
mentordigital committed Mar 24, 2020
1 parent 8dc4c07 commit e01e4f2
Show file tree
Hide file tree
Showing 13 changed files with 1,067 additions and 27 deletions.
1,035 changes: 1,035 additions & 0 deletions .vs/Umbraco.Examine.Linq/config/applicationhost.config

Large diffs are not rendered by default.

Binary file added LINQToExamine.1.5.nupkg
Binary file not shown.
2 changes: 1 addition & 1 deletion LINQToExamine.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>LINQToExamine</id>
<title>Linq To Examine for Umbraco</title>
<version>1.4</version>
<version>1.5</version>
<authors>Craig Noble</authors>
<description>This project allows you to query the Lucene indexes using LINQ based on your own classes.</description>
<language>en-US</language>
Expand Down
Binary file modified Umbraco.Examine.Linq.Sandbox/App_Data/Umbraco.sdf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
<LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
Expand Down
2 changes: 1 addition & 1 deletion Umbraco.Examine.Linq.Tests/TestSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Umbraco.Examine.Linq.Tests
public class TestSearcher : ISearcher
{

public IEnumerable<SearchResult> Search(string query)
public IEnumerable<SearchResult> Search(string query, int skip, int take)
{
return new List<SearchResult>();
}
Expand Down
2 changes: 1 addition & 1 deletion Umbraco.Examine.Linq.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void DoSomething()
var results = index.Where(r =>
!(r.Name.Contains("content page")).Fuzzy(0.2).Boost(10)
&& !(r.Name.ContainsAll("something", "else", "hello").Boost(10) || r.Name != "home boo")
).ToList();
).Skip(2).Take(20).ToList();

//IEnumerable<Result> results = (from r in index.AsQueryable()
// where r.Name.Contains("boo").Boost(10)
Expand Down
20 changes: 11 additions & 9 deletions Umbraco.Examine.Linq.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.352
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Examine.Linq", "Umbraco.Examine.Linq\Umbraco.Examine.Linq.csproj", "{86684269-83FD-4A57-B916-676C1CC85D18}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Examine.Linq.Tests", "Umbraco.Examine.Linq.Tests\Umbraco.Examine.Linq.Tests.csproj", "{7855A894-081A-4926-A2C8-98FBA63EB3B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Examine.Linq.Sandbox", "Umbraco.Examine.Linq.Sandbox\Umbraco.Examine.Linq.Sandbox.csproj", "{FE8678AD-BA86-4BAA-8A47-213F66417CB8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blog", "Blog\Blog.csproj", "{A6B9EC27-BF4B-4F2B-81AE-329168F9A20A}"
Expand All @@ -15,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sandbox", "Sandbox", "{813E
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LinqToExamine", "LinqToExamine", "{5D0B072C-86A3-4287-939C-58D03B4E2066}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Examine.Linq.Tests", "Umbraco.Examine.Linq.Tests\Umbraco.Examine.Linq.Tests.csproj", "{7855A894-081A-4926-A2C8-98FBA63EB3B9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -25,10 +25,6 @@ Global
{86684269-83FD-4A57-B916-676C1CC85D18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86684269-83FD-4A57-B916-676C1CC85D18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86684269-83FD-4A57-B916-676C1CC85D18}.Release|Any CPU.Build.0 = Release|Any CPU
{7855A894-081A-4926-A2C8-98FBA63EB3B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7855A894-081A-4926-A2C8-98FBA63EB3B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7855A894-081A-4926-A2C8-98FBA63EB3B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7855A894-081A-4926-A2C8-98FBA63EB3B9}.Release|Any CPU.Build.0 = Release|Any CPU
{FE8678AD-BA86-4BAA-8A47-213F66417CB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE8678AD-BA86-4BAA-8A47-213F66417CB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE8678AD-BA86-4BAA-8A47-213F66417CB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -37,14 +33,20 @@ Global
{A6B9EC27-BF4B-4F2B-81AE-329168F9A20A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6B9EC27-BF4B-4F2B-81AE-329168F9A20A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6B9EC27-BF4B-4F2B-81AE-329168F9A20A}.Release|Any CPU.Build.0 = Release|Any CPU
{7855A894-081A-4926-A2C8-98FBA63EB3B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7855A894-081A-4926-A2C8-98FBA63EB3B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7855A894-081A-4926-A2C8-98FBA63EB3B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7855A894-081A-4926-A2C8-98FBA63EB3B9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{86684269-83FD-4A57-B916-676C1CC85D18} = {5D0B072C-86A3-4287-939C-58D03B4E2066}
{7855A894-081A-4926-A2C8-98FBA63EB3B9} = {5D0B072C-86A3-4287-939C-58D03B4E2066}
{FE8678AD-BA86-4BAA-8A47-213F66417CB8} = {813EF9E5-133C-4F5B-A346-F33044528036}
{A6B9EC27-BF4B-4F2B-81AE-329168F9A20A} = {813EF9E5-133C-4F5B-A346-F33044528036}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FB80EF34-FB4D-407A-89DD-A9867A26E8B6}
EndGlobalSection
EndGlobal
10 changes: 1 addition & 9 deletions Umbraco.Examine.Linq/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,7 @@ public IEnumerable<T> ExecuteCollection<T>(QueryModel queryModel)
{
var visitor = new QueryModelVisitor();
visitor.VisitQueryModel(queryModel);
var searchResults = Searcher.Search(string.Join(" AND ", visitor.queries));

if (visitor.skip != -1)
searchResults = searchResults.Skip(visitor.skip);

if (visitor.take != -1)
{
searchResults = searchResults.Take(visitor.take);
}
var searchResults = Searcher.Search(string.Join(" AND ", visitor.queries), visitor.skip, visitor.take);

return (IEnumerable<T>)Mapper.Map(searchResults);
}
Expand Down
2 changes: 1 addition & 1 deletion Umbraco.Examine.Linq/ISearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ namespace Umbraco.Examine.Linq
{
public interface ISearcher
{
IEnumerable<SearchResult> Search(string query);
IEnumerable<SearchResult> Search(string query, int skip, int take);
}
}
2 changes: 1 addition & 1 deletion Umbraco.Examine.Linq/QueryModelVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class QueryModelVisitor : QueryModelVisitorBase
{
public List<StringBuilder> queries = new List<StringBuilder>();
public int take = -1;
public int skip = -1;
public int skip = 0;

public override void VisitWhereClause(Remotion.Linq.Clauses.WhereClause whereClause, QueryModel queryModel, int index)
{
Expand Down
9 changes: 7 additions & 2 deletions Umbraco.Examine.Linq/SearchProviders/ExamineSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ public ExamineSearch(string indexName)
IndexName = indexName;
}

public IEnumerable<SearchResult> Search(string query)
public IEnumerable<SearchResult> Search(string query, int skip, int take)
{
ISearchCriteria criteria = null;
var searcher = ExamineManager.Instance.SearchProviderCollection[IndexName];


if (searchQueryCache.ContainsKey(query))
criteria = searchQueryCache[query];
Expand All @@ -40,7 +41,11 @@ public IEnumerable<SearchResult> Search(string query)
searchQueryCache.Add(query, criteria);
}

return searcher.Search(criteria);
var results = searcher.Search(criteria).Skip(skip);

if (take > -1)
results = results.Take(take);
return results.ToList();
}
}
}
9 changes: 7 additions & 2 deletions Umbraco.Examine.Linq/SearchProviders/LuceneSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ public LuceneSearch(string indexName)
IndexName = indexName;
}

public IEnumerable<SearchResult> Search(string query)
public IEnumerable<SearchResult> Search(string query, int skip, int take)
{
LuceneSearcher searcher = ExamineManager.Instance.SearchProviderCollection[IndexName] as LuceneSearcher;
return searcher.Search(searcher.CreateSearchCriteria().RawQuery(query)).ToList();

var results = searcher.Search(searcher.CreateSearchCriteria().RawQuery(query)).Skip(skip);

if (take > -1)
results = results.Take(take);
return results.ToList();
}
}
}

0 comments on commit e01e4f2

Please sign in to comment.