Question

I am trying to incorporate Google site search into my .NET MVC project and I am very confused about the documentation.

The google XML API reference makes absolutely no reference to any code or classes that can be used for the search. As a result I am retreiving the XML and parsing it manually.

However, I have also come across the Google API as well and I am not sure whether these are connected or two different things and also confused why developers.google.com makes no reference to the existence of code.google.com

So my questions are here in order to put an end to the confusion.

a) Google site search (paid service) is possible to be used with the Google API despite there being no information about that on the developer section of the XML API? Mind you, you don't need an API key for the use of Google site search.

b) Is API an entirely separate entity that requires an API key and therefore not recommended for commercial use alongside Google site search because of API restrictions that otherwise don't exist with the plain paid service?

c) What is best practice when implementing Google site search (which I understand is the paid version of Google custom search) inside a .NET MVC 4 application? To fetch the XML and parse it manually or to consume the request into de serialized objects using the API?

Currently I am doing the former but I keep wondering if I can produce better, more testable code by combining my solution with the API.

I keep finding mixed resources regarding that on the web and I am not sure which way to go.

Thanks

Was it helpful?

Solution

I can't help with the .NET best practices, but can tell something about APIs. There are 2 different APIs for Custom Search (apart from the js widget):

Older, XML API: https://developers.google.com/custom-search/docs/xml_results Newer, JSON API: https://developers.google.com/custom-search/json-api/v1/overview

I believe the library you mentioned is for the latter.

The API key for paid site search version can be found in the Control Panel google.com/cse.

OTHER TIPS

Use below steps to implement Google custom search engine in ASP.Net MVC

Add controller

public class SearchController : Controller  
{  
    public ActionResult Search(string SearchString)  
    {  
        ViewBag.SearchString = SearchString;  
        ViewBag.Title = "Search";  
        return View("SearchResult");  
    }  
}

Add form to take user input

<div class="searchControl">  
 @using (Html.BeginForm("Search", "Search", FormMethod.Get))   
 {  
  <div class="input-group">  
    <input type="text" name="SearchString" class="form-control" placeholder="type something and hit enter">  
   <span class="input-group-btn">  
     <input class="btn" type="submit" value="Search!"/>  
   </span>  
  </div><!-- /input-group -->  
 }  
 </div>  

Add Search result page

@{  
 Layout = "~/Views/Shared/_Layout.cshtml";  
 }  
  <div class="container"">  
    <div class="row">   
      <div class="col-md-12">   
        <script>  
          //put here your Google custom search engine script
        </script>   
      <gcse:search>  
      </gcse:search>   
    </div>   
  </div>  
</div>

Here is complete step by step Article to implement Google custom search engine in MVC

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top