自定义搜索结果
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
与自定义搜索框类似,您也可以为搜索结果元素添加其他选项。
例如,要将我们的搜索引擎从基于网页搜索结果的
转换为基于图片,我们可以使用 defaultToImageSearch
属性。
首先,您需要在控制面板中为您的搜索引擎启用图片搜索。在设置部分的基本设置标签页中,点击图片搜索选项并进入“开启”状态排名。然后,将 defaultToImageSearch
属性添加到您网站上的 <div class="gcse-searchresults"></div>
元素中。
<!-- 在此插入您自己的可编程搜索引擎 ID -->
<script async src="https://cse.google.com/cse.js?cx=017643444788069204610:4gvhea_mvga"></script>
<!-- 尝试将属性值切换为“true”或“false”-->
<div class="gcse-searchbox"></div>
<div class="gcse-searchresults" data-defaultToImageSearch="true"></div>
现在,当您进行搜索时,系统会默认显示“图片搜索”标签页。
还有很多其他选项可供选择。如需了解其他搜索结果自定义选项,请参阅 Programmable Search Element Control API 部分。
下一个...
继续执行后续步骤。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eThe search results element can be customized with additional options, such as switching to image-based results using the \u003ccode\u003edefaultToImageSearch\u003c/code\u003e attribute.\u003c/p\u003e\n"],["\u003cp\u003eTo enable image search, you need to activate it in the Control Panel for your search engine and then add the \u003ccode\u003edefaultToImageSearch\u003c/code\u003e attribute to the search results div element.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003edefaultToImageSearch\u003c/code\u003e attribute, when set to "true", makes the image search tab the default view for search results.\u003c/p\u003e\n"],["\u003cp\u003eFurther customization options for search results can be found in the Programmable Search Element Control API documentation.\u003c/p\u003e\n"]]],[],null,["# Customizing Search Results\n\nIn a similar way to customizing search box, you can add additional options to the search results element.\n\nFor example, in order to change our search engine from webresults-based\nto image-based, we can utilize the `defaultToImageSearch` attribute.\n\nFirst of all, you need to enable Image Search in the [Control Panel](https://programmablesearchengine.google.com) for your search engine. In the **Setup** section, in **Basics** tab, click the **Image search** option into the \"on\" position. After that, add the `defaultToImageSearch` attribute to the `\u003cdiv class=\"gcse-searchresults\"\u003e\u003c/div\u003e` element on your website. \n\\\u003c!-- Insert your own Programmable Search Engine ID here --\\\u003e \\\u003cscript async src=\"https://cse.google.com/cse.js?cx=017643444788069204610:4gvhea_mvga\"\\\u003e\\\u003c/script\\\u003e \\\u003c!-- Try switching the attribute value to \"true\" or \"false\" --\\\u003e \n\n \u003cdiv class=\"gcse-searchbox\"\u003e\u003c/div\u003e\n \u003cdiv class=\"gcse-searchresults\" data-defaultToImageSearch=\"true\"\u003e\u003c/div\u003e\n\nNow, when you search for something, the image search tab is showing as a default.\n\nThere are many more options available. You can read about other search results customization options in [Programmable Search Element Control API](/custom-search/docs/element#supported_attributes) section.\n\nNext...\n-------\n\nContinue to [Next steps](/custom-search/docs/tutorial/nextsteps)."]]