/msgraph-search-connector-sample

This .NET Core application shows how to use the Microsoft Graph indexing API to create a connection to the Microsoft Search service and index custom items.

Primary LanguageC#MIT LicenseMIT

Microsoft Graph Search Connector Sample

This .NET Core application shows how to use the Microsoft Graph indexing API to create a connection to the Microsoft Search service and index custom items. The sample indexes appliance parts inventory for Contoso Appliance Repair.

Prerequisites

Register an app in Azure portal

In this step you'll register an application in the Azure AD admin center. This is necessary to authenticate the application to make calls to the Microsoft Graph indexing API.

  1. Go to the Azure Active Directory admin center and sign in with an administrator account.

  2. Select Azure Active Directory in the left-hand pane, then select App registrations under Manage.

  3. Select New registration.

  4. Complete the Register an application form with the following values, then select Register.

    • Name: Parts Inventory Connector
    • Supported account types: Accounts in this organizational directory only (Microsoft only - Single tenant)
    • Redirect URI: Leave blank
  5. On the Parts Inventory Connector page, copy the value of Application (client) ID, you'll need it in the next section.

  6. Copy the value of Directory (tenant) ID, you'll need it in the next section.

  7. Select API Permissions under Manage.

  8. Select Add a permission, then select Microsoft Graph.

  9. Select Application permissions, then select the ExternalItem.ReadWrite.All permission. Select Add permissions.

  10. Select Grant admin consent for {TENANT}, then select Yes when prompted.

  11. Select Certificates & secrets under Manage, then select New client secret.

  12. Enter a description and choose an expiration time for the secret, then select Add.

  13. Copy the new secret, you'll need it in the next section.

Configure the app

  1. Open your command line interface (CLI) in the directory where PartsInventoryConnector.csproj is located.

  2. Run the following command to initialize user secrets for the project.

    dotnet user-secrets init
    
  3. Run the following commands to store your app ID, app secret, and tenant ID in the user secret store.

    dotnet user-secrets set appId "YOUR_APP_ID_HERE"
    dotnet user-secrets set appSecret "YOUR_APP_SECRET_HERE"
    dotnet user-secrets set tenantId "YOUR_TENANT_ID_HERE"
    

Initialize the database

dotnet ef database update

Delete and reset database

dotnet ef database drop
dotnet ef database update

Run the app

In this step you'll build and run the sample. This will create a new connection, register the schema, then push items from the ApplianceParts.csv file into the connection.

  1. Open your command-line interface (CLI) in the PartsInventoryConnector directory.

  2. Use the dotnet build command to build the sample.

  3. Use the dotnet run command to run the sample.

  4. Select the 1. Create a connection option. Enter a unique identifier, name, and description for the connection.

  5. Select the 4. Register schema for current connection option. Wait for the operation to complete.

    Note: If this steps results in an error, wait a few minutes and then select the 5. View schema for current connection option. If a schema is returned, the operation completed successfully. If no schema is returned, you may need to try registering the schema again.

  6. Select the 6. Push updated items to current connection option.

Create a vertical

Create and enable a search vertical at the organization level following the instructions in Customize the Microsoft Search page.

  • Name: Appliance Parts
  • Content source: the connector created with the app
  • Add a query: leave blank

Create a result type

Create a result type at the organization level following the instructions in Customize the Microsoft Search page.

  • Name: Appliance Part
  • Content source: the connector created with the app
  • Rules: None
  • Paste contents of result-type.json into layout

Search for results

In this step you'll search for parts in SharePoint.

  1. Go to your root SharePoint site for your tenant.
  2. Using the search box at the top of the page, search for hinge.
  3. When the search completes with 0 results, select the Appliance Parts tab.
  4. Results from the connector are displayed.

Updating records in the database

Use your favorite tool to update records in the database. The Push updated items menu choice will only push the items you update.

NOTE: Do not delete records from the database. To "delete" an item, set the IsDeleted property to 1.

DB Browser