This sample shows how to let users search your app when they select the Search charm and open the search pane and how to use the search pane to display suggestions for users' queries. You can add search to your app by participating in the Search contract. This sample uses Windows.ApplicationModel.Search API, including the SearchPane class.

Note  Use the in-app search control to provide search results within your apps. For more info, see SearchBox.

You should use this sample as you go through the Quickstart: Adding search to a Windows Store app topic to fully understand how to participate in the Search contract. The sample and quickstart demonstrate these tasks:

  1. Participate in the Search contract so that users can search the app from anywhere in the system

    If the user is not using your app when they select the Search charm, they can still search your app by selecting it from the list of apps that is visible in the search pane.

  2. Display suggestions from an app-defined list in the search pane

  3. Display suggestions in East-Asian languages in the search pane

  4. Display suggestions from Windows in the search pane

  5. Display suggestions from Open Search in the search pane

    This shows how to supply suggestions to the search pane from a web server that returns suggestions in the OpenSearch Suggestions format.

    Use these steps to try it in the sample:

    1. Enter the URL to a web service that returns suggestions in the OpenSearch Suggestions format. Use {searchTerms} in the URL to represent where you want the query text to be inserted. (For example, "http://contoso.com?q={searchTerms}".)
    2. Select the Search charm.
    3. Type in a query.
    4. Search suggestions are provided.

    The following errors may occur during a search.

    • Incorrect URL   "Suggestions could not be retrieved, please verify that the URL points to a valid service (for example http://contoso.com?q={searchTerms}"
    • Ill-formed results   "Suggestions could not be displayed, please verify that the service provides valid OpenSearch suggestions"
  6. Display suggestions from a service that returns XML

    This shows how to supply suggestions to the search pane from a web server that returns suggestions in the XML search suggestions format.

    Use these steps to try it in the sample:

    1. Enter the URL to a web service that returns suggestions in the XML Search Suggestions format. Use {searchTerms} in the URL to represent where you want the query text to be inserted. (For example, "http://contoso.com?q={searchTerms}&format=xml".)
    2. Select the Search charm.
    3. Type in a query.
    4. Search suggestions are provided.

    The following errors may occur during a search.

    • Incorrect URL   "Suggestions could not be retrieved, please verify that the URL points to a valid service (for example http://contoso.com?q={searchTerms}"
    • Ill-formed results   "Suggestions could not be displayed, please verify that the service provides valid OpenSearch suggestions"

  7. Let the user open the search pane by starting to type a query

    This lets your users access the Search charm quickly while they are using a keyboard in your app. See Guidelines and checklist for search to learn about when and where you should consider enabling type to search.

To learn more about integrating with the Search contract so that the user can search your app, see Quickstart: Adding search to a Windows Store app and Guidelines and checklist for search.

Important APIs in this sample include:

To obtain an evaluation copy of Windows 8.1, go to Windows 8.1.

To obtain an evaluation copy of Microsoft Visual Studio 2013, go to Visual Studio 2013.

Related topics

SearchBox
Windows 8 app samples
Related samples
App activate and suspend using WinJS sample
App activated, resume, and suspend using the WRL sample

Related technologies

Windows.ApplicationModel.Search namespace

Operating system requirements

Client
Windows 8.1
Server
Windows Server 2012 R2

Build the sample

To build this sample, open the solutions (.sln) file titled SearchContractSample.sln from Visual Studio 2013 for Windows 8.1 (any SKU). Press F7 or go to Build->Build Solution from the top menu after the sample has loaded.

Run the sample

To run this sample after building it, go to the installation folder for this sample with Windows Explorer and run SearchContractSample.exe from the <install_root>\bin\Debug folder. Alternatively, press F5 (run with debegging enabled) or Ctrl-F5 (run without debugging enabled). (Or select the corresponding options from the Debug menu.)