Files
Umbraco-CMS/src/Umbraco.Web/DynamicDocumentSearchExtensions.cs
Shannon Deminick 1566b16f0f Migrated most of the functionality from RazorLibraryCore to UmbracoHelper and updated RazorLibraryCore to call
the methods in UmbracoHelper so we only have to maintain one set of code. Didn't port over the Wrap methods because
I need feedback on these as to what they do/are supposed to do.
Added the Media methods to UmbracoHelper using the media store stuff.
2012-09-14 09:09:23 +07:00

60 lines
2.2 KiB
C#

using Examine.LuceneEngine.SearchCriteria;
using Umbraco.Core.Dynamics;
namespace Umbraco.Web
{
/// <summary>
/// DynamicDocument extension methods for searching using Examine
/// </summary>
public static class DynamicDocumentSearchExtensions
{
public static DynamicDocumentList Search(this DynamicDocument 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 DynamicDocumentList SearchDescendants(this DynamicDocument d, string term, bool useWildCards = true, string searchProvider = null)
{
return d.Search(term, useWildCards, searchProvider);
}
public static DynamicDocumentList SearchChildren(this DynamicDocument 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 DynamicDocumentList Search(this DynamicDocument 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);
}
}
}