Beispiel #1
0
        /// <summary>
        /// Execute method to write transaction to the database.
        /// </summary>
        public void Execute()
        {
            using (var rockContext = new RockContext())
            {
                var metaPhones = rockContext.Metaphones;

                var newMetaphoneNames = names.Where(n => !metaPhones.Any(m => m.Name == n)).ToList();

                if (newMetaphoneNames.Any())
                {
                    foreach (string name in newMetaphoneNames)
                    {
                        string mp1 = string.Empty;
                        string mp2 = string.Empty;
                        Rock.Utility.DoubleMetaphone.doubleMetaphone(name, ref mp1, ref mp2);

                        var metaphone = new Metaphone();
                        metaphone.Name       = name;
                        metaphone.Metaphone1 = mp1;
                        metaphone.Metaphone2 = mp2;

                        metaPhones.Add(metaphone);
                    }

                    rockContext.SaveChanges();
                }
            }
        }
        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <param name="message"></param>
        public override void Execute(Message message)
        {
            var names = new List <string>();

            AddName(names, message.FirstName);
            AddName(names, message.LastName);
            AddName(names, message.NickName);

            using (var rockContext = new RockContext())
            {
                var metaPhones = rockContext.Metaphones;

                var newMetaphoneNames = names.Where(n => !metaPhones.Any(m => m.Name == n)).ToList();

                if (newMetaphoneNames.Any())
                {
                    foreach (string name in newMetaphoneNames)
                    {
                        string mp1 = string.Empty;
                        string mp2 = string.Empty;
                        Rock.Utility.DoubleMetaphone.doubleMetaphone(name, ref mp1, ref mp2);

                        var metaphone = new Metaphone();
                        metaphone.Name       = name;
                        metaphone.Metaphone1 = mp1;
                        metaphone.Metaphone2 = mp2;

                        metaPhones.Add(metaphone);
                    }

                    rockContext.SaveChanges();
                }
            }
        }
Beispiel #3
0
        public void GenerateMetaphoneCodeForInventory()
        {
            IPhoneticMatch phonetic = new Metaphone();
            var            token1   = phonetic.CreateToken("inventory");
            var            token2   = phonetic.CreateToken("invintury");

            Assert.AreEqual(token1, token2);
        }
Beispiel #4
0
        public void GenerateMetaphoneCodeForTakeMixedCase()
        {
            IPhoneticMatch phonetic = new Metaphone();
            var            token1   = phonetic.CreateToken("tAke");
            var            token2   = phonetic.CreateToken("taEK");

            Assert.AreEqual(token1, token2);
        }
Beispiel #5
0
        public void GenerateMetaphoneCodeForGetandFet()
        {
            IPhoneticMatch phonetic = new Metaphone();
            var            token1   = phonetic.CreateToken("get");
            var            token2   = phonetic.CreateToken("geht");

            Assert.AreEqual(token1, token2);
        }
Beispiel #6
0
        public void GenerateMetaphoneCodeForStephenAndGeorge()
        {
            IPhoneticMatch phonetic = new Metaphone();
            var            token1   = phonetic.CreateToken("Stephen");
            var            token2   = phonetic.CreateToken("George");

            Assert.AreNotEqual(token1, token2);
        }
Beispiel #7
0
        /// <summary>
        /// Does cleanup of Person Aliases and Metaphones
        /// </summary>
        /// <param name="dataMap">The data map.</param>
        private void PersonCleanup(JobDataMap dataMap)
        {
            // Add any missing person aliases
            var                personRockContext     = new Rock.Data.RockContext();
            PersonService      personService         = new PersonService(personRockContext);
            PersonAliasService personAliasService    = new PersonAliasService(personRockContext);
            var                personAliasServiceQry = personAliasService.Queryable();

            foreach (var person in personService.Queryable("Aliases")
                     .Where(p => !p.Aliases.Any() && !personAliasServiceQry.Any(pa => pa.AliasPersonId == p.Id))
                     .Take(300))
            {
                person.Aliases.Add(new PersonAlias {
                    AliasPersonId = person.Id, AliasPersonGuid = person.Guid
                });
            }

            personRockContext.SaveChanges();

            // Add any missing metaphones
            int namesToProcess = dataMap.GetString("MaxMetaphoneNames").AsInteger();

            if (namesToProcess > 0)
            {
                var firstNameQry = personService.Queryable().Select(p => p.FirstName).Where(p => p != null);
                var nickNameQry  = personService.Queryable().Select(p => p.NickName).Where(p => p != null);
                var lastNameQry  = personService.Queryable().Select(p => p.LastName).Where(p => p != null);
                var nameQry      = firstNameQry.Union(nickNameQry.Union(lastNameQry));

                var metaphones    = personRockContext.Metaphones;
                var existingNames = metaphones.Select(m => m.Name).Distinct();

                // Get the names that have not yet been processed
                var namesToUpdate = nameQry
                                    .Where(n => !existingNames.Contains(n))
                                    .Take(namesToProcess)
                                    .ToList();

                foreach (string name in namesToUpdate)
                {
                    string mp1 = string.Empty;
                    string mp2 = string.Empty;
                    Rock.Utility.DoubleMetaphone.doubleMetaphone(name, ref mp1, ref mp2);

                    var metaphone = new Metaphone();
                    metaphone.Name       = name;
                    metaphone.Metaphone1 = mp1;
                    metaphone.Metaphone2 = mp2;

                    metaphones.Add(metaphone);
                }

                personRockContext.SaveChanges();
            }
        }
Beispiel #8
0
        private void cmdMetaphone_Click(object sender, EventArgs e)
        {
            var metaphone = new Metaphone();
            var msg1      = metaphone.Encode(txtFirstText.Text.Trim());

            MessageBox.Show(msg1);

            var msg2 = metaphone.Encode(txtSecondText.Text.Trim());

            MessageBox.Show(msg2);
        }
Beispiel #9
0
    public static SqlString LongPhonetic(SqlInt16 PhoneticType, SqlString InputString)
    {
        BasePhonetics PhoneticObject;

        string _inputString;

        if (InputString.IsNull || InputString.Value.Trim() == String.Empty)
        {
            _inputString = " ";
        }
        else
        {
            _inputString = InputString.Value;
        }

        switch (PhoneticType.Value)
        {
        case 0:
            PhoneticObject = new Soundex(_inputString);
            break;

        case 1:
            PhoneticObject = new RefinedSoundex(_inputString);
            break;

        case 2:
            PhoneticObject = new NYSIIS(_inputString);
            break;

        case 3:
            PhoneticObject = new DaitchMokotoff(_inputString);
            break;

        case 4:
            PhoneticObject = new Metaphone(_inputString);
            break;

        case 6:
            PhoneticObject = new ColognePhonetic(_inputString);
            break;

        default:
            PhoneticObject = new Soundex(_inputString);
            PhoneticType   = 0;
            break;
        }
        PhoneticObject.Iterate();
        return(PhoneticObject.ReadOutput());
    }
        /// <summary>
        /// Execute method to write transaction to the database.
        /// </summary>
        public void Execute()
        {
            var rockContext = new RockContext();
            var metaPhones = rockContext.Metaphones;

            foreach( string name in names.Where( n => !metaPhones.Any( m => m.Name == n ) ) )
            {
                string mp1 = string.Empty;
                string mp2 = string.Empty;
                Rock.Utility.DoubleMetaphone.doubleMetaphone( name, ref mp1, ref mp2 );

                var metaphone = new Metaphone();
                metaphone.Name = name;
                metaphone.Metaphone1 = mp1;
                metaphone.Metaphone2 = mp2;

                metaPhones.Add( metaphone );
            }

            rockContext.SaveChanges();
        }
Beispiel #11
0
        private bool compareWords(WordGuess firstWordGuess, WordGuess secondWordGuess)
        {
            var firstWordModel = new WordModel
            {
                Word = firstWordGuess.Word.ToLower().Trim()
            };

            var secondWordModel = new WordModel
            {
                Word = secondWordGuess.Word.ToLower().Trim()
            };


            var stringArray = new string[] { firstWordModel.Word, secondWordModel.Word };

            var metaphone        = new Metaphone();
            var soundex          = new Soundex();
            var similarMetaphone = metaphone.IsSimilar(stringArray);
            var similarSoundex   = soundex.IsSimilar(stringArray);

            return(similarMetaphone || similarSoundex);
        }
Beispiel #12
0
        /// <summary>
        /// Does cleanup of Person Aliases and Metaphones
        /// </summary>
        /// <param name="dataMap">The data map.</param>
        private void PersonCleanup(JobDataMap dataMap)
        {
            // Add any missing person aliases
            using (var personRockContext = new Rock.Data.RockContext())
            {
                PersonService      personService      = new PersonService(personRockContext);
                PersonAliasService personAliasService = new PersonAliasService(personRockContext);
                var personAliasServiceQry             = personAliasService.Queryable();
                foreach (var person in personService.Queryable("Aliases")
                         .Where(p => !p.Aliases.Any() && !personAliasServiceQry.Any(pa => pa.AliasPersonId == p.Id))
                         .Take(300))
                {
                    person.Aliases.Add(new PersonAlias {
                        AliasPersonId = person.Id, AliasPersonGuid = person.Guid
                    });
                }

                personRockContext.SaveChanges();
            }

            AddMissingAlternateIds();

            using (var personRockContext = new Rock.Data.RockContext())
            {
                PersonService personService = new PersonService(personRockContext);
                // Add any missing metaphones
                int namesToProcess = dataMap.GetString("MaxMetaphoneNames").AsIntegerOrNull() ?? 500;
                if (namesToProcess > 0)
                {
                    var firstNameQry = personService.Queryable().Select(p => p.FirstName).Where(p => p != null);
                    var nickNameQry  = personService.Queryable().Select(p => p.NickName).Where(p => p != null);
                    var lastNameQry  = personService.Queryable().Select(p => p.LastName).Where(p => p != null);
                    var nameQry      = firstNameQry.Union(nickNameQry.Union(lastNameQry));

                    var metaphones    = personRockContext.Metaphones;
                    var existingNames = metaphones.Select(m => m.Name).Distinct();

                    // Get the names that have not yet been processed
                    var namesToUpdate = nameQry
                                        .Where(n => !existingNames.Contains(n))
                                        .Take(namesToProcess)
                                        .ToList();

                    foreach (string name in namesToUpdate)
                    {
                        string mp1 = string.Empty;
                        string mp2 = string.Empty;
                        Rock.Utility.DoubleMetaphone.doubleMetaphone(name, ref mp1, ref mp2);

                        var metaphone = new Metaphone();
                        metaphone.Name       = name;
                        metaphone.Metaphone1 = mp1;
                        metaphone.Metaphone2 = mp2;

                        metaphones.Add(metaphone);
                    }

                    personRockContext.SaveChanges(disablePrePostProcessing: true);
                }
            }

            // Ensures the PrimaryFamily is correct for all person records in the database
            using (var personRockContext = new Rock.Data.RockContext())
            {
                int primaryFamilyUpdates = PersonService.UpdatePrimaryFamilyAll(personRockContext);
            }

            // update any updated or incorrect age classifications on persons
            using (var personRockContext = new Rock.Data.RockContext())
            {
                int ageClassificationUpdates = PersonService.UpdatePersonAgeClassificationAll(personRockContext);
            }

            //// Add any missing Implied/Known relationship groups
            // Known Relationship Group
            AddMissingRelationshipGroups(GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS), Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid());

            // Implied Relationship Group
            AddMissingRelationshipGroups(GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_PEER_NETWORK), Rock.SystemGuid.GroupRole.GROUPROLE_PEER_NETWORK_OWNER.AsGuid());

            // Find family groups that have no members or that have only 'inactive' people (record status) and mark the groups inactive.
            using (var familyRockContext = new Rock.Data.RockContext())
            {
                int familyGroupTypeId           = GroupTypeCache.GetFamilyGroupType().Id;
                int recordStatusInactiveValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid()).Id;

                var activeFamilyWithNoActiveMembers = new GroupService(familyRockContext).Queryable()
                                                      .Where(a => a.GroupTypeId == familyGroupTypeId && a.IsActive == true)
                                                      .Where(a => !a.Members.Where(m => m.Person.RecordStatusValueId != recordStatusInactiveValueId).Any());

                var currentDateTime = RockDateTime.Now;

                familyRockContext.BulkUpdate(activeFamilyWithNoActiveMembers, x => new Rock.Model.Group
                {
                    IsActive = false
                });
            }
        }
Beispiel #13
0
 /// <summary>
 /// Copies the base properties from a source Metaphone object
 /// </summary>
 /// <param name="source">The source.</param>
 public void CopyPropertiesFrom( Metaphone source )
 {
     this.Metaphone1 = source.Metaphone1;
     this.Metaphone2 = source.Metaphone2;
     this.Name = source.Name;
 }
Beispiel #14
0
        /// <summary>
        /// Does cleanup of Person Aliases and Metaphones
        /// </summary>
        /// <param name="dataMap">The data map.</param>
        private void PersonCleanup(JobDataMap dataMap)
        {
            // Add any missing person aliases
            var                personRockContext     = new Rock.Data.RockContext();
            PersonService      personService         = new PersonService(personRockContext);
            PersonAliasService personAliasService    = new PersonAliasService(personRockContext);
            var                personAliasServiceQry = personAliasService.Queryable();

            foreach (var person in personService.Queryable("Aliases")
                     .Where(p => !p.Aliases.Any() && !personAliasServiceQry.Any(pa => pa.AliasPersonId == p.Id))
                     .Take(300))
            {
                person.Aliases.Add(new PersonAlias {
                    AliasPersonId = person.Id, AliasPersonGuid = person.Guid
                });
            }

            personRockContext.SaveChanges();

            // Add any missing metaphones
            int namesToProcess = dataMap.GetString("MaxMetaphoneNames").AsIntegerOrNull() ?? 500;

            if (namesToProcess > 0)
            {
                var firstNameQry = personService.Queryable().Select(p => p.FirstName).Where(p => p != null);
                var nickNameQry  = personService.Queryable().Select(p => p.NickName).Where(p => p != null);
                var lastNameQry  = personService.Queryable().Select(p => p.LastName).Where(p => p != null);
                var nameQry      = firstNameQry.Union(nickNameQry.Union(lastNameQry));

                var metaphones    = personRockContext.Metaphones;
                var existingNames = metaphones.Select(m => m.Name).Distinct();

                // Get the names that have not yet been processed
                var namesToUpdate = nameQry
                                    .Where(n => !existingNames.Contains(n))
                                    .Take(namesToProcess)
                                    .ToList();

                foreach (string name in namesToUpdate)
                {
                    string mp1 = string.Empty;
                    string mp2 = string.Empty;
                    Rock.Utility.DoubleMetaphone.doubleMetaphone(name, ref mp1, ref mp2);

                    var metaphone = new Metaphone();
                    metaphone.Name       = name;
                    metaphone.Metaphone1 = mp1;
                    metaphone.Metaphone2 = mp2;

                    metaphones.Add(metaphone);
                }

                personRockContext.SaveChanges();
            }

            //// Add any missing Implied/Known relationship groups
            // Known Relationship Group
            AddMissingRelationshipGroups(GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS), Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid());

            // Implied Relationship Group
            AddMissingRelationshipGroups(GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_IMPLIED_RELATIONSHIPS), Rock.SystemGuid.GroupRole.GROUPROLE_IMPLIED_RELATIONSHIPS_OWNER.AsGuid());
        }
        /// <summary>
        /// Does cleanup of Person Aliases and Metaphones
        /// </summary>
        /// <param name="dataMap">The data map.</param>
        private void PersonCleanup( JobDataMap dataMap )
        {
            // Add any missing person aliases
            var personRockContext = new Rock.Data.RockContext();
            PersonService personService = new PersonService( personRockContext );
            foreach ( var person in personService.Queryable( "Aliases" )
                .Where( p => !p.Aliases.Any() )
                .Take( 300 ) )
            {
                person.Aliases.Add( new PersonAlias { AliasPersonId = person.Id, AliasPersonGuid = person.Guid } );
            }

            personRockContext.SaveChanges();

            // Add any missing metaphones
            int namesToProcess = dataMap.GetString( "MaxMetaphoneNames" ).AsInteger();
            if ( namesToProcess > 0 )
            {
                var firstNameQry = personService.Queryable().Select( p => p.FirstName ).Where( p => p != null );
                var nickNameQry = personService.Queryable().Select( p => p.NickName ).Where( p => p != null );
                var lastNameQry = personService.Queryable().Select( p => p.LastName ).Where( p => p != null );
                var nameQry = firstNameQry.Union( nickNameQry.Union( lastNameQry ) );

                var metaphones = personRockContext.Metaphones;
                var existingNames = metaphones.Select( m => m.Name ).Distinct();

                // Get the names that have not yet been processed
                var namesToUpdate = nameQry
                    .Where( n => !existingNames.Contains( n ) )
                    .Take( namesToProcess )
                    .ToList();

                foreach ( string name in namesToUpdate )
                {
                    string mp1 = string.Empty;
                    string mp2 = string.Empty;
                    Rock.Utility.DoubleMetaphone.doubleMetaphone( name, ref mp1, ref mp2 );

                    var metaphone = new Metaphone();
                    metaphone.Name = name;
                    metaphone.Metaphone1 = mp1;
                    metaphone.Metaphone2 = mp2;

                    metaphones.Add( metaphone );
                }

                personRockContext.SaveChanges();
            }
        }
Beispiel #16
0
        private void StringMatchKeyTest(string[] testCases)
        {
            Debug.WriteLine("EditexKey");
            StringPhoneticKeyBuilder keyBuilder = new EditexKey();

            foreach (var name in testCases)
            {
                string key = keyBuilder.BuildKey(name);
                Debug.WriteLine("\t{0} for {1}", key, name);
            }

            Debug.WriteLine("DaitchMokotoff");
            StringPhoneticKeyBuilder keyBuilder2 = new DaitchMokotoff();

            foreach (var name in testCases)
            {
                string key = keyBuilder2.BuildKey(name);
                Debug.WriteLine("\t{0} for {1}", key, name);
            }

            Debug.WriteLine("Phonix");
            StringPhoneticKeyBuilder keyBuilder3 = new Phonix();

            foreach (var name in testCases)
            {
                string key = keyBuilder3.BuildKey(name);
                Debug.WriteLine("\t{0} for {1}", key, name);
            }

            Debug.WriteLine("SoundEx");
            StringPhoneticKeyBuilder keyBuilder4 = new SoundEx();

            foreach (var name in testCases)
            {
                string key = keyBuilder4.BuildKey(name);
                Debug.WriteLine("\t{0} for {1}", key, name);
            }

            Debug.WriteLine("SimpleTextKey");
            StringPhoneticKeyBuilder keyBuilder5 = new SimpleTextKey();

            foreach (var name in testCases)
            {
                string key = keyBuilder5.BuildKey(name);
                Debug.WriteLine("\t{0} for {1}", key, name);
            }

            Debug.WriteLine("Metaphone");
            StringPhoneticKeyBuilder keyBuilder6 = new Metaphone();

            foreach (var name in testCases)
            {
                string key = keyBuilder6.BuildKey(name);
                Debug.WriteLine("\t{0} for {1}", key, name);
            }

            Debug.WriteLine("DoubleMetaphone");
            StringPhoneticKeyBuilder keyBuilder7 = new DoubleMetaphone();

            foreach (var name in testCases)
            {
                string key = keyBuilder7.BuildKey(name);
                Debug.WriteLine("\t{0} for {1}", key, name);
            }
        }
Beispiel #17
0
 /// <summary>
 /// Copies the base properties from a source Metaphone object
 /// </summary>
 /// <param name="source">The source.</param>
 public void CopyPropertiesFrom(Metaphone source)
 {
     this.Metaphone1 = source.Metaphone1;
     this.Metaphone2 = source.Metaphone2;
     this.Name       = source.Name;
 }
Beispiel #18
0
        /// <summary> 
        /// Job that executes routine Rock cleanup tasks
        /// 
        /// Called by the <see cref="IScheduler" /> when a
        /// <see cref="ITrigger" /> fires that is associated with
        /// the <see cref="IJob" />.
        /// </summary>
        public virtual void Execute( IJobExecutionContext context )
        {
            var rockContext = new Rock.Data.RockContext();

            // get the job map
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            // delete accounts that have not been confirmed in X hours
            int? userExpireHours = dataMap.GetString( "HoursKeepUnconfirmedAccounts" ).AsIntegerOrNull();
            if ( userExpireHours.HasValue )
            {
                DateTime userAccountExpireDate = RockDateTime.Now.Add( new TimeSpan( userExpireHours.Value * -1, 0, 0 ) );

                var userLoginService = new UserLoginService(rockContext);

                foreach ( var user in userLoginService.Queryable().Where( u => u.IsConfirmed == false && ( u.CreatedDateTime ?? DateTime.MinValue ) < userAccountExpireDate ).ToList() )
                {
                    userLoginService.Delete( user );
                }

                rockContext.SaveChanges();
            }

            // purge exception log
            int? exceptionExpireDays = dataMap.GetString( "DaysKeepExceptions" ).AsIntegerOrNull();
            if ( exceptionExpireDays.HasValue )
            {
                DateTime exceptionExpireDate = RockDateTime.Now.Add( new TimeSpan( exceptionExpireDays.Value * -1, 0, 0, 0 ) );

                ExceptionLogService exceptionLogService = new ExceptionLogService( rockContext );

                foreach ( var exception in exceptionLogService.Queryable().Where( e => e.CreatedDateTime.HasValue && e.CreatedDateTime < exceptionExpireDate ).ToList() )
                {
                    exceptionLogService.Delete( exception );
                }

                rockContext.SaveChanges();
            }

            // purge audit log
            int? auditExpireDays = dataMap.GetString( "AuditLogExpirationDays" ).AsIntegerOrNull();
            if ( auditExpireDays.HasValue )
            {
                DateTime auditExpireDate = RockDateTime.Now.Add( new TimeSpan( auditExpireDays.Value * -1, 0, 0, 0 ) );
                AuditService auditService = new AuditService(rockContext);
                foreach ( var audit in auditService.Queryable().Where( a => a.DateTime < auditExpireDate ).ToList() )
                {
                    auditService.Delete( audit );
                }

                rockContext.SaveChanges();
            }

            // clean the cached file directory

            // get the attributes
            string cacheDirectoryPath = dataMap.GetString( "BaseCacheDirectory" );
            int? cacheExpirationDays = dataMap.GetString( "DaysKeepCachedFiles" ).AsIntegerOrNull();
            if ( cacheExpirationDays.HasValue )
            {
                DateTime cacheExpirationDate = RockDateTime.Now.Add( new TimeSpan( cacheExpirationDays.Value * -1, 0, 0, 0 ) );

                // if job is being run by the IIS scheduler and path is not null
                if ( context.Scheduler.SchedulerName == "RockSchedulerIIS" && !string.IsNullOrEmpty( cacheDirectoryPath ) )
                {
                    // get the physical path of the cache directory
                    cacheDirectoryPath = System.Web.Hosting.HostingEnvironment.MapPath( cacheDirectoryPath );
                }

                // if directory is not blank and cache expiration date not in the future
                if ( !string.IsNullOrEmpty( cacheDirectoryPath ) && cacheExpirationDate <= RockDateTime.Now )
                {
                    // Clean cache directory
                    CleanCacheDirectory( cacheDirectoryPath, cacheExpirationDate );
                }
            }

            // clean out any temporary binary files
            BinaryFileService binaryFileService = new BinaryFileService(rockContext);
            foreach ( var binaryFile in binaryFileService.Queryable().Where( bf => bf.IsTemporary == true ).ToList() )
            {
                if ( binaryFile.ModifiedDateTime < RockDateTime.Now.AddDays( -1 ) )
                {
                    binaryFileService.Delete( binaryFile );
                }
            }
            rockContext.SaveChanges();

            // Add any missing person aliases
            PersonService personService = new PersonService(rockContext);
            foreach ( var person in personService.Queryable( "Aliases" )
                .Where( p => !p.Aliases.Any() )
                .Take( 300 ) )
            {
                person.Aliases.Add( new PersonAlias { AliasPersonId = person.Id, AliasPersonGuid = person.Guid } );
            }

            rockContext.SaveChanges();

            // Add any missing metaphones
            int namesToProcess = dataMap.GetString( "MaxMetaphoneNames" ).AsInteger();
            if ( namesToProcess > 0 )
            {
                var firstNameQry = personService.Queryable().Select( p => p.FirstName );
                var nickNameQry = personService.Queryable().Select( p => p.NickName );
                var lastNameQry = personService.Queryable().Select( p => p.LastName );
                var nameQry = firstNameQry.Union( nickNameQry.Union( lastNameQry ) );

                var metaphones = rockContext.Metaphones;
                var existingNames = metaphones.Select( m => m.Name ).Distinct();

                // Get the names that have not yet been processed
                var namesToUpdate = nameQry
                    .Where( n => !existingNames.Contains( n ) )
                    .Take( namesToProcess )
                    .ToList();

                foreach ( string name in namesToUpdate )
                {
                    string mp1 = string.Empty;
                    string mp2 = string.Empty;
                    Rock.Utility.DoubleMetaphone.doubleMetaphone( name, ref mp1, ref mp2 );

                    var metaphone = new Metaphone();
                    metaphone.Name = name;
                    metaphone.Metaphone1 = mp1;
                    metaphone.Metaphone2 = mp2;

                    metaphones.Add( metaphone );
                }

                rockContext.SaveChanges();
            }
        }