How to: Deploy custom search configurations by using Visual Studio

apps for SharePoint

Learn how to deploy customized search configurations for apps for SharePoint by using Visual Studio.

Last modified: June 11, 2014

Applies to: Microsoft Visual Studio | Visual Studio | Visual Studio Tools for Microsoft Office

In this article
Prerequisites
Create the query source and the query rule to search MSDN
Test the query rule
Export the search configuration
Deploy the search configuration by using Visual Studio
Verify the custom search configuration
Additional resources

You can return results that are outside of your normal search domain by customizing your search configuration to include, for example, an Enterprise Search Center site. If you customize your search configuration, targeted results from external sources appear in a result block above the other results. For example, you can search for "SharePoint 2013 apps" to get a list of topics on the SharePoint site that contain those terms. If you customize the search configuration and then search for "MSDN" in addition to those terms, MSDN hits appear in a result block.

This article explains how to extend your search results beyond the SharePoint site, but you can also customize your search in other ways. In this example, you define a custom query rule and a Bing Open Search query source in SharePoint. When you include a specific keyword at the end of a search string (in this case, msdn), the query rule fires, and MSDN results appear in a result block at the top of the search page. You can create query rules and query sources more easily by using a designer in SharePoint. After you define settings for the search configuration, you export them as a single XML file that includes all of the exportable settings, such as query configurations, ranking model, and schema. You then import the XML file into an app for SharePoint in Visual Studio, and you use Enterprise Search Center to test and customize the app. After you verify that the search configuration works correctly, you package and deploy the app and its search configuration to SharePoint.

Note Note

To "side-load" an app (that is, to use Visual Studio to deploy an app to a SharePoint site), you need to use PowerShell commands instead of the site template for Enterprise Search Center. See Quickly start developing apps with the new "0-60" developer experience.

  • A local installation of Visual Studio.

  • A local installation of Office Developer Tools for Visual Studio.

  • A SharePoint developer site.

  • An Enterprise Search Center site.

  • An Office 365 subscription, if you're developing apps for SharePoint in Office 365.

Core concepts

Before you start these procedures, you should understand how search operations in SharePoint work, how to set up a SharePoint developer site, and how to set up an Enterprise Search Center site. You should gain that understanding by reviewing the topics in the following table.

Table 1. Core concepts for customizing SharePoint search

Article title

Description

Create a Search Center site in SharePoint Server 2013

Learn how to create an Enterprise Search Center site and grant access to users.

Manage query rules in SharePoint Server 2013

Learn how to improve search results by creating and managing query rules.

Administer search in SharePoint Server 2013

Learn how to improve search results and to manage crawling, the search schema, and the search topology in SharePoint 2013.

Export and import customized search configuration settings in SharePoint Server 2013

Learn how to export and import search configurations between SharePoint site collections and sites.

The query source indicates the URL where the search occurs and the protocol that it uses. In this case, it searches Bing by using the OpenSearch protocol. The query rule specifies the criteria for running the query. In this case, the words msdn or MSDN trigger the query.

To create the query source for MSDN

  1. On the SharePoint developer site, open the Settings page.

  2. In the Site Collection Administration section, choose the Search Result Sources link, and then choose the New Result Source link.

  3. On the Add Result Source page, add the following property values:

    Table 2. Property settings for the Add Result Source page

    Property

    Value

    Name

    MSDN Query Source

    Description

    MSDN Query Source

    Protocol

    OpenSearch 1.0/1.1 [If you choose this option, you refresh the page.]

    Source URL

    http://www.bing.com/search?q=site:msdn.microsoft.com+{searchTerms}&format=rss

  4. Choose the query source that you just added, and then choose the Test Source command to verify whether the query works.

To create the query rule for MSDN

  1. In the Site Collection Administration section of the Settings page, choose the Search Query Rules link.

  2. On the Manage Query Rules page, choose the Local SharePoint Results list item as the context in which you want to configure the query rule.

  3. Choose the New Query Rule link.

  4. On the Add Query Rule page, add the following property values:

    Table 3. Property settings for the Add Query Rule page

    Property

    Value

    Rule Name

    MSDN Query Rule

    Query Conditions

    Advanced Query Text Match

    Query contains one of these phrases

    msdn;MSDN;

  5. Select the End of query matches, but not entire query check box, and clear the Entire query matches exactly check box.

  6. Choose the Add Result Block link.

  7. On the Add Result Block page, add the following property values. (Leave the other properties at their current values.)

    Table 4. Property settings for the Add Result Block page

    Property

    Value

    Block Title

    MSDN Results for "{subjectTerms}" for Block Title

    Search this Source

    MSDN Query Source

    Items

    5

  8. Choose the OK button to create the result block, and then choose the Save button to create the MSDN query rule.

The query source and rule are defined, so now you can test the results.

To test the query rule

  1. In the upper-left part of the page, choose the SharePoint logo icon to browse to the home page.

  2. Search for sharepoint 2013 apps msdn, and then verify that the result block for MSDN appears on the results page.

    The block is denoted by the title MSDN Results for "sharepoint 2013 apps msdn" and a line on the left side of the results. Other results, if any, appear under the result block.

After you verify that the result block works, export the search configuration into an XML file that you can import into Visual Studio.

To export the search configuration

  1. In the Site Collection Administration section of the Site Settings page in SharePoint, choose the Search Configuration Export link.

  2. Save the SearchConfiguration.xml file.

    Note Note

    We recommend that you customize the search configuration in SharePoint, export it to an XML file, and then import the file into a Search Configuration project in Visual Studio.

You deploy the search configuration by using the Search Configuration project in Visual Studio.

To deploy the search configuration

  1. In Visual Studio, create an app for a SharePoint project, and name the project "MSDN Search Sample".

  2. In the New App for SharePoint dialog box, set the hosting type to SharePoint-hosted, and specify the URL of the enterprise search site (where you enabled side-loading of apps) for debugging.

  3. Add a Search Configuration project item to the project that you just created.

  4. In the Import Search Configuration Settings dialog box, browse to the SearchConfiguration.xml file that you exported earlier.

  5. In the SearchConfigurationSettings.xml file, change the value of the DeployToParent attribute to true.

  6. In Solution Explorer, open AppManifest.xml in the manifest designer, and then choose the Permissions tab in the designer.

  7. On the Permissions tab, add the following permission:

    Table 5. Permission settings

    Property

    Value

    Scope

    Site Collection

    Permission

    Full Control

After you finish customizing the search configuration, verify whether the search configuration in SharePoint is correct.

To verify the custom search configuration

  1. In Visual Studio, choose the F5 key to debug the project in SharePoint.

  2. In the upper-left corner of the page, choose the Enterprise Search Demo button to navigate to the host web.

  3. In the Site Collection Administration section of the Site Settings page in SharePoint, choose the Search Result Sources link.

  4. Choose the MSDN Query Source link to open the result source page, verify that the source URL is valid, and then choose the Save button.

  5. Choose the Site Collection Administration header to return to the Site Settings page.

  6. In the Site Collection Administration section of the Site Settings page in SharePoint, choose the Search Query Rules link.

  7. Choose Local SharePoint Results in the list as the result source.

  8. Choose the MSDN Query Rule link to verify the query rule.

  9. In the Result Blocks section, choose the Edit link.

  10. Verify that the result block is correct, choose the OK button, and then choose the Save button.

  11. In the top-left corner of the page, choose the SharePoint logo to navigate to the home page of the app.

  12. Search for sharepoint 2013 apps msdn, and then verify that the result block for MSDN appears.

  13. Search for sharepoint 2013 apps, and then verify that the result block for MSDN doesn't appear.

    If you omit msdn from the search keywords, you remove the trigger that creates the result block.

Show:
© 2014 Microsoft