Created
March 17, 2014 01:35
-
-
Save hyrmn/9592467 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class PersonSummaryIndex : AbstractIndexCreationTask<PersonProjection> | |
| { | |
| public PersonSummaryIndex() | |
| { | |
| Map = people => from person in people | |
| select new | |
| { | |
| person.Id, | |
| Query = new object[] | |
| { | |
| person.Id, | |
| person.FirstName, | |
| person.LastName, | |
| person.PublicNote, | |
| person.PrivateNote, | |
| LoadDocument<SourceProjection>(person.SourceId).Label, | |
| from t in LoadDocument<PersonTagProjection>(person.TagIds) select t.Name, | |
| from cf in person.CustomFields select cf.Value, | |
| from n in person.PhoneNumbers select n.Number, | |
| from e in person.EmailAddresses select e.Address, | |
| from e in person.EmailAddresses select e.Address.Split('@'), | |
| }, | |
| SortName = person.LastName + "_" + person.FirstName, | |
| Name = person.FirstName + " " + person.LastName | |
| }; | |
| TransformResults = (database, results) => | |
| from result in results | |
| let tags = database.Load<PersonTagProjection>(result.TagIds) | |
| select new | |
| { | |
| result.Id, | |
| result.SourceId, | |
| result.FirstName, | |
| result.LastName, | |
| result.PrivateNote, | |
| result.Addresses, | |
| result.EmailAddresses, | |
| result.PhoneNumbers, | |
| Tags = tags | |
| }; | |
| Sort("SortName", SortOptions.String); | |
| Index("SortName", FieldIndexing.NotAnalyzed); | |
| Index("Name", FieldIndexing.Analyzed); | |
| } | |
| public class ReduceResult | |
| { | |
| public string Id { get; set; } | |
| public string Query { get; set; } | |
| public string SortName { get; set; } | |
| public string Name { get; set; } | |
| } | |
| public class Result | |
| { | |
| public Result() | |
| { | |
| Tags = new List<PersonTagProjection>(); | |
| } | |
| public string Id { get; set; } | |
| public string FirstName { get; set; } | |
| public string LastName { get; set; } | |
| public string PrivateNote { get; set; } | |
| public IList<PersonAddressProjection> Addresses { get; set; } | |
| public IList<PersonEmailProjection> EmailAddresses { get; set; } | |
| public IList<PersonPhoneProjection> PhoneNumbers { get; set; } | |
| public DateTime? LastStay { get; set; } | |
| public DateTime? NextStay { get; set; } | |
| public IList<PersonTagProjection> Tags { get; set; } | |
| public string SourceId { get; set; } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment