在Chrome中为自定义搜索引擎添加建议URL [英] Add suggestion URL for custom search engine in chrome

查看:72
本文介绍了在Chrome中为自定义搜索引擎添加建议URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地搜索引擎,该引擎由elasticsearch和一个用于搜索的瘦nodejs API支持.我希望能够直接从Google Chrome浏览器中搜索这些文档(可从Google而不是Chromium上获得内部版本).在这种情况下,我将在此搜索引擎中使用chrome ,因此,我不想使用OmniBox关键字搜索API.我想要与在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. 开始在OmniBox中输入内容,并显示建议列表.
  2. 按Enter进入搜索结果页面

通过在设置下添加新的搜索引擎并提供搜索api的网址,我排名第二.我无法让#1工作.

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 (此返回我要在OmniBox中键入时显示的搜索建议的列表.

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

http://localhost:3000/results?query = my + sample+ query (这将返回实际的搜索结果作为网页,正在运行)

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

我尝试过的事情:

  1. 使用带有OpenSearchDescription.xml链接的window.externals.AddSearchProvider添加搜索引擎.XML也有建议网址.

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

尝试使用OmniBox编写背景扩展程序,但不允许我不使用关键字进行搜索

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

我搜索了Chromium,发现了这个JSON文件

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

但是我不知道如何使用它(或者甚至有可能在Chrome的官方版本中使用它).

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

推荐答案

我终于找到了解决方案.

I finally found the solution.

opensearch.xml 文档参考可以用作HTML页面顶部的链接.它包含两种URL方案,一种用于搜索结果,另一种用于建议.

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.

详细信息可以在这里找到: Opensearch文档规范.

The details can be found here: Opensearch Document Specs.

更新我的 index.html 并在Chrome中打开该页面后,Chrome会自动添加新的搜索引擎.它没有显示在设置>管理搜索引擎下有一个建议URL.

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.

这篇关于在Chrome中为自定义搜索引擎添加建议URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆