# Name sort order override?

**URL:** <https://gramps.discourse.group/t/name-sort-order-override/1145>\
**Category:** Help\
**Tags:** name-display, name-editor, name-sort, hacks\
**Created:** [January 22, 2021, 4:39pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145 "2021-01-22T16:39:19Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [January 22, 2021, 4:39pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/1 "2021-01-22T16:39:19Z")

</div>

Gramps 5.1.3 on Win10

Names are a complicated problem since the name display name is a concatenated form. I have my Display Preferences for the name format set to:  
`Title Surname, “Nickname” Given, Suffix`

ex. _Sgt. Horn, “Abram” Abraham, Sr._

This is excellent for clarity. However, I need it to sort without the Title and without the Nickname:  
`Surname, Given, Suffix`

Is there a way to set Sort Order and Display differently?

---

<div class="post-metadata">

**Author:** ![GeorgeWilmes](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@GeorgeWilmes](https://gramps.discourse.group/u/GeorgeWilmes)\
**Post date:** [January 22, 2021, 4:58pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/2 "2021-01-22T16:58:46Z")

</div>

Please see (and vote for!) feature request [11788 : Sorting of people with grouped surnames](https://gramps-project.org/bugs/view.php?id=11788#c59726).

> Nick  
> You really just want to change the sort order in the person tree view.
> 
> Try adding the following code to the end of the `gramps/gui/views/treemodels/`[`peoplemodel.py`](https://github.com/gramps-project/gramps/blob/master/gramps/gui/views/treemodels/peoplemodel.py) file:

```python

    def sort_name(self, data):
        handle = data[0]
        cached, name = self.get_cached_value(handle, "SORT_NAME")
        if not cached:
            name = name_displayer.name_formats[2][4](data[COLUMN_NAME])
            self.set_cached_value(handle, "SORT_NAME", name)
        return name

```

> > the added lines override the sort\_name method that PeopleTreeModel inherited from the PeopleBaseModel, and that they reference name\_formats[2][4] instead of raw\_sorted\_name?
> > 
> > So my only question is why “[2][4]” and whether having those values hard-coded may cause me any troubles later on.
> 
> Yes. It overrides the sort order for the person tree view.  
> [2] refers to one of the pre-defined name formats (First name, Last name).  
> [4] refers to the type of data passed to the function - raw in this case.
> 
> These values are unlikely to change.
> 
> It would have been better to use constants, but this is just a quick workaround before we come up with a more permanent solution.

---

<div class="post-metadata">

**Author:** ![DaveSch](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/davesch/32/40_2.png) [@DaveSch](https://gramps.discourse.group/u/DaveSch)\
**Post date:** [January 22, 2021, 5:03pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/3 "2021-01-22T17:03:36Z")

</div>

You need to set a name sort override for each occurrence in your People list.

In the Person’s edit window, under the Names tab, edit the name with the [Name Editor](https://gramps-project.org/wiki/index.php?title=Gramps_5.1_Wiki_Manual_-_Entering_and_editing_data%3A_detailed_-_part_3#Name_Editor).

Change the **Sort as** from the default to another option. The same functionality allows to override the **Display as**. Any custom option you select can be created using the Preferences’ [Display Name Editor](https://gramps-project.org/wiki/index.php?title=Gramps_5.1_Wiki_Manual_-_Settings#Display_Name_Editor)

 ![name sort override](https://global.discourse-cdn.com/free1/uploads/gramps/original/1X/58df745e469de09eeed12885589d0d3969c2d755.png) .

---

<div class="post-metadata">

**Author:** ![DaveSch](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/davesch/32/40_2.png) [@DaveSch](https://gramps.discourse.group/u/DaveSch)\
**Post date:** [January 22, 2021, 5:14pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/4 "2021-01-22T17:14:27Z")

</div>

From the same feature request, I offered up having the Default Display be different than the Default Sort.

My default display is `Title Given "Nickname" Surname, Suffix`.

I am also a heavy user of the Surname Override. So for most cases, this works great where in the Grouped name list `John Clark` shows next to `John Clarke`. But I do have to override the sort when there are Titles so that `Colonel John Clark` displays with his kinsmen.

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [January 22, 2021, 5:18pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/5 "2021-01-22T17:18:24Z")

</div>

> [@DaveSch](#):
>
> You need to set a name sort override for each occurrence in your People list.

Ouch! That’s fine for exception handling but it shouldn’t be the General Rule.

I suppose if I could do a mass update to a filtered list (like anyone with a Title or a Nickname) that it would work.

Otherwise, it cannot be a viable option.

---

<div class="post-metadata">

**Author:** ![DaveSch](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/davesch/32/40_2.png) [@DaveSch](https://gramps.discourse.group/u/DaveSch)\
**Post date:** [January 22, 2021, 5:25pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/6 "2021-01-22T17:25:08Z")

</div>

The first time I started with how I currently display and sort names with these exceptions, I used an uncompressed xml export and did a global search and replace based upon the Name’s Type. These exceptions are stored with the type in the xml. But this is not a solution I would recommend to the casual user. Editing the xml file is fraught with danger of corrupting the file.

And this only works if these exceptions have their own name Type that need to set. I use two, **Title** and **Rank**.

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [January 22, 2021, 6:38pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/7 "2021-01-22T18:38:06Z")

</div>

Would a calculated field reduce the number of sort order exceptions?

Say, for instance, what if Gramps had a feature to generate a value and store it for sort order?

[SoundEx](https://www.gramps-project.org/wiki/index.php/Gramps_5.1_Wiki_Manual_-_Gramplets#SoundEx) (not very good for internationalized tool), [Metaphone or Double Metaphone](https://pypi.org/project/Metaphone/) might alleviate the homonym issue.

Here are some interesting pages:

- [An Overview of Fuzzy Name Matching Techniques](https://www.rosette.com/blog/overview-fuzzy-name-matching-techniques/)
- [Python Tutorial: Fuzzy Name Matching Algorithms](https://towardsdatascience.com/python-tutorial-fuzzy-name-matching-algorithms-7a6f43322cc5)

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [January 22, 2021, 6:50pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/8 "2021-01-22T18:50:55Z")

</div>

> [@GeorgeWilmes](#):
>
> Please see (and vote for!) feature request [11788](https://gramps-project.org/bugs/view.php?id=11788#c59726)

That’s interesting.

But it looks like it could use some fleshing out. I was recently reminded that voting has no effect in feature development.

If, on the other hand, we can pique the interest of a developer (by exploring the concept fully with intriguing examples of how the feature would be broadly worthwhile) that might get someone to invest the time.

If we do enough of the homework, then someone familiar with the Gramps API can implement it with fewer hours of investment.

---

<div class="post-metadata">

**Author:** ![GeorgeWilmes](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@GeorgeWilmes](https://gramps.discourse.group/u/GeorgeWilmes)\
**Post date:** [January 22, 2021, 7:03pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/9 "2021-01-22T19:03:42Z")

</div>

> [@emyoulation](#):
>
> it looks like it could use some fleshing out.

I tried to be very specific. If I were any good at making a UI mockup, I would do so. I would like to make the request as clear and simple as possible. What details do you feel are missing?

---

<div class="post-metadata">

**Author:** ![DaveSch](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/davesch/32/40_2.png) [@DaveSch](https://gramps.discourse.group/u/DaveSch)\
**Post date:** [January 22, 2021, 7:12pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/10 "2021-01-22T19:12:06Z")

</div>

The way I understand @GeorgeWilmes 's request ([11788](https://gramps-project.org/bugs/view.php?id=11788#c59726)) is at the time a Display Name is created, a Sort order can be created for that display option. A tandem setting…

Display `Given Surname, Suffix` can have the preset sort `Surname, Given Suffix`. The problem with `Given Surname, Suffix` as a sort in the Grouped Name list, `John B Clark` sorts before just plain `John Clark`. Not bad, but not ideal. This allows a natural Display option and a proper sort.

But if I understand correctly, instead of `Surname, Given Suffix` as a sort add an option for `GroupAsSurname, Given Suffix` to account for the Surname override.

---

<div class="post-metadata">

**Author:** ![GeorgeWilmes](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@GeorgeWilmes](https://gramps.discourse.group/u/GeorgeWilmes)\
**Post date:** [January 22, 2021, 7:29pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/11 "2021-01-22T19:29:01Z")

</div>

> [@DaveSch](#):
>
> at the time a Display Name is created, a Sort order can be created for that display option. A tandem setting

Yes, and as I explained in that comment in the issue, the grouped surname was just my particular use case, but the proposed solution is more generic. If others among you have some specific use cases that would benefit from the same general solution, please share them in the issue. Thanks.

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [January 22, 2021, 9:12pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/12 "2021-01-22T21:12:59Z")

</div>

> [@DaveSch](#):
>
> heavy user of the Surname Override

Do you think that there ought to be an indicator for when an Override is applied to a row? So that a person knows to open the Alternate Name editor? Perhaps with a rollover that displays the override?

---

<div class="post-metadata">

**Author:** ![DaveSch](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/davesch/32/40_2.png) [@DaveSch](https://gramps.discourse.group/u/DaveSch)\
**Post date:** [January 22, 2021, 9:52pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/13 "2021-01-22T21:52:43Z")

</div>

When I use the override I set all applicable names so both “Clark” and “Clarke” are set to “Clark (Clarke)”. In the Grouped lists it is very noticeable. Not so noticeable in other areas. I have filed a Feature to have the global Group As display in the name list along when an override is done on a case by case basis. They use different methods to affect the change.

[https://gramps-project.org/bugs/view.php?id=10319](https://gramps-project.org/bugs/view.php?id=10319)

Other cues? Haven’t thought about it (or the need).

![grouped names](https://global.discourse-cdn.com/free1/uploads/gramps/original/1X/a00e398e088145bc6fec709978622bb9c7d72e91.png)

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [May 3, 2023, 4:33pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/16 "2023-05-03T16:33:57Z")

</div>

I wonder if there is a way to search for Names with Grouping, displaying and Sorting overrides? Then a way to clear/set selected overrides en masse?

@kku , can SuperTool address these preferred and alternative name attributes? Experiments so far all return AttributeError messages. So obviously I should not be using the labels as listed in the [SuperTool Help](https://github.com/Taapeli/isotammi-addons/blob/master/source/SuperTool/README.md#help-feature) or [Data Model](https://www.gramps-project.org/wiki/index.php/Gramps_Data_Model) documentation.

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [May 3, 2023, 4:55pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/17 "2023-05-03T16:55:15Z")

</div>

> [@GeorgeWilmes](#):
>
> Please see (and vote for!) feature request [11788](https://gramps-project.org/bugs/view.php?id=11788#c59726)

Note that the Master branch and PRs do not include a Sort enhancement for the People Tree. And none of the Bugs point towards a PR despite having a proposed solution in the comments. So it probably isn’t on the 5.2 roadmap.

And this sorting improvement doesn’t address sub-sorting namesakes (and recurrent given names in a line) in either the Tree or Flat Person lists. (Differentiating between eponyms and a multitude of Namesakes is a common difficulty in Genealogy. Sub-sorting by birth/death year or generation is a typical ordering in indices.)

---

<div class="post-metadata">

**Author:** ![GeorgeWilmes](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@GeorgeWilmes](https://gramps.discourse.group/u/GeorgeWilmes)\
**Post date:** [May 3, 2023, 5:27pm UTC](https://gramps.discourse.group/t/name-sort-order-override/1145/18 "2023-05-03T17:27:12Z")

</div>

> [@emyoulation](#):
>
> So it probably isn’t on the 5.2 roadmap.

That’s OK with me, I have a fix that works for my needs thanks to Nick’s comments in the issue.

> [@emyoulation](#):
>
> And this sorting improvement doesn’t address sub-sorting namesakes

Right, that should be a separate feature request, if there isn’t one already.
