Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index sortable work title field in solr #6697

Merged
merged 4 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions conf/solr/conf/managed-schema
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
<field name="has_fulltext" type="boolean"/>
<field name="title" type="text_en_splitting"/>
<field name="title_suggest" type="text_general" multiValued="false"/>
<field name="title_sort" type="text_title_sort" multiValued="false"/>
<field name="subtitle" type="text_en_splitting"/>
<field name="alternative_title" type="text_en_splitting" stored="false" multiValued="true"/>
<field name="alternative_subtitle" type="text_en_splitting" stored="false" multiValued="true"/>
Expand Down Expand Up @@ -272,6 +273,7 @@
<!-- TODO: Can we pare this down for performance and storage? -->

<copyField source="title" dest="title_suggest"/>
<copyField source="title" dest="title_sort"/>
<copyField source="publisher" dest="publisher_facet"/>
<copyField source="subject" dest="subject_facet"/>
<copyField source="place" dest="place_facet"/>
Expand Down Expand Up @@ -491,6 +493,18 @@
</analyzer>
</fieldType>

<!-- A text field that applies standard title sorting conventions to its content -->
<fieldType name="text_title_sort" class="solr.TextField" sortMissingLast="false" omitNorms="true">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory" />
<filter class="solr.TrimFilterFactory" />
<filter class="solr.PatternReplaceFilterFactory"
pattern="^(an? |the |l[aeo]s? |l'|de la |el |il |un[ae]? |du |de[imrst]? |das |ein |eine[mnrs]? |bir )(.*)" replacement="$2, $1" replace="all"
cdrini marked this conversation as resolved.
Show resolved Hide resolved
/>
</analyzer>
</fieldType>

<!-- A text field with defaults appropriate for English: it tokenizes with StandardTokenizer,
removes English stop words (lang/stopwords_en.txt), down cases, protects words from protwords.txt, and
finally applies Porter's stemming. The query time analyzer also applies synonyms from synonyms.txt. -->
Expand Down
3 changes: 2 additions & 1 deletion openlibrary/plugins/worksearch/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
'editions': 'edition_count desc',
'old': 'def(first_publish_year, 9999) asc',
'new': 'first_publish_year desc',
'title': 'title_sort asc',
'scans': 'ia_count desc',
# Classifications
'lcc_sort': 'lcc_sort asc',
Expand Down Expand Up @@ -830,7 +831,7 @@ def works_by_author(
elif sort.startswith('new'):
params.append(('sort', 'first_publish_year desc'))
elif sort.startswith('title'):
params.append(('sort', 'title asc'))
params.append(('sort', 'title_sort asc'))

facet_fields = [
"author_facet",
Expand Down
1 change: 1 addition & 0 deletions openlibrary/solr/solr_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
1 change: 1 addition & 0 deletions openlibrary/solr/types_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def generate():
'text_en_splitting': 'str',
'text_general': 'str',
'text_international': 'str',
'text_title_sort': 'str',
'boolean': 'bool',
}

Expand Down
4 changes: 4 additions & 0 deletions openlibrary/templates/type/author/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ <h2 class="collapse">

<form method="GET" class="olform pagesearchbox">
<input type="hidden" name="has_fulltext" value="true"/>
$if (query_param('sort')):
<input type="hidden" name="sort" value="$query_param('sort')"/>
$if (query_param('mode')):
<input type="hidden" name="mode" value="$query_param('mode')"/>
<input type="text" placeholder="Search $title Books" name="q" value="$(query_param('q', ''))"/>
<input type="submit"/>
</form>
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/templates/work_search.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<input type="radio" name="mode" value="printdisabled" id="mode-search-printdisabled" class="search-mode">
<label for="mode-search-printdisabled">$_('Print Disabled')</label>
</span>
$ 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:
Expand Down