Added TypedSearch methods to UmbracoHelper and Search extension methods to the IPublishedContent.
Added GetTemplateAlias() extension method to IPublishedContent and to DynamicPublishedContent.
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
using Examine.LuceneEngine.SearchCriteria;
|
||||
using Umbraco.Core.Dynamics;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Models;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// DynamicPublishedContent extension methods for searching using Examine
|
||||
/// </summary>
|
||||
public static class DynamicPublishedContentSearchExtensions
|
||||
{
|
||||
public static DynamicPublishedContentList Search(this DynamicPublishedContent d, string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
var searcher = Examine.ExamineManager.Instance.DefaultSearchProvider;
|
||||
if (!string.IsNullOrEmpty(searchProvider))
|
||||
searcher = Examine.ExamineManager.Instance.SearchProviderCollection[searchProvider];
|
||||
|
||||
var t = term.Escape().Value;
|
||||
if (useWildCards)
|
||||
t = term.MultipleCharacterWildcard().Value;
|
||||
|
||||
string luceneQuery = "+__Path:(" + d.Path.Replace("-", "\\-") + "*) +" + t;
|
||||
var crit = searcher.CreateSearchCriteria().RawQuery(luceneQuery);
|
||||
|
||||
return d.Search(crit, searcher);
|
||||
}
|
||||
|
||||
public static DynamicPublishedContentList SearchDescendants(this DynamicPublishedContent d, string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
return d.Search(term, useWildCards, searchProvider);
|
||||
}
|
||||
|
||||
public static DynamicPublishedContentList SearchChildren(this DynamicPublishedContent d, string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
var searcher = Examine.ExamineManager.Instance.DefaultSearchProvider;
|
||||
if (!string.IsNullOrEmpty(searchProvider))
|
||||
searcher = Examine.ExamineManager.Instance.SearchProviderCollection[searchProvider];
|
||||
|
||||
var t = term.Escape().Value;
|
||||
if (useWildCards)
|
||||
t = term.MultipleCharacterWildcard().Value;
|
||||
|
||||
string luceneQuery = "+parentID:" + d.Id.ToString() + " +" + t;
|
||||
var crit = searcher.CreateSearchCriteria().RawQuery(luceneQuery);
|
||||
|
||||
return d.Search(crit, searcher);
|
||||
}
|
||||
|
||||
public static DynamicPublishedContentList Search(this DynamicPublishedContent d, Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null)
|
||||
{
|
||||
var s = Examine.ExamineManager.Instance.DefaultSearchProvider;
|
||||
if (searchProvider != null)
|
||||
s = searchProvider;
|
||||
|
||||
var results = s.Search(criteria);
|
||||
return results.ConvertSearchResultToDynamicDocument(PublishedContentStoreResolver.Current.PublishedContentStore);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
internal static class ExamineExtensions
|
||||
{
|
||||
internal static DynamicPublishedContentList ConvertSearchResultToDynamicDocument(
|
||||
internal static IEnumerable<IPublishedContent> ConvertSearchResultToPublishedContent(
|
||||
this IEnumerable<SearchResult> results,
|
||||
IPublishedStore store)
|
||||
{
|
||||
@@ -22,9 +22,8 @@ namespace Umbraco.Web
|
||||
// however thsi is currently not the case:
|
||||
// http://examine.codeplex.com/workitem/10350
|
||||
|
||||
var list = new DynamicPublishedContentList();
|
||||
var xd = new XmlDocument();
|
||||
|
||||
var list = new List<IPublishedContent>();
|
||||
|
||||
foreach (var result in results.OrderByDescending(x => x.Score))
|
||||
{
|
||||
var doc = store.GetDocumentById(
|
||||
@@ -32,9 +31,8 @@ namespace Umbraco.Web
|
||||
result.Id);
|
||||
if (doc == null) continue; //skip if this doesn't exist in the cache
|
||||
doc.Properties.Add(
|
||||
new PropertyResult("examineScore", result.Score.ToString(), Guid.Empty, PropertyResultType.CustomProperty));
|
||||
var dynamicDoc = new DynamicPublishedContent(doc);
|
||||
list.Add(dynamicDoc);
|
||||
new PropertyResult("examineScore", result.Score.ToString(), Guid.Empty, PropertyResultType.CustomProperty));
|
||||
list.Add(doc);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -624,6 +624,39 @@ namespace Umbraco.Web.Models
|
||||
}
|
||||
#endregion
|
||||
|
||||
public string GetTemplateAlias()
|
||||
{
|
||||
return PublishedContentExtensions.GetTemplateAlias(this);
|
||||
}
|
||||
|
||||
#region Search
|
||||
|
||||
public DynamicPublishedContentList Search(string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
return new DynamicPublishedContentList(
|
||||
PublishedContentExtensions.Search(this, term, useWildCards, searchProvider));
|
||||
}
|
||||
|
||||
public DynamicPublishedContentList SearchDescendants(string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
return new DynamicPublishedContentList(
|
||||
PublishedContentExtensions.SearchDescendants(this, term, useWildCards, searchProvider));
|
||||
}
|
||||
|
||||
public DynamicPublishedContentList SearchChildren(string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
return new DynamicPublishedContentList(
|
||||
PublishedContentExtensions.SearchChildren(this, term, useWildCards, searchProvider));
|
||||
}
|
||||
|
||||
public DynamicPublishedContentList Search(Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null)
|
||||
{
|
||||
return new DynamicPublishedContentList(
|
||||
PublishedContentExtensions.Search(this, criteria, searchProvider));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetProperty methods which can be used with the dynamic object
|
||||
|
||||
public IPublishedContentProperty GetProperty(string alias)
|
||||
|
||||
@@ -3,10 +3,12 @@ using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Examine.LuceneEngine.SearchCriteria;
|
||||
using Umbraco.Core.Dynamics;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Routing;
|
||||
using umbraco;
|
||||
using umbraco.cms.businesslogic;
|
||||
using Umbraco.Core;
|
||||
|
||||
@@ -21,6 +23,65 @@ namespace Umbraco.Web
|
||||
/// </remarks>
|
||||
public static class PublishedContentExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the current template Alias
|
||||
/// </summary>
|
||||
/// <param name="doc"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetTemplateAlias(this IPublishedContent doc)
|
||||
{
|
||||
var template = new template(doc.TemplateId);
|
||||
return template.TemplateAlias;
|
||||
}
|
||||
|
||||
#region Search
|
||||
public static IEnumerable<IPublishedContent> Search(this IPublishedContent d, string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
var searcher = Examine.ExamineManager.Instance.DefaultSearchProvider;
|
||||
if (!string.IsNullOrEmpty(searchProvider))
|
||||
searcher = Examine.ExamineManager.Instance.SearchProviderCollection[searchProvider];
|
||||
|
||||
var t = term.Escape().Value;
|
||||
if (useWildCards)
|
||||
t = term.MultipleCharacterWildcard().Value;
|
||||
|
||||
string luceneQuery = "+__Path:(" + d.Path.Replace("-", "\\-") + "*) +" + t;
|
||||
var crit = searcher.CreateSearchCriteria().RawQuery(luceneQuery);
|
||||
|
||||
return d.Search(crit, searcher);
|
||||
}
|
||||
|
||||
public static IEnumerable<IPublishedContent> SearchDescendants(this IPublishedContent d, string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
return d.Search(term, useWildCards, searchProvider);
|
||||
}
|
||||
|
||||
public static IEnumerable<IPublishedContent> SearchChildren(this IPublishedContent d, string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
var searcher = Examine.ExamineManager.Instance.DefaultSearchProvider;
|
||||
if (!string.IsNullOrEmpty(searchProvider))
|
||||
searcher = Examine.ExamineManager.Instance.SearchProviderCollection[searchProvider];
|
||||
|
||||
var t = term.Escape().Value;
|
||||
if (useWildCards)
|
||||
t = term.MultipleCharacterWildcard().Value;
|
||||
|
||||
string luceneQuery = "+parentID:" + d.Id.ToString() + " +" + t;
|
||||
var crit = searcher.CreateSearchCriteria().RawQuery(luceneQuery);
|
||||
|
||||
return d.Search(crit, searcher);
|
||||
}
|
||||
|
||||
public static IEnumerable<IPublishedContent> Search(this IPublishedContent d, Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null)
|
||||
{
|
||||
var s = Examine.ExamineManager.Instance.DefaultSearchProvider;
|
||||
if (searchProvider != null)
|
||||
s = searchProvider;
|
||||
|
||||
var results = s.Search(criteria);
|
||||
return results.ConvertSearchResultToPublishedContent(PublishedContentStoreResolver.Current.PublishedContentStore);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region List Extensions
|
||||
|
||||
|
||||
@@ -266,7 +266,6 @@
|
||||
<Compile Include="Dictionary\UmbracoCultureDictionary.cs" />
|
||||
<Compile Include="Dictionary\UmbracoCultureDictionaryFactory.cs" />
|
||||
<Compile Include="PublishedContentExtensions.cs" />
|
||||
<Compile Include="DynamicPublishedContentSearchExtensions.cs" />
|
||||
<Compile Include="ExamineExtensions.cs" />
|
||||
<Compile Include="FormlessPage.cs">
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
|
||||
@@ -547,12 +547,8 @@ namespace Umbraco.Web
|
||||
/// <returns></returns>
|
||||
public dynamic Search(string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
var searcher = Examine.ExamineManager.Instance.DefaultSearchProvider;
|
||||
if (!string.IsNullOrEmpty(searchProvider))
|
||||
searcher = Examine.ExamineManager.Instance.SearchProviderCollection[searchProvider];
|
||||
|
||||
var results = searcher.Search(term, useWildCards);
|
||||
return results.ConvertSearchResultToDynamicDocument(PublishedContentStoreResolver.Current.PublishedContentStore);
|
||||
return new DynamicPublishedContentList(
|
||||
TypedSearch(term, useWildCards, searchProvider));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -562,13 +558,42 @@ namespace Umbraco.Web
|
||||
/// <param name="searchProvider"></param>
|
||||
/// <returns></returns>
|
||||
public dynamic Search(Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null)
|
||||
{
|
||||
return new DynamicPublishedContentList(
|
||||
TypedSearch(criteria, searchProvider));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches content
|
||||
/// </summary>
|
||||
/// <param name="term"></param>
|
||||
/// <param name="useWildCards"></param>
|
||||
/// <param name="searchProvider"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<IPublishedContent> TypedSearch(string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
var searcher = Examine.ExamineManager.Instance.DefaultSearchProvider;
|
||||
if (!string.IsNullOrEmpty(searchProvider))
|
||||
searcher = Examine.ExamineManager.Instance.SearchProviderCollection[searchProvider];
|
||||
|
||||
var results = searcher.Search(term, useWildCards);
|
||||
return results.ConvertSearchResultToPublishedContent(PublishedContentStoreResolver.Current.PublishedContentStore);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searhes content
|
||||
/// </summary>
|
||||
/// <param name="criteria"></param>
|
||||
/// <param name="searchProvider"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<IPublishedContent> TypedSearch(Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null)
|
||||
{
|
||||
var s = Examine.ExamineManager.Instance.DefaultSearchProvider;
|
||||
if (searchProvider != null)
|
||||
s = searchProvider;
|
||||
|
||||
var results = s.Search(criteria);
|
||||
return results.ConvertSearchResultToDynamicDocument(PublishedContentStoreResolver.Current.PublishedContentStore);
|
||||
return results.ConvertSearchResultToPublishedContent(PublishedContentStoreResolver.Current.PublishedContentStore);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user