Skip to content

Commit

Permalink
SearchHelper uses GetResults method to get typed results
Browse files Browse the repository at this point in the history
  • Loading branch information
callumbwhyte committed Mar 14, 2021
1 parent 3eb1afb commit 0e64be6
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/Our.Umbraco.Extensions.Search/Helpers/SearchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
using Examine;
using Examine.Search;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;

namespace Our.Umbraco.Extensions.Search.Helpers
{
public class SearchHelper
{
private readonly IExamineManager _examineManager;
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;

public SearchHelper(IExamineManager examineManager, IPublishedSnapshotAccessor publishedSnapshotAccessor)
public SearchHelper(IExamineManager examineManager)
{
_examineManager = examineManager;
_publishedSnapshotAccessor = publishedSnapshotAccessor;
}

/// <summary>
Expand Down Expand Up @@ -51,10 +47,7 @@ public IEnumerable<T> Search<T>(IBooleanOperation query, out int totalResults)

totalResults = (int)searchResult.TotalItemCount;

var typedResult = searchResult
.ToPublishedSearchResults(_publishedSnapshotAccessor.PublishedSnapshot.Content)
.Select(x => x.Content as T)
.Where(x => x != null);
var typedResult = searchResult.GetResults<T>();

return typedResult;
}
Expand Down Expand Up @@ -83,9 +76,7 @@ public IEnumerable<T> Page<T>(IBooleanOperation query, int page, int perPage, ou

var pagedResult = searchResult
.Skip((page - 1) * perPage)
.ToPublishedSearchResults(_publishedSnapshotAccessor.PublishedSnapshot.Content)
.Select(x => x.Content as T)
.Where(x => x != null)
.GetResults<T>()
.Take(perPage);

return pagedResult;
Expand Down

0 comments on commit 0e64be6

Please sign in to comment.