From 91fc0f36787c4cb0fc7f84ca59486d0316691b18 Mon Sep 17 00:00:00 2001 From: "Mark F. Heiman" Date: Wed, 22 Jun 2022 10:17:16 -0500 Subject: [PATCH 1/4] Added title_sortable field --- conf/solr/conf/managed-schema | 13 +++++++++++++ openlibrary/plugins/worksearch/code.py | 5 +++-- openlibrary/solr/update_work.py | 1 + openlibrary/templates/search/sort_options.html | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/conf/solr/conf/managed-schema b/conf/solr/conf/managed-schema index 51e58cb8916..9910fc3014d 100644 --- a/conf/solr/conf/managed-schema +++ b/conf/solr/conf/managed-schema @@ -142,6 +142,7 @@ + @@ -491,6 +492,18 @@ + + + + + + + + + + diff --git a/openlibrary/plugins/worksearch/code.py b/openlibrary/plugins/worksearch/code.py index 73029717133..54d91a3123b 100644 --- a/openlibrary/plugins/worksearch/code.py +++ b/openlibrary/plugins/worksearch/code.py @@ -116,6 +116,7 @@ 'editions': 'edition_count desc', 'old': 'def(first_publish_year, 9999) asc', 'new': 'first_publish_year desc', + 'alpha': 'title_sortable asc', 'scans': 'ia_count desc', # Classifications 'lcc_sort': 'lcc_sort asc', @@ -829,8 +830,8 @@ def works_by_author( params.append(('sort', 'first_publish_year asc')) elif sort.startswith('new'): params.append(('sort', 'first_publish_year desc')) - elif sort.startswith('title'): - params.append(('sort', 'title asc')) + elif sort.startswith('alpha'): + params.append(('sort', 'title_sortable asc')) facet_fields = [ "author_facet", diff --git a/openlibrary/solr/update_work.py b/openlibrary/solr/update_work.py index 8367b0cb6e2..9c8747d4fd6 100644 --- a/openlibrary/solr/update_work.py +++ b/openlibrary/solr/update_work.py @@ -552,6 +552,7 @@ def add_list(name, values): add('type', 'work') add('seed', BaseDocBuilder().compute_seeds(w, editions)) add('title', w.get('title')) + add('title_sortable', w.get('title')) add('subtitle', w.get('subtitle')) add_list("alternative_title", self.get_alternate_titles((w, *editions))) diff --git a/openlibrary/templates/search/sort_options.html b/openlibrary/templates/search/sort_options.html index 35ce1559fa2..fb2b419a027 100644 --- a/openlibrary/templates/search/sort_options.html +++ b/openlibrary/templates/search/sort_options.html @@ -7,6 +7,7 @@ { 'sort': 'editions', 'name': _("Most Editions"), 'ga_key': 'Editions' }, { 'sort': 'old', 'name': _("First Published"), 'ga_key': 'Old' }, { 'sort': 'new', 'name': _("Most Recent"), 'ga_key': 'New' }, + { 'sort': 'alpha', 'name': _("Alphabetical"), 'ga_key': 'Alphabetical' }, { 'sort': 'random', 'name': _("Random"), 'ga_key': 'Random', 'selected': selected_sort and selected_sort.startswith('random') }, ] $for sort_option in sort_options: From 8e66e8cf78deb0553aefff2a352ba435ec449ec8 Mon Sep 17 00:00:00 2001 From: "Mark F. Heiman" Date: Wed, 22 Jun 2022 16:59:36 -0500 Subject: [PATCH 2/4] Make sort preference sticky --- openlibrary/templates/type/author/view.html | 4 ++++ openlibrary/templates/work_search.html | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/openlibrary/templates/type/author/view.html b/openlibrary/templates/type/author/view.html index bb06f4b00d7..f57de91f42e 100644 --- a/openlibrary/templates/type/author/view.html +++ b/openlibrary/templates/type/author/view.html @@ -119,6 +119,10 @@

+ $if (query_param('sort')): + + $if (query_param('mode')): +
diff --git a/openlibrary/templates/work_search.html b/openlibrary/templates/work_search.html index 1a7e0130372..2d8f4348252 100644 --- a/openlibrary/templates/work_search.html +++ b/openlibrary/templates/work_search.html @@ -81,7 +81,7 @@ - $ sticky = set(['author_facet', 'language', 'first_publish_year', 'publisher_facet', 'subject_facet', 'person_facet', 'place_facet', 'time_facet', 'public_scan_b']) + $ sticky = set(['sort', 'author_facet', 'language', 'first_publish_year', 'publisher_facet', 'subject_facet', 'person_facet', 'place_facet', 'time_facet', 'public_scan_b']) $for k, values in param.items(): $if k not in sticky: From 39370d7304720c142c4f3162a7efcc522e7669b8 Mon Sep 17 00:00:00 2001 From: "Mark F. Heiman" Date: Tue, 28 Jun 2022 16:09:11 -0500 Subject: [PATCH 3/4] title_sortable -> title_sort; added copyfield --- conf/solr/conf/managed-schema | 3 ++- openlibrary/plugins/worksearch/code.py | 6 +++--- openlibrary/solr/solr_types.py | 1 + openlibrary/solr/types_generator.py | 1 + openlibrary/solr/update_work.py | 1 - openlibrary/templates/search/sort_options.html | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/conf/solr/conf/managed-schema b/conf/solr/conf/managed-schema index 9910fc3014d..f6e50bceccd 100644 --- a/conf/solr/conf/managed-schema +++ b/conf/solr/conf/managed-schema @@ -142,7 +142,7 @@ - + @@ -273,6 +273,7 @@ + diff --git a/openlibrary/plugins/worksearch/code.py b/openlibrary/plugins/worksearch/code.py index 54d91a3123b..daf464d7192 100644 --- a/openlibrary/plugins/worksearch/code.py +++ b/openlibrary/plugins/worksearch/code.py @@ -116,7 +116,7 @@ 'editions': 'edition_count desc', 'old': 'def(first_publish_year, 9999) asc', 'new': 'first_publish_year desc', - 'alpha': 'title_sortable asc', + 'title': 'title_sort asc', 'scans': 'ia_count desc', # Classifications 'lcc_sort': 'lcc_sort asc', @@ -830,8 +830,8 @@ def works_by_author( params.append(('sort', 'first_publish_year asc')) elif sort.startswith('new'): params.append(('sort', 'first_publish_year desc')) - elif sort.startswith('alpha'): - params.append(('sort', 'title_sortable asc')) + elif sort.startswith('title'): + params.append(('sort', 'title_sort asc')) facet_fields = [ "author_facet", diff --git a/openlibrary/solr/solr_types.py b/openlibrary/solr/solr_types.py index 4fcd537b0a6..20be3bb38b4 100644 --- a/openlibrary/solr/solr_types.py +++ b/openlibrary/solr/solr_types.py @@ -10,6 +10,7 @@ class SolrDocument(TypedDict): has_fulltext: Optional[bool] title: Optional[str] title_suggest: Optional[str] + title_sort: Optional[str] subtitle: Optional[str] alternative_title: Optional[list[str]] alternative_subtitle: Optional[list[str]] diff --git a/openlibrary/solr/types_generator.py b/openlibrary/solr/types_generator.py index 4e8a508c124..16b5b285b14 100755 --- a/openlibrary/solr/types_generator.py +++ b/openlibrary/solr/types_generator.py @@ -27,6 +27,7 @@ def generate(): 'text_en_splitting': 'str', 'text_general': 'str', 'text_international': 'str', + 'text_title_sort': 'str', 'boolean': 'bool', } diff --git a/openlibrary/solr/update_work.py b/openlibrary/solr/update_work.py index 9c8747d4fd6..8367b0cb6e2 100644 --- a/openlibrary/solr/update_work.py +++ b/openlibrary/solr/update_work.py @@ -552,7 +552,6 @@ def add_list(name, values): add('type', 'work') add('seed', BaseDocBuilder().compute_seeds(w, editions)) add('title', w.get('title')) - add('title_sortable', w.get('title')) add('subtitle', w.get('subtitle')) add_list("alternative_title", self.get_alternate_titles((w, *editions))) diff --git a/openlibrary/templates/search/sort_options.html b/openlibrary/templates/search/sort_options.html index fb2b419a027..d37fe2be81f 100644 --- a/openlibrary/templates/search/sort_options.html +++ b/openlibrary/templates/search/sort_options.html @@ -7,7 +7,7 @@ { 'sort': 'editions', 'name': _("Most Editions"), 'ga_key': 'Editions' }, { 'sort': 'old', 'name': _("First Published"), 'ga_key': 'Old' }, { 'sort': 'new', 'name': _("Most Recent"), 'ga_key': 'New' }, - { 'sort': 'alpha', 'name': _("Alphabetical"), 'ga_key': 'Alphabetical' }, + { 'sort': 'title', 'name': _("Alphabetical"), 'ga_key': 'Alphabetical' }, { 'sort': 'random', 'name': _("Random"), 'ga_key': 'Random', 'selected': selected_sort and selected_sort.startswith('random') }, ] $for sort_option in sort_options: From 795971681d1c9bc93747685b2994ceae04677bd7 Mon Sep 17 00:00:00 2001 From: "Mark F. Heiman" Date: Tue, 28 Jun 2022 16:39:01 -0500 Subject: [PATCH 4/4] Removed title sort option from this branch --- openlibrary/templates/search/sort_options.html | 1 - 1 file changed, 1 deletion(-) diff --git a/openlibrary/templates/search/sort_options.html b/openlibrary/templates/search/sort_options.html index d37fe2be81f..35ce1559fa2 100644 --- a/openlibrary/templates/search/sort_options.html +++ b/openlibrary/templates/search/sort_options.html @@ -7,7 +7,6 @@ { 'sort': 'editions', 'name': _("Most Editions"), 'ga_key': 'Editions' }, { 'sort': 'old', 'name': _("First Published"), 'ga_key': 'Old' }, { 'sort': 'new', 'name': _("Most Recent"), 'ga_key': 'New' }, - { 'sort': 'title', 'name': _("Alphabetical"), 'ga_key': 'Alphabetical' }, { 'sort': 'random', 'name': _("Random"), 'ga_key': 'Random', 'selected': selected_sort and selected_sort.startswith('random') }, ] $for sort_option in sort_options: