Fixed get_person_handles(sort_index=True)

Before did not include first_name in sorting (thanks Paul!)

Also added rebuilding all order_by fields when rebuilding
secondaries.
This commit is contained in:
Doug Blank 2016-05-01 16:47:58 -04:00
parent 780a4be62c
commit c8f3c25d84
3 changed files with 76 additions and 12 deletions

View File

@ -2042,12 +2042,14 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
pa/matronymic not as they change for every generation!
returns a byte string
"""
if person.primary_name and person.primary_name.surname_list:
order_by = " ".join([x.surname for x in person.primary_name.surname_list if not
(int(x.origintype) in [NameOriginType.PATRONYMIC,
NameOriginType.MATRONYMIC]) ])
else:
order_by = ""
order_by = ""
if person.primary_name:
order_by_list = [surname.surname + " " + person.primary_name.first_name
for surname in person.primary_name.surname_list
if not (int(surname.origintype) in
[NameOriginType.PATRONYMIC,
NameOriginType.MATRONYMIC])]
order_by = " ".join(order_by_list)
return glocale.sort_key(order_by)
def _order_by_place_key(self, place):

View File

@ -116,9 +116,24 @@ def find_fullname(key, data):
Creating a fullname from raw data of a person, to use for sort and index
returns a byte string
"""
# data[3] -> primary_name
# data[3][4] -> primary given
# data[3][5] -> surname_list
# data[3][5][0] -> primary surnameobj
# data[3][5][0][0] -> primary surname
# data[3][5][0][1] -> primary surname prefix
# data[3][5][0][2] -> primary surname primary (bool)
# data[3][5][0][3] -> primary surname origin type
# data[3][5][0][4] -> primary surname connector
# [(surname + ' ' + given,
# surname prefix,
# surname primary,
# surname origin type,
# surname connector)]
fullname_data = [(data[3][5][0][0] + ' ' + data[3][4], # surname givenname
data[3][5][0][1], data[3][5][0][2],
data[3][5][0][3], data[3][5][0][4])]
# ignore if origin type is PATRONYMIC or MATRONYMIC
return __index_surname(fullname_data)
def find_surname(key, data):
@ -126,6 +141,7 @@ def find_surname(key, data):
Creating a surname from raw data of a person, to use for sort and index
returns a byte string
"""
# data[3][5] -> surname_list
return __index_surname(data[3][5])
def find_surname_name(key, data):

View File

@ -1227,6 +1227,7 @@ class DBAPI(DbGeneric):
def rebuild_secondary(self, update):
gstats = self.get_gender_stats()
self.genderStats = GenderStats(gstats)
## Rebuild place order_by:
self.dbapi.execute("""select blob_data from place;""")
row = self.dbapi.fetchone()
while row:
@ -1235,6 +1236,51 @@ class DBAPI(DbGeneric):
cur2 = self.dbapi.execute("""UPDATE place SET order_by = ? WHERE handle = ?;""",
[order_by, place.handle])
row = self.dbapi.fetchone()
## Rebuild person order_by:
self.dbapi.execute("""select blob_data from person;""")
row = self.dbapi.fetchone()
while row:
person = Person.create(pickle.loads(row[0]))
order_by = self._order_by_person_key(person)
cur2 = self.dbapi.execute("""UPDATE person SET order_by = ? WHERE handle = ?;""",
[order_by, person.handle])
row = self.dbapi.fetchone()
## Rebuild citation order_by:
self.dbapi.execute("""select blob_data from citation;""")
row = self.dbapi.fetchone()
while row:
citation = Citation.create(pickle.loads(row[0]))
order_by = self._order_by_citation_key(citation)
cur2 = self.dbapi.execute("""UPDATE citation SET order_by = ? WHERE handle = ?;""",
[order_by, citation.handle])
row = self.dbapi.fetchone()
## Rebuild source order_by:
self.dbapi.execute("""select blob_data from source;""")
row = self.dbapi.fetchone()
while row:
source = Source.create(pickle.loads(row[0]))
order_by = self._order_by_source_key(source)
cur2 = self.dbapi.execute("""UPDATE source SET order_by = ? WHERE handle = ?;""",
[order_by, source.handle])
row = self.dbapi.fetchone()
## Rebuild tag order_by:
self.dbapi.execute("""select blob_data from tag;""")
row = self.dbapi.fetchone()
while row:
tag = Tag.create(pickle.loads(row[0]))
order_by = self._order_by_tag_key(tag.name)
cur2 = self.dbapi.execute("""UPDATE tag SET order_by = ? WHERE handle = ?;""",
[order_by, tag.handle])
row = self.dbapi.fetchone()
## Rebuild media order_by:
self.dbapi.execute("""select blob_data from media;""")
row = self.dbapi.fetchone()
while row:
media = Media.create(pickle.loads(row[0]))
order_by = self._order_by_media_key(media)
cur2 = self.dbapi.execute("""UPDATE media SET order_by = ? WHERE handle = ?;""",
[order_by, media.handle])
row = self.dbapi.fetchone()
def has_handle_for_person(self, key):
if isinstance(key, bytes):