summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-01-25 22:56:41 +0000
committerGreg Roach <fisharebest@webtrees.net>2019-01-25 22:56:41 +0000
commita41e65f051cac5087779d201c412b92d9ce58c1f (patch)
tree71ecc286ddcb8804ddef12cd3635e07b9a36c244
parentc50ff97d26d25286aa37e82d2f7d2b624b0f6178 (diff)
downloadwebtrees-a41e65f051cac5087779d201c412b92d9ce58c1f.tar.gz
webtrees-a41e65f051cac5087779d201c412b92d9ce58c1f.tar.bz2
webtrees-a41e65f051cac5087779d201c412b92d9ce58c1f.zip
Fix: #2136 - secondary searching in advanced search
-rw-r--r--app/Services/SearchService.php38
1 files changed, 23 insertions, 15 deletions
diff --git a/app/Services/SearchService.php b/app/Services/SearchService.php
index 0e1bb5dc0a..99a3ea64b3 100644
--- a/app/Services/SearchService.php
+++ b/app/Services/SearchService.php
@@ -706,47 +706,55 @@ class SearchService
->map(Individual::rowMapper())
->filter(GedcomRecord::accessFilter())
->filter(function (Individual $individual) use ($fields): bool {
- if (empty($fields)) {
- return true;
- }
-
// Check for XXXX:PLAC fields, which were only partially matched by SQL
foreach ($fields as $field_name => $field_value) {
- $regex_field_value = preg_quote($field_value, '/');
+ $regex = '/' . preg_quote($field_value, '/') . '/i';
$parts = preg_split('/:/', $field_name . '::::');
if ($parts[1] === 'PLAC') {
// *:PLAC
- if (preg_match('/\n\d PLAC .*' . $regex_field_value . '/i', $individual->gedcom())) {
- continue;
+ foreach ($individual->facts([$parts[0]]) as $fact) {
+ if (preg_match($regex, $fact->place()->getGedcomName())) {
+ return true;
+ }
}
+
} elseif ($parts[0] === 'FAMS' && $parts[2] === 'PLAC') {
// FAMS:*:PLAC
foreach ($individual->getSpouseFamilies() as $family) {
- if (preg_match('/\n\d PLAC .*' . $regex_field_value . '/i', $family->gedcom())) {
- continue;
+ foreach ($family->facts([$parts[1]]) as $fact) {
+ if (preg_match($regex, $fact->place()->getGedcomName())) {
+ return true;
+ }
}
}
} elseif ($parts[0] === 'FAMS') {
// e.g. searches for occupation, religion, note, etc.
foreach ($individual->getSpouseFamilies() as $family) {
- if (preg_match('/\n1 ' . $parts[1] . ' .*' . $regex_field_value . '/i', $family->gedcom())) {
- continue;
+ foreach ($family->facts([$parts[1]]) as $fact) {
+ if (preg_match($regex, $fact->value())) {
+ return true;
+ }
}
}
} elseif ($parts[1] === 'TYPE') {
// e.g. FACT:TYPE or EVEN:TYPE
- if (preg_match('/\n1 ' . $parts[0] . '.*(\n2.*)*2 TYPE .*' . $regex_field_value . '/i', $individual->gedcom())) {
- continue;
+ foreach ($individual->facts([$parts[0]]) as $fact) {
+ if (preg_match($regex, $fact->attribute('TYPE'))) {
+ return true;
+ }
}
} else {
// e.g. searches for occupation, religion, note, etc.
- if (preg_match('/\n1 ' . $parts[0] . ' .*' . $regex_field_value . '/i', $individual->gedcom())) {
- continue;
+ foreach ($individual->facts([$parts[0]]) as $fact) {
+ if (preg_match($regex, $fact->value())) {
+ return true;
+ }
}
}
+ // No match
return false;
}