Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add suggestion URL for custom search engine in chrome

I have a local search engine backed by a elasticsearch and a thin nodejs API for search. I want to be able to search those documents from Google Chrome (builds available from Google, not Chromium) directly. In this use case, I will use chrome ONLY with this search engine, so I don't want to use OmniBox keyword search API. I want the same behavior as I get while choosing the default search engine in chrome. Which is

  1. Start typing in the OmniBox and it shows a list of suggestions.
  2. Hit enter and it takes to the search results page

I got the #2 working by adding a new search engine under settings and providing the search api's url. I can't get #1 working.

The two urls exposed by my server are:

  1. http://localhost:3000/complete?query=my (this returns a list of search suggestions which I want to show while typing in OmniBox).

  2. http://localhost:3000/results?query=my+sample+query (this returns the actual search results as a web page, this is working)

Things that I have tried:

  1. Added search engine using window.externals.AddSearchProvider with OpenSearchDescription.xml link. The XML has suggestions url as well.

  2. Tried writing a background extension with OmniBox but it does not allow me to search without using a keyword

I searched through Chromium and found this JSON file

https://code.google.com/p/chromium/codesearch#chromium/src/components/search_engines/prepopulated_engines.json&q=prepopulated&sq=package:chromium&l=1

But I don't know how can I use it (or if its even possible to do this in official builds of Chrome).

like image 297
drcocoa Avatar asked Feb 06 '16 04:02

drcocoa


People also ask

How do I add suggestions to Google Chrome?

Turn on autocompletions:Click Search features from the menu on the left and then click the Autocomplete tab. Click on the slider to set Enable autocomplete to On. It can take up to 2-4 days for autocompletions tailored to your search engine to start appearing.


2 Answers

I finally found the solution.

The opensearch.xml document reference can be used as a link in the head section of the HTML page. It contains two URL schemes, one for search results and other for suggestions.

The details can be found here: Opensearch Document Specs.

As soon as I updated my index.html and opened the page in Chrome, Chrome automatically added a new search engine. It didn't show that there is a suggestions URL under Settings > Manage search engines.

Next, I chose my engine as the default search engine by clicking on Make Default and done! Now I can see all the search suggestions in the omnibox without using a keyword.

like image 169
drcocoa Avatar answered Sep 24 '22 02:09

drcocoa


There is a Setting Overrides mechanism for Chrome Extensions, which is not widely known, which can achieve what you want, but:

  • At least according to the docs, it only works on Windows.
  • You won't be able to publish the extension unless you can verify the site in Webmaster Tools. Otherwise, you are stuck with unpacked installs.
like image 37
Xan Avatar answered Sep 22 '22 02:09

Xan