31 lines
932 B
C#
31 lines
932 B
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Examine;
|
|
using Umbraco.Core;
|
|
using Umbraco.Core.Models.PublishedContent;
|
|
using Umbraco.Web.PublishedCache;
|
|
|
|
namespace Umbraco.Web
|
|
{
|
|
/// <summary>
|
|
/// Extension methods for Examine
|
|
/// </summary>
|
|
public static class ExamineExtensions
|
|
{
|
|
public static IEnumerable<PublishedSearchResult> ToPublishedSearchResults(this IEnumerable<SearchResult> results, IPublishedCache cache)
|
|
{
|
|
var list = new List<PublishedSearchResult>();
|
|
|
|
foreach (var result in results.OrderByDescending(x => x.Score))
|
|
{
|
|
var content = cache.GetById(result.Id);
|
|
if (content == null) continue; // skip if this doesn't exist in the cache
|
|
|
|
list.Add(new PublishedSearchResult(content, result.Score));
|
|
}
|
|
|
|
return list;
|
|
}
|
|
}
|
|
}
|