The difference between those two posts and my Index, is that I have a reduce. So i'm not sure how to do the map, bit.
Here's my code.
public class LogEntries_ByClientGuidClientName :
AbstractIndexCreationTask<LogEntry, LogEntries_ByClientGuidClientName.ReduceResult>
{
public LogEntries_ByClientGuidClientName()
{
Map = docs => from doc in docs
//where !string.IsNullOrEmpty(doc.ClientGuid) &&
// !string.IsNullOrEmpty(doc.ClientName)
where doc.ClientGuid != null && doc.ClientName != null
select new
{
doc.ClientGuid,
ReversedClientGuid = (string)null,
ClientNames = new[] {doc.ClientName}
};
Reduce = results => from result in results
group result by result.ClientGuid
into g
select new
{
ClientGuid = g.Key,
ReversedClientGuid = g.Key.Reverse(),
ClientNames = g.SelectMany(x => x.ClientNames).Distinct().ToArray()
};
Index(x => x.ClientNames, FieldIndexing.Analyzed);
Index(x => x.ReversedClientGuid, FieldIndexing.Analyzed);
}
#region Nested type: QueryResult
public class ReduceResult
{
public string ClientGuid { get; set; }
public string ReversedClientGuid { get; set; }
public string[] ClientNames { get; set; }
public override string ToString()
{
return string.Format("{0} : {1}", ClientGuid, ClientNames != null && ClientNames.Count() == 1
? ClientNames[0]
: ClientNames == null
? "no names"
: ClientNames.Count() + " names.");
}
}
#endregion
}