2012-09-14 09:09:23 +07:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Examine;
|
|
|
|
|
using Umbraco.Core.Dynamics;
|
2012-10-04 01:31:08 +05:00
|
|
|
using Umbraco.Core.Models;
|
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
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Extension methods for Examine
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal static class ExamineExtensions
|
|
|
|
|
{
|
2013-09-05 17:47:13 +02:00
|
|
|
internal static PublishedContentSet<IPublishedContent> ConvertSearchResultToPublishedContent(this IEnumerable<SearchResult> results,
|
2013-03-19 17:51:55 -01:00
|
|
|
ContextualPublishedCache cache)
|
2012-09-14 09:09:23 +07:00
|
|
|
{
|
2012-10-02 01:35:39 +05:00
|
|
|
//TODO: The search result has already returned a result which SHOULD include all of the data to create an IPublishedContent,
|
2013-09-05 17:47:13 +02:00
|
|
|
// however this is currently not the case:
|
2012-09-20 07:13:45 +07:00
|
|
|
// http://examine.codeplex.com/workitem/10350
|
|
|
|
|
|
2013-09-05 17:47:13 +02:00
|
|
|
var list = new List<IPublishedContent>();
|
|
|
|
|
var set = new PublishedContentSet<IPublishedContent>(list);
|
2012-10-18 08:00:07 +05:00
|
|
|
|
2012-09-14 09:09:23 +07:00
|
|
|
foreach (var result in results.OrderByDescending(x => x.Score))
|
|
|
|
|
{
|
2013-09-05 17:47:13 +02:00
|
|
|
var content = cache.GetById(result.Id);
|
|
|
|
|
if (content == null) continue; // skip if this doesn't exist in the cache
|
|
|
|
|
|
|
|
|
|
// need to extend the content as we're going to add a property to it,
|
|
|
|
|
// and we should not ever do it to the content we get from the cache,
|
|
|
|
|
// precisely because it is cached and shared by all requests.
|
|
|
|
|
|
|
|
|
|
// but we cannot wrap it because we need to respect the type that was
|
|
|
|
|
// returned by the cache, in case the cache can create real types.
|
|
|
|
|
// so we have to ask it to please extend itself.
|
|
|
|
|
|
|
|
|
|
list.Add(content);
|
|
|
|
|
var extend = set.MapContent(content);
|
|
|
|
|
|
|
|
|
|
var property = new PropertyResult("examineScore",
|
2013-09-23 21:57:22 +02:00
|
|
|
result.Score,
|
2013-09-05 17:47:13 +02:00
|
|
|
PropertyResultType.CustomProperty);
|
|
|
|
|
extend.AddProperty(property);
|
2012-09-14 09:09:23 +07:00
|
|
|
}
|
2013-09-05 17:47:13 +02:00
|
|
|
|
|
|
|
|
return set;
|
2012-09-14 09:09:23 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|