Repository: internetarchive/openlibrary

Issue:
Display author date(s) with name for librarians
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
Author disambiguation is difficult and even more difficult when the author names all look the same for different identities. To see precisely which author is associated with a work, one must either click the author to view the profile or go into edit mode and use the author selection box.

### Describe the problem that you'd like solved
<!-- A clear and concise description of what you want to happen. -->
Authors should display their associated years to make this task less cumbersome. 

### Proposal & Constraints
<!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->

<!-- Which suggestions or requirements should be considered for how feature needs to appear or be implemented? -->
Only the year is necessary, any other date information does not need to be displayed.
This should be a librarian-feature only.

### Additional context
<!-- Add any other context or screenshots about the feature request here. -->

For example, these are two different Stephen Kings:
<img width="454" alt="Screenshot 2023-04-19 at 09 02 16" src="https://user-images.githubusercontent.com/17739465/232992930-9b99cdaf-2e84-491f-bea3-ec4457b18a32.png">
<img width="484" alt="Screenshot 2023-04-19 at 09 02 38" src="https://user-images.githubusercontent.com/17739465/232993031-8c846762-0dee-4d60-9c83-b10100d4be65.png">

A display like this would make disambiguation much easier and less time-consuming:
<img width="314" alt="Screenshot 2023-04-19 at 09 04 35" src="https://user-images.githubusercontent.com/17739465/232993643-55f2d88f-ff8f-487b-8931-aaa447f54acf.png">
<img width="466" alt="Screenshot 2023-04-19 at 09 04 47" src="https://user-images.githubusercontent.com/17739465/232993680-717724ab-907f-473c-9c4a-048575328ed1.png">

### Stakeholders
<!-- @ tag stakeholders of this bug -->





Discussion:
@seabelis 
Why librarian-feature only? Many of us mortals have struggled with this problem.
@LeadSongDog @mekarpeles indicated that this is preferred.
> @mekarpeles indicated that this is preferred.

Preferred by a representative sample of customers? I missed the fact that this was spec'd as librarian only and agree that it is generally useful. What is the down side to having more information available to everyone?
The logic is that this area of the page is already featuring a lot of information. The downside to having more information _visible_ (note the information is/was always _available_) is that it can make it difficult to realize what information to focus on, and potentially look cluttered. My guess would be that a very large chunk of the users accessing this page would not have their experience improved by having that extra information in one of the most prominent pieces of realestate on this page, and in fact it would defer their attention from information that might be more meaningful to them.
@cdrini 
"Available" only in the sense that the Lost Ark was available to Indiana Jones with sufficient motivation, persistence, and willingness to risk bending rules.  A library's task is to make correct information readily accessible.  Perhaps a compromise then: don’t show it on small screens, where errors are unlikely to be corrected anyhow. Otherwise we have no hope of ever prying apart all the John Smith misattributions.
Working on it

Resolving patch:
diff --git a/openlibrary/core/helpers.py b/openlibrary/core/helpers.py
--- a/openlibrary/core/helpers.py
+++ b/openlibrary/core/helpers.py
@@ -50,6 +50,7 @@
     "bookreader_host",
     "private_collections",
     "private_collection_in",
+    "extract_year",
     # functions imported from elsewhere
     "parse_datetime",
     "safeint",
@@ -324,6 +325,14 @@ def private_collection_in(collections):
     return any(x in private_collections() for x in collections)
 
 
+def extract_year(input):
+    """Extracts the year from an author's birth or death date."""
+    if result := re.search(r'\d{4}', input):
+        return result.group()
+    else:
+        return ''
+
+
 def _get_helpers():
     _globals = globals()
     return web.storage((k, _globals[k]) for k in __all__)
diff --git a/openlibrary/plugins/worksearch/code.py b/openlibrary/plugins/worksearch/code.py
--- a/openlibrary/plugins/worksearch/code.py
+++ b/openlibrary/plugins/worksearch/code.py
@@ -338,6 +338,8 @@ def get_doc(doc: SolrDocument):
                 key=key,
                 name=name,
                 url=f"/authors/{key}/{urlsafe(name or 'noname')}",
+                birth_date=doc.get('birth_date', None),
+                death_date=doc.get('death_date', None),
             )
             for key, name in zip(doc.get('author_key', []), doc.get('author_name', []))
         ],


Test patch:
diff --git a/openlibrary/plugins/worksearch/tests/test_worksearch.py b/openlibrary/plugins/worksearch/tests/test_worksearch.py
--- a/openlibrary/plugins/worksearch/tests/test_worksearch.py
+++ b/openlibrary/plugins/worksearch/tests/test_worksearch.py
@@ -47,6 +47,8 @@ def test_get_doc():
                         'key': 'OL218224A',
                         'name': 'Alan Freedman',
                         'url': '/authors/OL218224A/Alan_Freedman',
+                        'birth_date': None,
+                        'death_date': None,
                     }
                 )
             ],