Create Your Own Web Search Service Application For Your Organization Using Bing Custom Search Instance

This will explain in brief about creating the Search web application using the custom search instance you have created.

In the previous blog, we have seen about creating Bing custom search instance through custom search portal. Now, we are going to see implementing the Bing custom search instance in the ASP.Net web application.
 
Using this you can create own search service for your organization either in .Net platform or in Sharepoint applications. Let's see, how to create the web application.
 
Open Visual Studio on your computer. 
 
On the File Menu, select New, and then choose Project.
 
In the New Project window, select Visual C# / Web / ASP.NET core web application, name your project, and then click create.
 
 
Once the solution gets created, open the solution file and in the Solution Explorer, expand Pages and double-click index.cshtml to open the file
 
 
In index.cshtml, delete everything starting from line 7 and below. 
  1. @page  
  2. @model IndexModel  
  3. @{  
  4.    ViewData["Title"] = "Home page";  
  5. }   
Then add a line break element and div section to act as container
  1. @page  
  2. @model IndexModel  
  3. @{  
  4.    ViewData["Title"] = "Home page";  
  5. }  
  6. <br />  
  7. <div id="customSearchPortal"></div>  
While creating the custom search instance you might have published the Hosted UI to consume your Bing custom search instance. Please navigate to custom search instance you created then in the Hosted UI page, scroll down to the section titled consuming the UI. Click the Endpoints to access the Javascript snippet. You can also get to the snippet by clicking production and then the Hosted UI tab. ( Please refer previous blog).
 
Paste the script container you added.
  1. @page  
  2. @model IndexModel  
  3. @{  
  4.    ViewData["Title"] = "Home page";  
  5. }  
  6. <br />  
  7. <div id="customSearchPortal">  
  8.    <script type="text/javascript"   
  9.        id="bcs_js_snippet"  
  10.        src="https://ui.customsearch.ai /api/ux/rendering-js?customConfig=<YOUR-CUSTOM-CONFIG-ID>&market=en-US&safeSearch=Moderate&version=latest&q=">  
  11.    </script>  
  12. </div>  
In the Solution Explorer, right click on wwwroot and click View in Browser.
 
 
Your new custom search web page should look like this,
 
 
By this application you can do external web search and bring the results from the sites you indexed in the Bing custom search instance. Happy learning !!