From 7400976c965c95032d1358267004d90dcbbc0793 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Wed, 20 Oct 2010 19:22:40 +0000 Subject: [PATCH] fix filters for name search svn: r16016 --- src/Filters/Rules/Person/_HasNameOf.py | 76 ++++++++++++++------ src/Filters/Rules/Person/_IncompleteNames.py | 7 +- src/Filters/Rules/Person/_RegExpName.py | 4 +- src/Filters/Rules/Person/_SearchName.py | 7 +- 4 files changed, 66 insertions(+), 28 deletions(-) diff --git a/src/Filters/Rules/Person/_HasNameOf.py b/src/Filters/Rules/Person/_HasNameOf.py index 02308fd5a..bc4d79a3b 100644 --- a/src/Filters/Rules/Person/_HasNameOf.py +++ b/src/Filters/Rules/Person/_HasNameOf.py @@ -34,6 +34,7 @@ from gen.ggettext import sgettext as _ # #------------------------------------------------------------------------- from Filters.Rules._Rule import Rule +from gen.lib import NameOriginType #------------------------------------------------------------------------- # @@ -43,41 +44,76 @@ from Filters.Rules._Rule import Rule class HasNameOf(Rule): """Rule that checks for full or partial name matches""" - labels = [ _('Given name:'), - _('Family name:'), - _('Suffix:'), + labels = [ _('Given name:'), + _('Full Family name:'), _('person|Title:'), + _('Suffix:'), + _('Call Name:'), + _('Nick Name:'), _('Prefix:'), + _('Single Surname:'), + _('Connector'), _('Patronymic:'), - _('Call Name:'),] + _('Family Nick Name:')] name = _('People with the ') description = _("Matches people with a specified (partial) name") category = _('General filters') - def apply(self,db,person): - self.firstn = self.list[0] - self.lastn = self.list[1] - self.surn = self.list[2] - self.title = self.list[3] - self.prefix = self.list[4] - self.patr = self.list[5] - self.calln = self.list[6] + def prepare(self, db): + self.firstn = self.list[0].upper() + self.lastn = self.list[1].upper() + self.title = self.list[2].upper() + self.suffix = self.list[3].upper() + self.calln = self.list[4].upper() + self.nick = self.list[5].upper() + self.famnick = self.list[10].upper() + #surname parts + self.prefix = self.list[6].upper() + self.surn = self.list[7].upper() + self.con = self.list[8].upper() + self.patr = self.list[9].upper() + + def apply(self, db, person): for name in [person.get_primary_name()] + person.get_alternate_names(): val = 1 - if self.firstn and name.get_first_name().upper().find(self.firstn.upper()) == -1: + valpref = 0 + if not self.prefix: + valpref = 1 + valsurn = 0 + if not self.surn: + valsurn = 1 + valcon = 0 + if not self.con: + valcon = 1 + valpatr = 0 + if not self.patr: + valpatr = 1 + if self.firstn and name.get_first_name().upper().find(self.firstn) == -1: val = 0 - if self.lastn and name.get_surname().upper().find(self.lastn.upper()) == -1: + elif self.lastn and name.get_surname().upper().find(self.lastn) == -1: val = 0 - if self.surn and name.get_suffix().upper().find(self.surn.upper()) == -1: + elif self.suffix and name.get_suffix().upper().find(self.surn) == -1: val = 0 - if self.title and name.get_title().upper().find(self.title.upper()) == -1: + elif self.title and name.get_title().upper().find(self.title) == -1: val = 0 - if self.prefix and name.get_prefix().upper().find(self.prefix.upper()) == -1: + elif self.calln and name.get_call_name().upper().find(self.calln) == -1: val = 0 - if self.patr and name.get_patronymic().upper().find(self.patr.upper()) == -1: + elif self.nick and name.get_nick_name().upper().find(self.nick) == -1: val = 0 - if self.calln and name.get_call_name().upper().find(self.calln.upper()) == -1: + elif self.famnick and name.get_family_nick_name().upper().find(self.famnick) == -1: val = 0 - if val == 1: + else: + #obtain surnames + for surn in name.get_surname_list(): + if self.prefix and surn.get_prefix().upper().find(self.prefix) != -1: + valpref = 1 + if self.surn and surn.get_surname().upper().find(self.surn) != -1: + valsurn = 1 + if self.con and surn.get_connector().upper().find(self.con) != -1: + valcon = 1 + if self.patr and surn.get_origintype().value == NameOriginType.PATRONYMIC \ + and surn.get_surname().upper().find(self.patr) != -1: + valpatr = 1 + if val == 1 and valpref == 1 and valsurn == 1 and valcon == 1 and valpatr ==1: return True return False diff --git a/src/Filters/Rules/Person/_IncompleteNames.py b/src/Filters/Rules/Person/_IncompleteNames.py index 7fed919e3..a0912fcbd 100644 --- a/src/Filters/Rules/Person/_IncompleteNames.py +++ b/src/Filters/Rules/Person/_IncompleteNames.py @@ -48,8 +48,9 @@ class IncompleteNames(Rule): def apply(self,db,person): for name in [person.get_primary_name()] + person.get_alternate_names(): - if name.get_first_name() == "": - return True - if name.get_surname() == "": + if name.get_first_name().strip() == "": return True + for surn in name.get_surname_list(): + if surn.get_surname().strip() == "": + return True return False diff --git a/src/Filters/Rules/Person/_RegExpName.py b/src/Filters/Rules/Person/_RegExpName.py index 5a0cde75a..a39f76481 100644 --- a/src/Filters/Rules/Person/_RegExpName.py +++ b/src/Filters/Rules/Person/_RegExpName.py @@ -59,8 +59,8 @@ class RegExpName(Rule): def apply(self,db,person): for name in [person.get_primary_name()] + person.get_alternate_names(): - for field in [name.first_name, name.surname, name.suffix, name.title, - name.prefix, name.patronymic, name.call]: + for field in [name.first_name, name.get_surname(), name.suffix, + name.title, name.nick, name.famnick, self.call]: if self.match.match(field): return True else: diff --git a/src/Filters/Rules/Person/_SearchName.py b/src/Filters/Rules/Person/_SearchName.py index 99e7b74eb..678eab7bd 100644 --- a/src/Filters/Rules/Person/_SearchName.py +++ b/src/Filters/Rules/Person/_SearchName.py @@ -49,12 +49,13 @@ class SearchName(Rule): category = _('General filters') def apply(self, db, person): - src = self.list[0].upper() + if not src: + return False for name in [person.get_primary_name()] + person.get_alternate_names(): - for field in [name.first_name, name.surname, name.suffix, name.title, - name.prefix, name.patronymic, name.call]: + for field in [name.first_name, name.get_surname(), name.suffix, + name.title, name.nick, name.famnick, self.call]: if src and field.upper().find(src) != -1: return True else: