Beispiel #1
0
        //----------------------------------------------------------------------
        /// <summary>
        /// Search the SNAP system for matches to the provided criteria.
        /// </summary>
        public static ResultSet Do <ProfileType>(
            ITimer timerContext,
            IEnumerable <string> nameSearchNoiseWords,
            Dictionary <string, string> consumerProperties,
            Comparison <Result> sortOrder,
            AddressParserResult searchLocale,
            int desiredResultCount,
            int maxResultCount,
            List <int> externalPartyMembershipTypeIds,
            IntSet <PartyId> profileSpecificParties,
            IntSet <ProfileId> profileSpecificiProfiles,
            MembershipSearch membershipSearch,
            PartySearch partySearch,
            ProfileSearch <ProfileType> profileSearch,
            string featuredProfileTemplateLabel)
            where ProfileType : ISearch, new()
        {
            Timer t = new Timer(timerContext, "Search.Do() - implicit");

            try {
                return(InnerSearch <ProfileType>(t,
                                                 nameSearchNoiseWords,
                                                 consumerProperties,
                                                 sortOrder,
                                                 searchLocale,
                                                 desiredResultCount,
                                                 maxResultCount,
                                                 externalPartyMembershipTypeIds,
                                                 profileSpecificParties,
                                                 profileSpecificiProfiles,
                                                 membershipSearch,
                                                 partySearch,
                                                 profileSearch,
                                                 featuredProfileTemplateLabel));
            }
            finally {
                t.Stop();
            }
        }
Beispiel #2
0
        //----------------------------------------------------------------------
        private static ResultSet InnerSearch <ProfileType>(
            Timer t,
            IEnumerable <string> nameSearchNoiseWords,
            Dictionary <string, string> consumerProperties,
            Comparison <Result> sortOrder,
            AddressParserResult searchLocale,
            int desiredResultCount,
            int maxResultCount,
            List <int> externalPartyMembershipTypeIds,
            IntSet <PartyId> profileSpecificParties,
            IntSet <ProfileId> profileSpecificProfiles,
            MembershipSearch membershipSearch,
            PartySearch partySearch,
            ProfileSearch <ProfileType> profileSearch,
            string featuredProfileTemplateLabel)
            where ProfileType : ISearch, new()
        {
            if (null == profileSpecificProfiles)
            {
                profileSpecificProfiles = IntSet <ProfileId> .Universe;
            }

            if (null == profileSpecificParties)
            {
                profileSpecificParties = IntSet <PartyId> .Universe;
            }

            //Console.WriteLine(Snap.Cache.Cache.ProfileTemplate.Count);
            ISearch profileType = new ProfileType();

            IntSet <PartyId> matchesByProfileType = null;

            try {
                if (String.IsNullOrEmpty(profileType.ProfileTemplateLabel))
                {
                    matchesByProfileType = IntSet <PartyId> .Universe;
                }
                else
                {
                    matchesByProfileType =
                        Snap.Cache.Cache.ProfileTemplate[profileType.ProfileTemplateLabel];
                }
            }
            catch (KeyNotFoundException exc) {
                throw new ApplicationException(
                          "Unknown ProfileTemplateLabel: " + profileType.ProfileTemplateLabel,
                          exc);
            }

            IntSet <PartyId> matchesByMembership = IntSet <PartyId> .Universe;

            t.Measure("Search by membership(s)", delegate() {
                if (!ListX.IsEmpty(externalPartyMembershipTypeIds))
                {
                    matchesByMembership = membershipSearch(externalPartyMembershipTypeIds);
                }
            });

            matchesByMembership =
                IntSet <PartyId> .Intersection(matchesByProfileType, matchesByMembership);

            ResultSet matchesByProfile = null;

            t.Measure("Search by Profile ('advanced' search)", delegate() {
                matchesByProfile = profileSearch(
                    t,
                    consumerProperties,
                    profileSpecificProfiles);
            });

            double nonGeoMatchAbsDensity = NonGeoMatchAbsDensity(
                matchesByMembership,
                matchesByProfile);

            ResultSet matchesByParty = ResultSet.Universe;

            t.Measure("Search by Party (geography,name)", delegate() {
                if (searchLocale == null)
                {
                    matchesByParty = ResultSet.From(null, null, matchesByMembership);
                }
                else
                {
                    matchesByParty = partySearch(
                        t,
                        nameSearchNoiseWords,
                        searchLocale,
                        desiredResultCount,
                        maxResultCount,
                        matchesByMembership,
                        profileSpecificParties,
                        nonGeoMatchAbsDensity,
                        ref sortOrder);
                }
            });

            ResultSet matches = null;

            t.Measure("Combine matches-by-party and matches-by-profile", delegate() {
                matches = ResultSet.Intersection(matchesByParty, matchesByProfile);
            });

            return(FinalizeResultSet(
                       t,
                       sortOrder,
                       desiredResultCount,
                       matches,
                       featuredProfileTemplateLabel));
        }