Skip to content

Commit

Permalink
func to get the tag collection for the each result
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendy committed Oct 12, 2018
1 parent e9b71a5 commit 23336cf
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/Our.Umbraco.Look/Services/LookSearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,27 @@ public static IEnumerableWithTotal<LookMatch> Query(LookQuery lookQuery)
}
}

Func<Field[], string[]> 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<string>();
var anyTags = new List<string>();

Expand Down Expand Up @@ -252,6 +270,7 @@ public static IEnumerableWithTotal<LookMatch> Query(LookQuery lookQuery)
indexSearcher,
topDocs,
getHighlight,
getTags,
getDistance),
topDocs.TotalHits);
}
Expand All @@ -273,10 +292,11 @@ private static IEnumerable<LookMatch> GetLookMatches(
IndexSearcher indexSearcher,
TopDocs topDocs,
Func<string, IHtmlString> getHighlight,
Func<Field[], string[]> getTags,
Func<int, double?> 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<string>();

Expand All @@ -295,10 +315,14 @@ private static IEnumerable<LookMatch> GetLookMatches(
getHighlight = x => null;
}

if (getTags)
if (getTags != null)
{
fields.Add(LookConstants.TagsField);
}
else
{
getTags = x => null;
}

var mapFieldSelector = new MapFieldSelector(fields.ToArray());

Expand All @@ -319,7 +343,7 @@ private static IEnumerable<LookMatch> 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,
Expand Down

0 comments on commit 23336cf

Please sign in to comment.