Bug 11994 - Fix OpenSearch discovery in the OPAC
Summary: Fix OpenSearch discovery in the OPAC
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: OPAC (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal (vote)
Assignee: Owen Leonard
QA Contact: Testopia
URL:
Keywords: Academy
Depends on:
Blocks:
 
Reported: 2014-03-25 12:09 UTC by Katrin Fischer
Modified: 2021-12-13 21:09 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
OpenSearch (https://en.wikipedia.org/wiki/OpenSearch) allows you to search your library's catalog directly from the browser address bar or search box. This fixes the OpenSearch feature so that it now works correctly in Firefox. Note: make sure OPACBaseURL is correctly set.
Version(s) released in:
20.11.00, 20.05.02, 19.11.08, 19.05.14


Attachments
Bug 11994: Fix OpenSearch discovery in the OPAC (4.10 KB, patch)
2020-04-28 15:09 UTC, Owen Leonard
Details | Diff | Splinter Review
Screenshot showing menu for adding search engine in Firefox (129.59 KB, image/png)
2020-04-28 16:55 UTC, Owen Leonard
Details
Screenshot showing option to search in Koha (Firefox) (218.29 KB, image/png)
2020-04-28 16:55 UTC, Owen Leonard
Details
Bug 11994: Attempt to fix Content-Type (1.92 KB, patch)
2020-05-01 17:21 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 11994: Fix OpenSearch discovery in the OPAC (4.15 KB, patch)
2020-05-01 20:15 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 11994: OpenSearch plugins needs to be delivered with Content-Type application/opensearchdescription+xml (2.30 KB, patch)
2020-05-01 20:15 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 11994: (follow-up) Make things work when LibraryName is empty (1.99 KB, patch)
2020-05-01 20:15 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 11994: Fix OpenSearch discovery in the OPAC (4.20 KB, patch)
2020-05-01 21:04 UTC, David Nind
Details | Diff | Splinter Review
Bug 11994: OpenSearch plugins needs to be delivered with Content-Type application/opensearchdescription+xml (2.35 KB, patch)
2020-05-01 21:04 UTC, David Nind
Details | Diff | Splinter Review
Bug 11994: (follow-up) Make things work when LibraryName is empty (2.04 KB, patch)
2020-05-01 21:04 UTC, David Nind
Details | Diff | Splinter Review
Bug 11994: Fix OpenSearch discovery in the OPAC (4.25 KB, patch)
2020-06-19 13:26 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 11994: OpenSearch plugins needs to be delivered with Content-Type application/opensearchdescription+xml (2.41 KB, patch)
2020-06-19 13:26 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 11994: (follow-up) Make things work when LibraryName is empty (2.10 KB, patch)
2020-06-19 13:26 UTC, Martin Renvoize
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Katrin Fischer 2014-03-25 12:09:27 UTC
One of our libraries has asked about a search plugin for Koha and I did some experimenting. The needed xml could look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>Short name</ShortName>
<Description>Longer description</Description>
<InputEncoding>UTF-8</InputEncoding>
<Url type="text/html" method="GET" template="yourbaseurlforkoha/cgi-bin/koha/opac-search.pl?q={searchTerms}"/>
</OpenSearchDescription>

I also found different options to make this visible to the user:

A link using Javascript, similar to what Bugzila itself offers on the start page:

<a href="javascript:window.external.AddSearchProvider('URL for xml file')">Search Plugin</a>

This seems to work nicely in Firefox and IE.

Another option is using a link tag in the header. This will offer to install the plugin when you open the pull down of your search targets. It seems to only work in Firefox and not in IE.

<link rel="search" type="application/opensearchdescription+xml" title="..." href="http://...xml" />

Example: http://swb2.bsz-bw.de/

I thought maybe it would be nice to offer a plugin by default, using Koha's OpacBaseURL and LibraryName system preferences to fill out the required fields. 

This could be helpful for libraries with hosted Koha solutions that don't have the option to create an .xml file and store it on a web server themselves.
Comment 1 Katrin Fischer 2014-03-25 12:59:19 UTC
The URL to the favicon could be taken from Koha's system preferences as well:

<Image height="16" width="16" type="image/x-icon">http://example.com/favicon.ico</Image>
Comment 2 Owen Leonard 2020-04-28 14:41:01 UTC
This feature was working in Koha a long time ago, and the basic building blocks are still there. Updating the bug title to reflect that this will be a bug fix.
Comment 3 Owen Leonard 2020-04-28 15:09:01 UTC
Created attachment 103866 [details] [review]
Bug 11994: Fix OpenSearch discovery in the OPAC

This patch corrects the markup for the OpenSearchDescription XML
document and adds (back) the link in the OPAC header which points to it.
This will enable compatible browsers to offer the addition of the OPAC's
keyword search as a search engine option.

I've found documentation suggesting this feature is available (or at
least was at one time) in Chrome and Safari, but in my test it only
works in Firefox.

To test, apply the patch and make sure the OPACBaseURL preference is
set correctly.

 - Open the OPAC in Firefox (these instructions assume the latest
   version, currently v.75).
 - On the right side of the address bar you should see ". . ." Click it
   to trigger the menu.
 - You should see an "Add search engine" entry with your OPAC's icon.
 - Click to add the search engine.

 - Type a keyword to search in the address bar
 - A box should pop up below the address bar showing icons at the bottom
   for performing a search in various search engines. One of these icons
   should be the icon for your Koha OPAC.
 - Click the Koha OPAC icon and confirm that it triggers a keyword
   search in your OPAC.
Comment 4 Owen Leonard 2020-04-28 16:55:09 UTC
Created attachment 103873 [details]
Screenshot showing menu for adding search engine in Firefox
Comment 5 Owen Leonard 2020-04-28 16:55:57 UTC
Created attachment 103874 [details]
Screenshot showing option to search in Koha (Firefox)
Comment 6 David Nind 2020-05-01 10:37:06 UTC
Hi Owen.

I've had a couple of attempts at testing this, but get this message when trying to add:

Firefox could not download the search plugin from:
http://kohadev.mydnsname.org:8080/cgi-bin/koha/opac-search.pl?format=opensearchdescription

OPACBaseURL is set to http://kohadev.mydnsname.org:8080 - I think this is correct.

Here is the XML delivered when I look at the source for the URL in the error message above:

<?xml version='1.0' encoding='utf-8'  ?>
    <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
        <ShortName></ShortName>
        <Description>Search the Koha library catalog</Description>
        <InputEncoding>UTF-8</InputEncoding>
        <Image width="16" height="16" type="image/x-icon">
                http://kohadev.myDNSname.org:8080/opac-tmpl/bootstrap/images/favicon.ico
        </Image>
        <Url method="get" type="text/html" template="http://kohadev.myDNSname.org:8080/cgi-bin/koha/opac-search.pl?q={searchTerms}" />
        <Query role="example" searchTerms="cat" />
    </OpenSearchDescription>
Comment 7 Katrin Fischer 2020-05-01 10:49:52 UTC
The OpacBaseURl like this never works for me - I always have to change it to localhost:8080 (kohadevbox)
Comment 8 David Nind 2020-05-01 11:18:54 UTC
Thanks Katrin!

Unfortunately, the error still happens after making that change 8-(
Comment 9 Katrin Fischer 2020-05-01 16:38:57 UTC
I have the same issue as David, maybe opensearchdescription is not declared? I couldn't spot where this is set. Maybe a change missing from the patch set?
Comment 10 Katrin Fischer 2020-05-01 17:13:23 UTC
Trying to figure out where the issue could be:

ShortName
A short name for the search engine. It must be 16 or fewer characters of plain text, with no HTML or other markup.
=> We might have a longer library name easily, maybe we need to shorten it automatically if longer? Or have a default fallback text.

Or it could be this:

Your server should serve OpenSearch plugins using Content-Type: application/opensearchdescription+xml.

?
Comment 11 Katrin Fischer 2020-05-01 17:21:12 UTC
Created attachment 104132 [details] [review]
Bug 11994: Attempt to fix Content-Type

Not working yet...
Comment 12 David Nind 2020-05-01 19:38:44 UTC
Glad it just wasn't me.

Found this resource useful, and it mentions the error as well:
https://developer.mozilla.org/en-US/docs/Web/OpenSearch
Comment 13 Katrin Fischer 2020-05-01 20:15:23 UTC
Created attachment 104133 [details] [review]
Bug 11994: Fix OpenSearch discovery in the OPAC

This patch corrects the markup for the OpenSearchDescription XML
document and adds (back) the link in the OPAC header which points to it.
This will enable compatible browsers to offer the addition of the OPAC's
keyword search as a search engine option.

I've found documentation suggesting this feature is available (or at
least was at one time) in Chrome and Safari, but in my test it only
works in Firefox.

To test, apply the patch and make sure the OPACBaseURL preference is
set correctly.

 - Open the OPAC in Firefox (these instructions assume the latest
   version, currently v.75).
 - On the right side of the address bar you should see ". . ." Click it
   to trigger the menu.
 - You should see an "Add search engine" entry with your OPAC's icon.
 - Click to add the search engine.

 - Type a keyword to search in the address bar
 - A box should pop up below the address bar showing icons at the bottom
   for performing a search in various search engines. One of these icons
   should be the icon for your Koha OPAC.
 - Click the Koha OPAC icon and confirm that it triggers a keyword
   search in your OPAC.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 14 Katrin Fischer 2020-05-01 20:15:27 UTC
Created attachment 104134 [details] [review]
Bug 11994: OpenSearch plugins needs to be delivered with Content-Type application/opensearchdescription+xml

https://developer.mozilla.org/en-US/docs/Web/OpenSearch
Your server should serve OpenSearch plugins using
Content-Type: application/opensearchdescription+xml.

To test:
- Verify the Content-Type the file is delivered with
  is correct, for example using wget
  http://127.0.0.1:8080/cgi-bin/koha/opac-search.pl?format=opensearchdescription
Comment 15 Katrin Fischer 2020-05-01 20:15:30 UTC
Created attachment 104135 [details] [review]
Bug 11994: (follow-up) Make things work when LibraryName is empty

When LibraryName system preference was not set, the installation
of the plugin would fail with:

Firefox could not download the search plugin from: ...

Now if the pref is empty, the description 'Library catalog'
will be used instead.

To test:
- Empty your LibraryName pref
- Verify the search plugin can still be installed
  (see first patch for further instructions)
Comment 16 Katrin Fischer 2020-05-01 20:16:46 UTC
I couldn't let this go... and I finally figured it out! ... It would fial when LibraryName is not set. I also cleaned up the patch for Content-Type. While it seems to work without, I think we would be on the safer side to do it correctly.
Comment 17 David Nind 2020-05-01 20:38:06 UTC
That's awesome Katrin, thank you for your perseverance!
Comment 18 David Nind 2020-05-01 20:50:42 UTC
I'm getting something weird when applying the patch and trying to sign off.

There are four patches listed in the bug, bit git log only shows three.

Does that mean patch 104132 - Bug 11994: Attempt to fix Content-Type can be obsoleted?

This is what I get when applying the patch:

root@b23fad95e500:koha(master)$ git bz apply 11994
Bug 11994 - Fix OpenSearch discovery in the OPAC

104132 - Bug 11994: Attempt to fix Content-Type
104133 - Bug 11994: Fix OpenSearch discovery in the OPAC
104134 - Bug 11994: OpenSearch plugins needs to be delivered with Content-Type application/opensearchdescription+xml
104135 - Bug 11994: (follow-up) Make things work when LibraryName is empty

Apply? [(y)es, (n)o, (i)nteractive] y
Applying: Bug 11994: Attempt to fix Content-Type
Applying: Bug 11994: Fix OpenSearch discovery in the OPAC
Applying: Bug 11994: OpenSearch plugins needs to be delivered with Content-Type application/opensearchdescription+xml
Using index info to reconstruct a base tree...
M	C4/Output.pm
M	opac/opac-search.pl
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.
Applying: Bug 11994: (follow-up) Make things work when LibraryName is empty
Comment 19 Katrin Fischer 2020-05-01 20:53:07 UTC
Sorry, yes, one patch was obsolete, fixed now!
Comment 20 David Nind 2020-05-01 21:04:45 UTC
Created attachment 104138 [details] [review]
Bug 11994: Fix OpenSearch discovery in the OPAC

This patch corrects the markup for the OpenSearchDescription XML
document and adds (back) the link in the OPAC header which points to it.
This will enable compatible browsers to offer the addition of the OPAC's
keyword search as a search engine option.

I've found documentation suggesting this feature is available (or at
least was at one time) in Chrome and Safari, but in my test it only
works in Firefox.

To test, apply the patch and make sure the OPACBaseURL preference is
set correctly.

 - Open the OPAC in Firefox (these instructions assume the latest
   version, currently v.75).
 - On the right side of the address bar you should see ". . ." Click it
   to trigger the menu.
 - You should see an "Add search engine" entry with your OPAC's icon.
 - Click to add the search engine.

 - Type a keyword to search in the address bar
 - A box should pop up below the address bar showing icons at the bottom
   for performing a search in various search engines. One of these icons
   should be the icon for your Koha OPAC.
 - Click the Koha OPAC icon and confirm that it triggers a keyword
   search in your OPAC.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: David Nind <david@davidnind.com>
Comment 21 David Nind 2020-05-01 21:04:49 UTC
Created attachment 104139 [details] [review]
Bug 11994: OpenSearch plugins needs to be delivered with Content-Type application/opensearchdescription+xml

https://developer.mozilla.org/en-US/docs/Web/OpenSearch
Your server should serve OpenSearch plugins using
Content-Type: application/opensearchdescription+xml.

To test:
- Verify the Content-Type the file is delivered with
  is correct, for example using wget
  http://127.0.0.1:8080/cgi-bin/koha/opac-search.pl?format=opensearchdescription

Signed-off-by: David Nind <david@davidnind.com>
Comment 22 David Nind 2020-05-01 21:04:52 UTC
Created attachment 104140 [details] [review]
Bug 11994: (follow-up) Make things work when LibraryName is empty

When LibraryName system preference was not set, the installation
of the plugin would fail with:

Firefox could not download the search plugin from: ...

Now if the pref is empty, the description 'Library catalog'
will be used instead.

To test:
- Empty your LibraryName pref
- Verify the search plugin can still be installed
  (see first patch for further instructions)

Signed-off-by: David Nind <david@davidnind.com>
Comment 23 Martin Renvoize 2020-06-19 13:26:12 UTC
Created attachment 106092 [details] [review]
Bug 11994: Fix OpenSearch discovery in the OPAC

This patch corrects the markup for the OpenSearchDescription XML
document and adds (back) the link in the OPAC header which points to it.
This will enable compatible browsers to offer the addition of the OPAC's
keyword search as a search engine option.

I've found documentation suggesting this feature is available (or at
least was at one time) in Chrome and Safari, but in my test it only
works in Firefox.

To test, apply the patch and make sure the OPACBaseURL preference is
set correctly.

 - Open the OPAC in Firefox (these instructions assume the latest
   version, currently v.75).
 - On the right side of the address bar you should see ". . ." Click it
   to trigger the menu.
 - You should see an "Add search engine" entry with your OPAC's icon.
 - Click to add the search engine.

 - Type a keyword to search in the address bar
 - A box should pop up below the address bar showing icons at the bottom
   for performing a search in various search engines. One of these icons
   should be the icon for your Koha OPAC.
 - Click the Koha OPAC icon and confirm that it triggers a keyword
   search in your OPAC.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 24 Martin Renvoize 2020-06-19 13:26:15 UTC
Created attachment 106093 [details] [review]
Bug 11994: OpenSearch plugins needs to be delivered with Content-Type application/opensearchdescription+xml

https://developer.mozilla.org/en-US/docs/Web/OpenSearch
Your server should serve OpenSearch plugins using
Content-Type: application/opensearchdescription+xml.

To test:
- Verify the Content-Type the file is delivered with
  is correct, for example using wget
  http://127.0.0.1:8080/cgi-bin/koha/opac-search.pl?format=opensearchdescription

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 25 Martin Renvoize 2020-06-19 13:26:18 UTC
Created attachment 106094 [details] [review]
Bug 11994: (follow-up) Make things work when LibraryName is empty

When LibraryName system preference was not set, the installation
of the plugin would fail with:

Firefox could not download the search plugin from: ...

Now if the pref is empty, the description 'Library catalog'
will be used instead.

To test:
- Empty your LibraryName pref
- Verify the search plugin can still be installed
  (see first patch for further instructions)

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 26 Martin Renvoize 2020-06-19 13:27:05 UTC
Works as expected, no regressions..

Passing QA
Comment 27 Jonathan Druart 2020-06-24 13:31:33 UTC
Pushed to master for 20.11, thanks to everybody involved!
Comment 28 Lucas Gass 2020-07-10 16:06:26 UTC
backported to 20.05.x for 20.05.02
Comment 29 Aleisha Amohia 2020-07-13 02:20:29 UTC
backported to 19.11.x for 19.11.08
Comment 30 Victor Grousset/tuxayo 2020-07-23 23:41:18 UTC
Backported to 19.05.x branch for 19.05.14