Repository: internetarchive/openlibrary

Issue:
Edition titles excluded from search
Edition titles seem to be excluded from search. Try doing a search for "Pippi Longstocking", for example. I think the average user would expect to find https://openlibrary.org/works/OL16249458W/Pippi_L%C3%A5ngstrump among results (title aliases should probably be searchable as well.)


Discussion:
Thanks for submitting this @seabelis!
Title search fails but All search finds it.
I think this also affects imports. Translations seem to be added as new works when imported rather than added to the existing edition. Would allowing aliases for work titles be 1) possible and 2) fix or improve the situation?
Relates to #1816
Bumping @seabelis comment, is giving works aliases possible/a fix to this situation? Authors have a `personal_name` and `alternate_names` field. Example: https://openlibrary.org/authors/OL31353A.json

@tfmorris Would it be computationally expensive for Solr to search for the work title field and the associated edition title field? Also, are you willing to be assignee for this issue?
@guyjeangilles We'd need to add the edition titles to a collected `title` field like we do for the `text` field that is used for the "All" search. Generally speaking Solr can handle almost anything you can dream up in a pretty efficient manner, so that's not a worry.

Rather than investing in this though, I'd prefer to just make editions searchable and this will fall out of that naturally.

Also, as was mentioned earlier, the "All" search: https://openlibrary.org/search?q=pippi+longstockings
will find the work, even though the title search: https://openlibrary.org/search?q=title%3A+%22pippi+longstockings%22
doesn't include the primary work.
Sounds like this should be fixed by #2246. Assigning @cdrini per slack discussions since he's the assignee of the PR
It's actually #2064 that will address this problem.

Resolving patch:
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
@@ -105,7 +105,7 @@
     'by': 'author_name',
     'publishers': 'publisher',
     'subtitle': 'alternative_subtitle',
-    # **({'title': 'alternative_title'} if get_solr_next() else {}),
+    'title': 'alternative_title',
     'work_subtitle': 'subtitle',
     'work_title': 'title',
     # "Private" fields
@@ -495,10 +495,7 @@ def run_solr_query(
         if use_dismax:
             params.append(('q', ' '.join(q_list)))
             params.append(('defType', 'dismax'))
-            if False:  # get_solr_next():
-                params.append(('qf', 'text alternative_title^20 author_name^20'))
-            else:
-                params.append(('qf', 'text title^20 author_name^20'))
+            params.append(('qf', 'text alternative_title^20 author_name^20'))
             params.append(('bf', 'min(100,edition_count)'))
         else:
             params.append(('q', ' '.join(q_list + ['_val_:"sqrt(edition_count)"^10'])))
diff --git a/openlibrary/solr/update_work.py b/openlibrary/solr/update_work.py
--- a/openlibrary/solr/update_work.py
+++ b/openlibrary/solr/update_work.py
@@ -559,14 +559,13 @@ def add_list(name, values):
         if number_of_pages_median:
             add('number_of_pages_median', number_of_pages_median)
 
-        if get_solr_next():
-            add_list(
-                "editions",
-                [
-                    build_edition_data(ed, ia_metadata.get(ed.get('ocaid', '').strip()))
-                    for ed in editions
-                ],
-            )
+        add_list(
+            "editions",
+            [
+                build_edition_data(ed, ia_metadata.get(ed.get('ocaid', '').strip()))
+                for ed in editions
+            ],
+        )
 
         field_map = [
             ('lccn', 'lccn'),
@@ -612,11 +611,6 @@ def get_edition_ddcs(ed: dict):
 
         d |= self.get_ebook_info(editions, ia_metadata)
 
-        # See https://github.com/internetarchive/openlibrary/issues/6836
-        # This was half-implemented
-        if 'ia_collection' in d and not get_solr_next():
-            del d['ia_collection']
-
         return d
 
     @staticmethod
@@ -684,11 +678,10 @@ def get_ebook_info(
         ebook_info["ebook_count_i"] = sum(
             1 for e in solr_editions if e.ebook_access > bp.EbookAccess.UNCLASSIFIED
         )
-        if get_solr_next():
-            ebook_info["ebook_access"] = max(
-                (e.ebook_access for e in solr_editions),
-                default=bp.EbookAccess.NO_EBOOK,
-            ).to_solr_str()
+        ebook_info["ebook_access"] = max(
+            (e.ebook_access for e in solr_editions),
+            default=bp.EbookAccess.NO_EBOOK,
+        ).to_solr_str()
         ebook_info["has_fulltext"] = any(e.has_fulltext for e in solr_editions)
         ebook_info["public_scan_b"] = any(e.public_scan_b for e in solr_editions)
 


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
@@ -64,7 +64,7 @@ def test_sorted_work_editions():
     'Field aliases': (
         'title:food rules by:pollan',
         [
-            {'field': 'title', 'value': 'food rules'},
+            {'field': 'alternative_title', 'value': 'food rules'},
             {'field': 'author_name', 'value': 'pollan'},
         ],
     ),
@@ -78,7 +78,7 @@ def test_sorted_work_editions():
     'Quotes': (
         'title:"food rules" author:pollan',
         [
-            {'field': 'title', 'value': '"food rules"'},
+            {'field': 'alternative_title', 'value': '"food rules"'},
             {'field': 'author_name', 'value': 'pollan'},
         ],
     ),
@@ -86,7 +86,7 @@ def test_sorted_work_editions():
         'query here title:food rules author:pollan',
         [
             {'field': 'text', 'value': 'query here'},
-            {'field': 'title', 'value': 'food rules'},
+            {'field': 'alternative_title', 'value': 'food rules'},
             {'field': 'author_name', 'value': 'pollan'},
         ],
     ),
@@ -100,7 +100,7 @@ def test_sorted_work_editions():
         'title:flatland:a romance of many dimensions',
         [
             {
-                'field': 'title',
+                'field': 'alternative_title',
                 'value': r'flatland\:a romance of many dimensions',
             },
         ],
@@ -251,7 +251,7 @@ def test_build_q_list():
     }
     expect = (
         [
-            'title:((Holidays are Hell))',
+            'alternative_title:((Holidays are Hell))',
             'author_name:((Kim Harrison))',
             'OR',
             'author_name:((Lynsay Sands))',
@@ -259,7 +259,7 @@ def test_build_q_list():
         False,
     )
     query_fields = [
-        {'field': 'title', 'value': '(Holidays are Hell)'},
+        {'field': 'alternative_title', 'value': '(Holidays are Hell)'},
         {'field': 'author_name', 'value': '(Kim Harrison)'},
         {'op': 'OR'},
         {'field': 'author_name', 'value': '(Lynsay Sands)'},