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

Add a parameter for returning search suggestions in OpenSearch format #110

Open
aminomancer opened this issue Oct 21, 2022 · 0 comments
Open

Comments

@aminomancer
Copy link

Browsers can display search suggestions (see search_provider.suggest_url) from an OpenSearch definition, but they have to be formatted as a JSON array [input:string, packageNames:string[]] or an XML SearchSuggestion (slower).

Example (for Wiktionary):
Request: https://en.wiktionary.org/w/api.php?action=opensearch&search=test
Response:

[
  "test",
  [
    "test",
    "testa",
    "testis",
    "testament",
    "teste",
    "tester",
    "testicle",
    "testimonium",
    "testo",
    "testudo"
  ],
  // ...unnecessary implementation-specific members
]

If you add a parameter like format=osxs that will return this simple array type, the OpenSearch description on this repo can be extended so browsers can display npm search suggestions:

--- a/npms-www/web/opensearch.xml
+++ b/npms-www/web/opensearch.xml
@@ -1,11 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
 	<ShortName>npms</ShortName>
 	<Description>npms - a better and open sourced search for node packages</Description>
 	<Tags>npm search node module package score github</Tags>
 	<Contact>amdfcruz+npms@gmail.com</Contact>
 	<Developer>André Cruz</Developer>
 	<Url type="text/html" method="get" template="https://npms.io/search?q={searchTerms}"/>
+ 	<Url type="application/x-suggestions+json" method="get" template="https://npms.io/search?q={searchTerms}&format=osxs" />
	<InputEncoding>UTF-8</InputEncoding>
	<Image height="16" width="16" type="image/vnd.microsoft.icon"></Image>
</OpenSearchDescription>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant