Repository: internetarchive/openlibrary

Issue:
Fix multi-word search
Fix MULTI-KEYWORD search in AUTHORS PAGE.


### Testing
<!-- Steps for reviewer to reproduce/verify what this PR does/fixes. -->
Seacrch for a book using more than 1 word in authors page.
### Screenshot
<!-- If this PR touches UI, please post evidence (screenshots) of it behaving correctly. -->

![before1](https://user-images.githubusercontent.com/53273271/101183060-f76aa600-3674-11eb-8ed6-339fa879db91.png)


![after1](https://user-images.githubusercontent.com/53273271/101183099-05b8c200-3675-11eb-839f-d42d5779d64a.png)

<!-- @ tag stakeholders of this bug -->
@mekarpeles  @tabshaikh 
Lists widget erroring and not rendering on non-author pages
Seems possible related to https://github.com/internetarchive/openlibrary/releases/tag/deploy-2020-11-17

`/opt/openlibrary/deploys/openlibrary/bc485c1/openlibrary/templates/lists/widget.html: error in processing template: AttributeError: 'NoneType' object has no attribute 'key' (falling back to default template)`

Sentry: 
### Evidence / Screenshot (if possible)
![image](https://user-images.githubusercontent.com/6251786/99467179-dc293800-290b-11eb-9cd5-2b75ce3fe19c.png)

### Relevant url?
e.g. https://openlibrary.org/authors/OL550077A/Robert_E._Staub

### Details

- **Logged in (Y/N)?** Y
- **Browser type/version?** FF82
- **Operating system?** Win10
- **Environment (prod/dev/local)?** prod
<!-- If not sure, put prod -->

### Proposal & Constraints
<!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->

### Related files
<!-- Files related to this issue; this is super useful for new contributors who might want to help! If you're not sure, leave this blank; a maintainer will add them. -->

### Stakeholders
@mekarpeles 

Fix multi-word search
Fix MULTI-KEYWORD search in AUTHORS PAGE.


### Testing
<!-- Steps for reviewer to reproduce/verify what this PR does/fixes. -->
Seacrch for a book using more than 1 word in authors page.
### Screenshot
<!-- If this PR touches UI, please post evidence (screenshots) of it behaving correctly. -->

![before1](https://user-images.githubusercontent.com/53273271/101183060-f76aa600-3674-11eb-8ed6-339fa879db91.png)


![after1](https://user-images.githubusercontent.com/53273271/101183099-05b8c200-3675-11eb-839f-d42d5779d64a.png)

<!-- @ tag stakeholders of this bug -->
@mekarpeles  @tabshaikh 


Discussion:
https://travis-ci.com/github/internetarchive/openlibrary/jobs/454470742#L443
When you type `make lint-diff` on your command line do you get output like
https://travis-ci.com/github/internetarchive/openlibrary/jobs/454576741#L443
Can not replicate this on my Mac.
![Screen Shot 2020-11-18 at 11 58 10](https://user-images.githubusercontent.com/3709715/99522250-b0eb2b00-2995-11eb-97e8-4d77ce4dae2e.png)

I also cannot replicate it on Linux/Chrome (logged in or logged out), Linux/Firefox (logged out), OS X/Chrome (logged in or logged out), or OS X/Firefox (logged out).
https://travis-ci.com/github/internetarchive/openlibrary/jobs/454470742#L443
When you type `make lint-diff` on your command line do you get output like
https://travis-ci.com/github/internetarchive/openlibrary/jobs/454576741#L443

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
@@ -637,33 +637,46 @@ def works_by_author(akey, sort='editions', page=1, rows=100, has_fulltext=False,
         q = query
 
     offset = rows * (page - 1)
-    fields = ['key', 'author_name', 'author_key', 'title', 'subtitle',
-        'edition_count', 'ia', 'cover_edition_key', 'has_fulltext', 'language',
-        'first_publish_year', 'public_scan_b', 'lending_edition_s', 'lending_identifier_s',
-        'ia_collection_s', 'cover_i']
-    fl = ','.join(fields)
-    fq = 'author_key:' + akey
+    params = [
+        ('fq', 'author_key:' + akey),
+        ('fq', 'type:work'),
+        ('q', q),
+        ('start', offset),
+        ('rows', rows),
+        ('fl', ','.join([
+            'key', 'author_name', 'author_key', 'title', 'subtitle', 'edition_count',
+            'ia', 'cover_edition_key', 'has_fulltext', 'language', 'first_publish_year',
+            'public_scan_b', 'lending_edition_s', 'lending_identifier_s',
+            'ia_collection_s', 'cover_i'])),
+        ('wt', 'json'),
+        ('q.op', 'AND'),
+        ('facet', 'true'),
+        ('facet.mincount', 1),
+        ('f.author_facet.facet.sort', 'count'),
+        ('f.publish_year.facet.limit', -1),
+        ('facet.limit', 25),
+    ]
+
     if has_fulltext:
-        fq.append('has_fulltext:true')
-    params = {
-        'fq': fq,
-        'q': q,
-        'start': offset,
-        'rows': rows,
-        'fl': fl,
-    }
-    solr_select = solr_select_url + "?fq=type:work&wt=json&q.op=AND&"
-    solr_select = solr_select_url + urllib.parse.urlencode(params, 'utf-8')
-    facet_fields = ["author_facet", "language", "publish_year", "publisher_facet", "subject_facet", "person_facet", "place_facet", "time_facet"]
-    if (sort == "editions"):
-        solr_select += '&sort=edition_count+desc'
+        params.append(('fq', 'has_fulltext:true'))
+
+    if sort == "editions":
+        params.append(('sort', 'edition_count desc'))
     elif sort.startswith('old'):
-        solr_select += '&sort=first_publish_year+asc'
+        params.append(('sort', 'first_publish_year asc'))
     elif sort.startswith('new'):
-        solr_select += '&sort=first_publish_year+desc'
+        params.append(('sort', 'first_publish_year desc'))
     elif sort.startswith('title'):
-        solr_select += '&sort=title+asc'
-    solr_select += "&facet=true&facet.mincount=1&f.author_facet.facet.sort=count&f.publish_year.facet.limit=-1&facet.limit=25&" + '&'.join("facet.field=" + f for f in facet_fields)
+        params.append(('sort', 'title asc'))
+
+    facet_fields = [
+        "author_facet", "language", "publish_year", "publisher_facet",
+        "subject_facet", "person_facet", "place_facet", "time_facet"
+    ]
+    for f in facet_fields:
+        params.append(("facet.field", f))
+
+    solr_select = solr_select_url + "?" + urllib.parse.urlencode(params)
     reply = parse_json_from_solr_query(solr_select)
     if reply is None:
         return web.storage(


Test patch: