2017-07-20 11:21:28 +02:00
|
|
|
|
using System.Collections.Generic;
|
2012-09-14 09:09:23 +07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Examine;
|
2017-07-21 17:04:14 +02:00
|
|
|
|
using Umbraco.Core;
|
2013-09-05 17:47:13 +02:00
|
|
|
|
using Umbraco.Core.Models.PublishedContent;
|
2013-02-05 06:31:13 -01:00
|
|
|
|
using Umbraco.Web.PublishedCache;
|
2012-09-14 09:09:23 +07:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web
|
|
|
|
|
|
{
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Extension methods for Examine
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static class ExamineExtensions
|
|
|
|
|
|
{
|
2017-07-21 17:04:14 +02:00
|
|
|
|
public static IEnumerable<PublishedSearchResult> ToPublishedSearchResults(this IEnumerable<SearchResult> results, IPublishedCache cache)
|
2017-07-20 11:21:28 +02:00
|
|
|
|
{
|
2017-07-21 17:04:14 +02:00
|
|
|
|
var list = new List<PublishedSearchResult>();
|
2016-05-26 17:12:04 +02:00
|
|
|
|
|
2017-07-20 11:21:28 +02:00
|
|
|
|
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
|
2013-09-05 17:47:13 +02:00
|
|
|
|
|
2017-07-21 17:04:14 +02:00
|
|
|
|
list.Add(new PublishedSearchResult(content, result.Score));
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|
2013-09-05 17:47:13 +02:00
|
|
|
|
|
2016-06-09 20:13:20 +02:00
|
|
|
|
return list;
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|