Google 自定义搜索 - Add/remove 个要动态搜索的站点

Google Custom Search - Add/remove sites to search dynamically

Google 自定义搜索具有指定您希望搜索引擎搜索的站点的功能 - "Sites to search" 功能。 我需要即时 add/remove 这些网站。是否有 api 或 Google 提供的任何其他方法可以实现此目的?

您可以在这里找到相关信息:

https://developers.google.com/custom-search/docs/tutorial/creatingcse

To create a custom search engine:

Sign into Control Panel using your Google Account (get an account if you don't have one). In the Sites to search section, add the pages you want to include in your search engine. You can include any sites you want, not just the sites you own. You can include whole site URLs or individual pages URLs. You can also use URL patterns.

https://support.google.com/customsearch/answer/71826?hl=en

URL patterns

URL patterns are used to specify what pages you want included in your custom search engine. When you use the control panel or the Google Marker to add sites, you're generating URL patterns. Most URL patterns are very simple and simply specify a whole site. However, by using more advanced patterns, you can more precisely pick out portions of sites.

For example, the pattern 'www.foo.com/bar' will only match the single page 'www.foo.com/bar'. To cover all the pages where the URL starts with ' www.foo.com/bar', you must explicitly add a '' at the end. In the form-based interfaces for adding sites, 'foo.com' defaults to '.foo.com/*'. If this is not what you want, you can change it back in the control panel. No such defaulting occurs for patterns that you upload. Also note that URLs are case sensitive - if your site URLs include capital letters, you'll need to make sure your patterns do as well.

In addition, the use of wildcards in URL patterns allows you to include or exclude multiple pages or portions of a site all at once.

所以,基本上您必须导航到 "Sites to search section" 并在那里输入所需的站点。如果您想即时更改这些网站,您必须操纵您的 URL 模式。

还有一个使用 XML configuration files 的选项。您只需在此处添加(或删除)您的网站:

https://developers.google.com/custom-search/docs/annotations

Annotations: The annotations XML file lists the webpages or websites you want your search engine to cover, and indicates any preferences you have about how these sites should be ranked in your search results. Each site and its associated information is called an annotation. More information about the annotations XML file.

注释示例:

<Annotation about="http://www.solarenergy.org/*">
   <Label name="_cse_abcdefghijk"/>
</Annotation>

使用 api 我们可以添加过滤器 "siteSearch"=>"somedmain.com somdomain2.com","siteSearchFilter"=>"e" 但单独的域之间会有间距。