Fixes search algorithm to have more accurate results

This commit is contained in:
Shannon
2013-10-29 16:00:15 +11:00
parent e862ffcb1b
commit aca550a9b4

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Text;
using System.Web.Http; using System.Web.Http;
using System.Web.Http.Controllers; using System.Web.Http.Controllers;
using System.Web.Http.ModelBinding; using System.Web.Http.ModelBinding;
@@ -161,18 +162,26 @@ namespace Umbraco.Web.Editors
} }
var internalSearcher = ExamineManager.Instance.SearchProviderCollection[searcher]; var internalSearcher = ExamineManager.Instance.SearchProviderCollection[searcher];
var criteria = internalSearcher.CreateSearchCriteria(type, BooleanOperation.Or);
criteria //build a lucene query:
//search the special __nodeName specifically with lowercase since it is indexed lowercase // the __nodeName will be boosted 10x with wildcards
// - we are however by default using whitespace analyzer which doesn't care about casing anyways. // the rest will be normal with wildcards
.Field("__nodeName", query.ToLower().MultipleCharacterWildcard()) var sb = new StringBuilder("+(__nodeName:");
.Or() sb.Append(query.ToLower());
//then just search the result of the fields specified. sb.Append("*^10.0 ");
.GroupedOr(fields, new[] { query.MultipleCharacterWildcard() }) foreach (var f in fields)
.Compile(); {
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) switch (entityType)
{ {