diff --git a/src/Our.Umbraco.Look/Services/LookSearchService.cs b/src/Our.Umbraco.Look/Services/LookSearchService.cs index 5c55188..90302ad 100644 --- a/src/Our.Umbraco.Look/Services/LookSearchService.cs +++ b/src/Our.Umbraco.Look/Services/LookSearchService.cs @@ -58,9 +58,27 @@ public static IEnumerableWithTotal Query(LookQuery lookQuery) } } + Func getTags = null; + // Tags if (lookQuery.TagQuery != null) { + if (lookQuery.TagQuery.GetTags) + { + getTags = x => + { + if (x != null) + { + return x + .Select(y => y.StringValue()) + .Where(y => !string.IsNullOrWhiteSpace(y)) + .ToArray(); + } + + return null; + }; + } + var allTags = new List(); var anyTags = new List(); @@ -252,6 +270,7 @@ public static IEnumerableWithTotal Query(LookQuery lookQuery) indexSearcher, topDocs, getHighlight, + getTags, getDistance), topDocs.TotalHits); } @@ -273,10 +292,11 @@ private static IEnumerable GetLookMatches( IndexSearcher indexSearcher, TopDocs topDocs, Func getHighlight, + Func getTags, Func getDistance) { + // flag to indicate that the query has requested the full text to be returned bool getText = lookQuery.TextQuery != null && lookQuery.TextQuery.GetText; - bool getTags = lookQuery.TagQuery != null && lookQuery.TagQuery.GetTags; var fields = new List(); @@ -295,10 +315,14 @@ private static IEnumerable GetLookMatches( getHighlight = x => null; } - if (getTags) + if (getTags != null) { fields.Add(LookConstants.TagsField); } + else + { + getTags = x => null; + } var mapFieldSelector = new MapFieldSelector(fields.ToArray()); @@ -319,7 +343,7 @@ private static IEnumerable GetLookMatches( Convert.ToInt32(doc.Get(LuceneIndexer.IndexNodeIdFieldName)), getHighlight(doc.Get(LookConstants.TextField)), getText ? doc.Get(LookConstants.TextField) : null, - getTags ? doc.Get(LookConstants.TagsField).Split(' ') : null, + getTags(doc.GetFields(LookConstants.TagsField)), date, doc.Get(LookConstants.NameField), doc.Get(LookConstants.LocationField) != null ? new Location(doc.Get(LookConstants.LocationField)) : null,