//---------------------------------------------------------------------- private static ResultSet FinalizeResultSet( Timer t, Comparison <Result> sortOrder, int desiredResultCount, ResultSet matches, string featuredProfileTemplateLabel) { // KLUDGE: Ed V. is not confident that this is the right place for // this code. Would it be better to make this a ResultSet method? // Would you ever *not* want to call all of these methods in exactly // this order? If so, it should not be a ResultSet method. If not, // it should be. t.Measure("Find summaries for each matching Party", delegate() { matches.LoadSummaries(); }); if (StringX.IsNotEmpty(featuredProfileTemplateLabel)) { t.Measure("Find featured-since dates for each matching Party", delegate() { matches.LoadFeaturedSinceDates(featuredProfileTemplateLabel); }); } t.Measure("Sort matching Parties", delegate() { matches.OrderBy(sortOrder); }); t.Measure("Trim results to desiredResultCount", delegate() { matches.TrimToDesiredResultCount(desiredResultCount); }); t.Measure("Find EPMTs associated with matching Parties", delegate() { // BUG: Since the "trim" step above doesn't actually discard the // Party IDs from the ResultSet, we may find a EPMT here that // isn't actually represented in the *visible* results. Arrg! // In practice, this is *very* rare, so we'll live with the // slight chance that an extra license type will be included for // now. matches.LoadExternalPartyMembershipTypes(); }); return(matches); }
//---------------------------------------------------------------------- private static ResultSet SearchByParty <ProfileType>( Timer t, IEnumerable <string> nameSearchNoiseWords, AddressParserResult searchLocale, int desiredResultCount, int maxResultCount, IntSet <PartyId> externalPartyMembershipTypeMatches, IntSet <PartyId> profileSpecificParties, double nonGeoMatchAbsDensity, ref Comparison <Result> sortOrder) where ProfileType : ISearch, new() { IntSet <PartyId> nameMatches = null; IntSet <PartyId> locationMatches = null; IntSet <PartyId> geoOrNameMatches = null; Location centroid = null; double? maxRadiusMi = null; ResultSet rs = null; if (StringX.IsNotEmpty(searchLocale.PartyName)) { nameMatches = SearchByName(t, searchLocale, nameSearchNoiseWords); } if (searchLocale.Type == Snap.Data.Controller.SearchType.PartyName) { geoOrNameMatches = nameMatches; sortOrder = Result.NameAscending; } else { switch (new ProfileType().GeoSearch) { case GeoSearchType.Point: locationMatches = SearchForLocations( t, nameSearchNoiseWords, searchLocale, desiredResultCount, maxResultCount, nonGeoMatchAbsDensity, out centroid, out maxRadiusMi); break; case GeoSearchType.ServiceArea: locationMatches = SearchForServiceArea(t, searchLocale); break; case GeoSearchType.All: var pointMatches = SearchForLocations( t, nameSearchNoiseWords, searchLocale, desiredResultCount, maxResultCount, nonGeoMatchAbsDensity, out centroid, out maxRadiusMi); var svcAreaMatches = SearchForServiceArea(t, searchLocale); locationMatches = IntSet <PartyId> .Union(pointMatches, svcAreaMatches); sortOrder = Result.ShowServiceAreaMatchesFirst(svcAreaMatches, sortOrder); break; default: throw new ArgumentException(String.Format( "Unexpected value of 'ISearch.GeoSearch': {0}", new ProfileType().GeoSearch.ToString())); } geoOrNameMatches = StringX.IsNotEmpty(searchLocale.PartyName) ? IntSet <PartyId> .Intersection(nameMatches, locationMatches) : locationMatches; } rs = ResultSet.From( centroid, maxRadiusMi, IntSet <PartyId> .IntersectionOfMany( geoOrNameMatches, externalPartyMembershipTypeMatches, profileSpecificParties)); if (Snap.Data.Controller.SearchType.Membership == searchLocale.Type) { rs.UnfilteredMatchCount = externalPartyMembershipTypeMatches.Count; } else if (IntSet <PartyId> .IsEmpty(geoOrNameMatches)) { rs.UnfilteredMatchCount = 0; } else { rs.UnfilteredMatchCount = geoOrNameMatches.Count; } return(rs); }