diff options
| author | Greg Roach <fisharebest@webtrees.net> | 2019-10-15 17:35:47 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@webtrees.net> | 2019-10-15 17:35:47 +0100 |
| commit | 6412bde396c713d428206ad45a7df1b16aedd4b3 (patch) | |
| tree | 7db259391e22f3473c3f7beb9d39ab0de9af1301 | |
| parent | 5136fb17e611f939d033ca71409d6a5b1272f13b (diff) | |
| download | webtrees-6412bde396c713d428206ad45a7df1b16aedd4b3.tar.gz webtrees-6412bde396c713d428206ad45a7df1b16aedd4b3.tar.bz2 webtrees-6412bde396c713d428206ad45a7df1b16aedd4b3.zip | |
Simplify branches logic to match surnames
| -rw-r--r-- | app/Http/Controllers/BranchesController.php | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/app/Http/Controllers/BranchesController.php b/app/Http/Controllers/BranchesController.php index 60063b8242..8ddf541cd2 100644 --- a/app/Http/Controllers/BranchesController.php +++ b/app/Http/Controllers/BranchesController.php @@ -35,7 +35,7 @@ use Illuminate\Database\Query\Builder; use Illuminate\Database\Query\JoinClause; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; - +use function stripos; use function view; /** @@ -278,6 +278,10 @@ class BranchesController extends AbstractBaseController $person_name = $name['full']; break; } + if ($this->surnamesMatch($surn1, $surname, $soundex_std, $soundex_dm)) { + $person_name = $name['full']; + break; + } } // No matching name? Typically children with a different surname. The branch stops here. @@ -357,6 +361,30 @@ class BranchesController extends AbstractBaseController } /** + * Do two surnames match? + * + * @param string $surname1 + * @param string $surname2 + * @param bool $soundex_std + * @param bool $soundex_dm + * + * @return bool + */ + private function surnamesMatch(string $surname1, string $surname2, bool $soundex_std, bool $soundex_dm): bool + { + // One name sounds like another? + if ($soundex_std && Soundex::compare(Soundex::russell($surname1), Soundex::russell($surname2))) { + return true; + } + if ($soundex_dm && Soundex::compare(Soundex::daitchMokotoff($surname1), Soundex::daitchMokotoff($surname2))) { + return true; + } + + // One is a substring of the other. e.g. Halen / Van Halen + return stripos($surname1, $surname2) !== false || stripos($surname2, $surname1) !== false; + } + + /** * Convert a SOSA number into a generation number. e.g. 8 = great-grandfather = 3 generations * * @param int $sosa |
