From a3e4eaa2e41fe02da206cb5f2a4614baf11d15e8 Mon Sep 17 00:00:00 2001 From: perploug Date: Thu, 10 Oct 2013 08:51:55 +0200 Subject: [PATCH] membersearch support --- src/Umbraco.Web/Editors/EntityController.cs | 39 ++++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs index a3e39692f3..8ac97bdf08 100644 --- a/src/Umbraco.Web/Editors/EntityController.cs +++ b/src/Umbraco.Web/Editors/EntityController.cs @@ -39,15 +39,18 @@ namespace Umbraco.Web.Editors if (string.IsNullOrEmpty(query)) return null; + return ExamineSearch(query, type); + + /* switch (type) { case UmbracoEntityTypes.Document: - return ExamineSearch(query, true); + case UmbracoEntityTypes.Media: - return ExamineSearch(query, false); + return ExamineSearch(query, UmbracoEntityType); default: throw new NotSupportedException("The " + typeof(EntityController) + " currently does not support searching against object type " + type); - } + }*/ } /// @@ -92,14 +95,32 @@ namespace Umbraco.Web.Editors return GetResultForAll(type, postFilter, postFilterParams); } - private IEnumerable ExamineSearch(string query, bool isContent) + private IEnumerable ExamineSearch(string query, UmbracoEntityTypes entityType) { - //TODO: WE should really just allow passing in a lucene raw query - - var internalSearcher = ExamineManager.Instance.SearchProviderCollection[Constants.Examine.InternalSearcher]; - var criteria = internalSearcher.CreateSearchCriteria(isContent ? "content" : "media", BooleanOperation.Or); + var searcher = Constants.Examine.InternalSearcher; + var type = "content"; var fields = new[] { "id", "__nodeName", "bodyText" }; + //TODO: WE should really just allow passing in a lucene raw query + switch (entityType) + { + case UmbracoEntityTypes.Member: + searcher = Constants.Examine.InternalMemberSearcher; + type = "member"; + break; + case UmbracoEntityTypes.Media: + type = "media"; + break; + case UmbracoEntityTypes.Document: + break; + default: + throw new NotSupportedException("The " + typeof(EntityController) + " currently does not support searching against object type " + entityType); + + } + + var internalSearcher = ExamineManager.Instance.SearchProviderCollection[searcher]; + var criteria = internalSearcher.CreateSearchCriteria(type, BooleanOperation.Or); + var term = new[] { query.ToLower().Escape() }; var operation = criteria.GroupedOr(fields, term).Compile(); @@ -108,7 +129,7 @@ namespace Umbraco.Web.Editors //TODO: Just create a basic entity from the results!! why double handling and going to the database... this will be ultra slow. - return GetResultForIds(results.ToArray(), isContent ? UmbracoEntityTypes.Document : UmbracoEntityTypes.Media) + return GetResultForIds(results.ToArray(), entityType) .WhereNotNull(); }