快速入门:在门户中创建演示应用(Azure 认知搜索)Quickstart: Create a demo app in the portal (Azure Cognitive Search)

使用 Azure 门户的“创建演示应用”向导生成可在浏览器中运行的、可供下载的“localhost”样式 Web 应用。Use the Azure portal's Create demo app wizard to generate a downloadable, "localhost"-style web app that runs in a browser. 根据其配置,生成的应用在首次使用时就能正常运行,并与远程索引建立实时只读连接。Depending on its configuration, the generated app is operational on first use, with a live read-only connection to a remote index. 默认应用可以包含搜索栏、结果区域、边栏筛选器和自动提示支持。A default app can include a search bar, results area, sidebar filters, and typeahead support.

演示应用有助于你直观地了解索引在客户端应用中的工作方式,但其不适用于生产场景。The demo app can help you visualize how an index will function in a client app, but it is not intended for production scenarios. 客户端应用应包括生成的 HTML 页未提供的安全性、错误处理和托管逻辑。Client apps should include security, error handling, and hosting logic that the generated HTML page doesn't provide. 准备好创建客户端应用时,请参阅使用 .NET SDK 创建第一个搜索应用以了解后续步骤。When you are ready to create a client app, see Create your first search app using the .NET SDK for next steps.


在开始之前,必须满足以下条件:Before you begin, you must have the following:

  • 具有活动订阅的 Azure 帐户。An Azure account with an active subscription. 创建试用帐户Create an account for trial.

  • Azure 认知搜索服务。An Azure Cognitive Search service. 创建服务或在当前订阅下查找现有服务Create a service or find an existing service under your current subscription. 可以使用本快速入门的免费服务。You can use a free service for this quickstart.

  • Microsoft Edge(最新版本)或 Google Chrome。Microsoft Edge (latest version) or Google Chrome.

  • 要用作所生成应用程序的基础的搜索索引A search index to use as the basis of your generated application.

    本快速入门使用内置的“房地产”示例数据和索引,因为该示例包含缩略图(向导支持将图像添加到结果页)。This quickstart uses the built-in Real Estate sample data and index because it has thumbnail images (the wizard supports adding images to the results page). 若要创建本练习中使用的索引,请运行“导入数据”向导,并选择“realestate-us-sample”数据源。To create the index used in this exercise, run the Import data wizard, choosing the realestate-us-sample data source.


索引可供使用后,转到下一步。When the index is ready to use, move on to the next step.

启动向导Start the wizard

  1. 使用 Azure 帐户登录到 Azure 门户Sign in to the Azure portal with your Azure account.

  2. 查找搜索服务,然后在“概述”页中间的链接中,选择“索引”。Find your search service and on the Overview page, from the links on the middle of the page, select Indexes.

  3. 从现有索引的列表中选择“realestate-us-sample-index”。Choose realestate-us-sample-index from the list of existing indexes.

  4. 在索引页的顶部,选择“创建演示应用(预览版)”以启动向导。On the index page, at the top, select Create demo app (preview) to start the wizard.

  5. 在第一个向导页上,选择“启用跨源资源共享(CORS)”以将 CORS 支持添加到索引定义。On the first wizard page, select Enable Cross Origin Resource Sharing (CORS) to add CORS support to your index definition. 此步骤是可选的,但如果不执行此步骤,本地 Web 应用无法连接到远程索引。This step is optional, but your local web app won't connect to the remote index without it.

配置搜索结果Configure search results

向导将为呈现的搜索结果提供一个基本布局,其中包含缩略图、标题和说明的空间。The wizard provides a basic layout for rendered search results that includes space for a thumbnail image, a title, and description. 其中的每个元素由索引中一个提供数据的字段赋值。Backing each of these elements is a field in your index that provides the data.

  1. 在“缩略图”中,选择“realestate-us-sample”索引中的“thumbnail”字段。 In Thumbnail, choose the thumbnail field in the realestate-us-sample index. 此示例正好包含 URL 定址图像形式的缩略图,这些缩略图存储在名为 thumbnail 的字段中。This sample happens to include image thumbnails in the form of URL-addressed images stored in a field called thumbnail. 如果索引中没有图像,请将此字段留空。If your index doesn't have images, leave this field blank.

  2. 在“标题”中,选择能够表达每个文档的唯一性的字段。In Title, choose a field that conveys the uniqueness of each document. 在此示例中,列表 ID 是合理的选择。In this sample, the listing ID is a reasonable selection.

  3. 在“说明”中,选择一个提供详细信息的字段,这些信息可以帮助用户确定是否要单击进入特定的文档。In Description, choose a field that provides details that might help someone decide whether to click through to that particular document.


添加边栏Add a sidebar

搜索服务支持分面导航(通常以边栏的形式呈现)。The search service supports faceted navigation, which is often rendered as a sidebar. 分面基于可筛选且可分面的字段,在索引架构中表示。Facets are based on filterable and facetable fields, as expressed in the index schema.

在 Azure 认知搜索中,分面导航是一种累积筛选体验。In Azure Cognitive Search, faceted navigation is a cumulative filtering experience. 在一个类别中选择多个筛选器会展开结果(例如,在“城市”中选择“西雅图”和“贝尔维尤”)。Within a category, selecting multiple filters expands the results (for example, selecting Seattle and Bellevue within City). 跨类别选择多个筛选器会缩小结果范围。Across categories, selecting multiple filters narrows results.


可以在门户中查看整个索引架构。You can view the full index schema in the portal. 在每个索引的概述页中,找到“索引定义(JSON)”链接。Look for the Index definition (JSON) link in each index's overview page. 符合分面导航要求的字段具有“filterable: true”和“facetable: true”属性。Fields that qualify for faceted navigation have "filterable: true" and "facetable: true" attributes.

接受当前所做的分面选择,然后转到下一页。Accept the current selection of facets and continue to the next page.

添加自动提示功能Add typeahead

自动提示功能以自动完成和查询建议的形式提供。Typeahead functionality is available in the form of autocomplete and query suggestions. 向导支持查询建议。The wizard supports query suggestions. 根据用户提供的击键输入,搜索服务将返回可选作输入的“已完成”查询字符串列表。Based on keystroke inputs provided by the user, the search service returns a list of "completed" query strings that can be selected as the input.

在特定的字段定义中启用建议。Suggestions are enabled on specific field definitions. 向导提供相应的选项用于配置要在建议中包含的信息量。The wizard gives you options for configuring how much information is included in a suggestion.

以下屏幕截图显示了向导中的选项,同时显示了应用中呈现的页面。The following screenshot shows options in the wizard, juxtaposed with a rendered page in the app. 其中展示了如何使用字段选项,以及如何使用“显示字段名称”在建议中包含或排除标签。You can see how field selections are used, and how "Show Field Name" is used to include or exclude labeling within the suggestion.


创建、下载和执行Create, download and execute

  1. 选择“创建演示应用”,生成 HTML 文件。Select Create demo app to generate the HTML file.

  2. 出现提示时,请选择“下载应用”以下载文件。When prompted, select Download your app to download the file.

  3. 打开 文件。Open the file. 应会看到类似于以下屏幕截图的页面。You should see a page similar to the following screenshot. 输入一个搜索词,然后使用筛选器来缩小结果范围。Enter a term and use filters to narrow results.

基础索引由虚构生成的、已在不同文档中复制的数据构成,说明有时与图像不符。The underlying index is composed of fictitious, generated data that has been duplicated across documents, and descriptions sometimes do not match the image. 如果基于自己的索引创建应用,则预期会获得更有整体性的体验。You can expect a more cohesive experience when you create an app based on your own indexes.


清理资源Clean up resources

在自己的订阅中操作时,最好在项目结束时确定是否仍需要已创建的资源。When you're working in your own subscription, it's a good idea at the end of a project to identify whether you still need the resources you created. 持续运行资源可能会产生费用。Resources left running can cost you money. 可以逐个删除资源,也可以删除资源组以删除整个资源集。You can delete resources individually or delete the resource group to delete the entire set of resources.

可以使用左侧导航窗格中的“所有资源”或“资源组”链接 ,在门户中查找和管理资源。You can find and manage resources in the portal, using the All resources or Resource groups link in the left-navigation pane.

如果使用的是免费服务,请记住只能设置三个索引、索引器和数据源。If you are using a free service, remember that you are limited to three indexes, indexers, and data sources. 可以在门户中删除单个项目,以不超出此限制。You can delete individual items in the portal to stay under the limit.

后续步骤Next steps

默认应用对于初始探索和小任务非常有用,而尽早查看 API 有助于更深入地了解概念和工作流:While the default app is useful for initial exploration and small tasks, reviewing the APIs early on will help you understand the concepts and workflow on a deeper level: