Repository: internetarchive/openlibrary

Issue:
Some publisher links are broken
<!-- What problem are we solving? What does the experience look like today? What are the symptoms? -->
From a patron:
Searching for a publisher sometimes brings up no results, even if the search was from a direct link showing multiple books to that publisher. For example:

https://openlibrary.org/search/publishers?q=%22Media+Blasters%22

Clicking on the link for "Media Blasters 147 books" results in "We couldn't find any books published by Media Blasters." So where are the 147 books?

### Evidence / Screenshot (if possible)

### Relevant url?
<!-- `https://openlibrary.org/...` -->
https://openlibrary.org/search/publishers?q=%22Media+Blasters%22
https://openlibrary.org/publishers/Media_Blasters
### Steps to Reproduce
<!-- What steps caused you to find the bug? -->
1. Go to ... https://openlibrary.org/search/publishers?q=%22Media+Blasters%22
2. Do ...click the first entry, https://openlibrary.org/publishers/Media_Blasters

<!-- What actually happened after these steps? What did you expect to happen? -->
* Actual: no books
* Expected: should see 147 books

### Details

- **Logged in (Y/N)?**
- **Browser type/version?**
- **Operating system?**
- **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? -->
Maybe solr related?

### 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
<!-- @ tag stakeholders of this bug -->
@cdrini @mekarpeles @jimchamp 


Discussion:
I can confirm this problem. When I open the work OL27025404W and click on the publisher link, I get an error page saying this publisher would not have any books.

On book page
![Screenshot_20221023_235628](https://user-images.githubusercontent.com/36878944/197420101-9d0085b5-5810-4ec0-b024-7e2acff1942b.png)

On publisher page
![Screenshot_20221023_235646](https://user-images.githubusercontent.com/36878944/197420105-9446e030-ac9d-4711-8542-c81b10f6cca1.png)
The issue appears to be affecting publishers with a space in their name, which is being converted to a _ for the url, but then being searched as a literal _ (which sometimes finds a few matching entries).


Resolving patch:
diff --git a/openlibrary/plugins/worksearch/subjects.py b/openlibrary/plugins/worksearch/subjects.py
--- a/openlibrary/plugins/worksearch/subjects.py
+++ b/openlibrary/plugins/worksearch/subjects.py
@@ -255,6 +255,7 @@ def get_subject(
                 'q': query_dict_to_str(
                     {meta.facet_key: self.normalize_key(meta.path)},
                     unescaped=unescaped_filters,
+                    phrase=True,
                 ),
                 **filters,
             },
diff --git a/openlibrary/solr/query_utils.py b/openlibrary/solr/query_utils.py
--- a/openlibrary/solr/query_utils.py
+++ b/openlibrary/solr/query_utils.py
@@ -232,6 +232,7 @@ def query_dict_to_str(
     escaped: dict | None = None,
     unescaped: dict | None = None,
     op: Literal['AND', 'OR', ''] = '',
+    phrase: bool = False,
 ) -> str:
     """
     Converts a query dict to a search query.
@@ -246,11 +247,16 @@ def query_dict_to_str(
     'title:(foo \\\\? to escape)'
     >>> query_dict_to_str({'title': 'YES AND'})
     'title:(YES and)'
+    >>> query_dict_to_str({'publisher_facet': 'Running Press'}, phrase=True)
+    'publisher_facet:"Running Press"'
     """
     result = ''
     if escaped:
         result += f' {op} '.join(
-            f'{k}:({fully_escape_query(v)})' for k, v in escaped.items()
+            f'{k}:"{fully_escape_query(v)}"'
+            if phrase
+            else f'{k}:({fully_escape_query(v)})'
+            for k, v in escaped.items()
         )
     if unescaped:
         if result:


Test patch: