From aca550a9b4e627998ddd4e99a660ec6ab79d5c7e Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 29 Oct 2013 16:00:15 +1100 Subject: [PATCH] Fixes search algorithm to have more accurate results --- src/Umbraco.Web/Editors/EntityController.cs | 29 ++++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs index c774e26c7e..c069fcbfb8 100644 --- a/src/Umbraco.Web/Editors/EntityController.cs +++ b/src/Umbraco.Web/Editors/EntityController.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Net; +using System.Text; using System.Web.Http; using System.Web.Http.Controllers; using System.Web.Http.ModelBinding; @@ -161,18 +162,26 @@ namespace Umbraco.Web.Editors } var internalSearcher = ExamineManager.Instance.SearchProviderCollection[searcher]; - var criteria = internalSearcher.CreateSearchCriteria(type, BooleanOperation.Or); - criteria - //search the special __nodeName specifically with lowercase since it is indexed lowercase - // - we are however by default using whitespace analyzer which doesn't care about casing anyways. - .Field("__nodeName", query.ToLower().MultipleCharacterWildcard()) - .Or() - //then just search the result of the fields specified. - .GroupedOr(fields, new[] { query.MultipleCharacterWildcard() }) - .Compile(); + //build a lucene query: + // the __nodeName will be boosted 10x with wildcards + // the rest will be normal with wildcards + var sb = new StringBuilder("+(__nodeName:"); + sb.Append(query.ToLower()); + sb.Append("*^10.0 "); + foreach (var f in fields) + { + sb.Append(f); + sb.Append(":"); + sb.Append(query); + sb.Append("* "); + } + sb.Append(") +__IndexType:"); + sb.Append(type); - var result = internalSearcher.Search(criteria); + var raw = internalSearcher.CreateSearchCriteria().RawQuery(sb.ToString()); + + var result = internalSearcher.Search(raw); switch (entityType) {