Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

Google web service in asp.net web application

I have a google search web service working in my application but want to restrict the search to just my site.  But I can't work out where to put the url address.

Dim gs As New com.google.api.GoogleSearchService()
        Dim r As com.google.api.GoogleSearchResult = gs.doGoogleSearch(key, txtSearch.Text, 0, 10, True, "countryUK", False, "lang_en", "", "")
   
Any suggestions?
Thanks
0
ladykh
Asked:
ladykh
  • 6
  • 3
  • 3
1 Solution
 
sachiekCommented:
Can you take a look at this page.

See View code. They had done it with setting the target and hidden fields only.

http://www.csharpcorner.com/ -->Go here and click search link on the top right corner.


Sachi

0
 
sachiekCommented:
Lookout this article.

http://www.eggheadcafe.com/articles/20020802.asp

Peter Bromberg had commentted atlast in his article.

"If you wanted to, you could get pretty sophisticated with this. One idea is to create a usercontrol that can simply be plugged into a web page at the location of your choice. You can also use the tool to restrict the search to only a particular site (like their "put Google Search on your site" feature) so that it only searches on your site."

Hope you got it.
0
 
sachiekCommented:
I guess you can use this url to refer for your query.

You need to restrict google search to only your site.
There is a feature call "Site restriction"

http://www.google.com/apis/reference.html#2_2
Under above url look for "Special Query Terms"
In that topic there are details.

Site Restricted Search

example:
 admission site:www.stanford.edu  

If you know the specific web site you want to search but aren't sure where the information is located within that site, you can use Google to search only within a specific web site.
Do this by entering your query followed by the string "site:" followed by the host name.

Note: The exclusion operator ("-") can be applied to this query term to remove a web site from consideration in the search.

Note: Only one site: term per query is supported.
 


0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
davidlars99Commented:
I had this code tested and ran you just replace key with your own key value


<%@ Import Namespace="System.Text" %>
<HTML>
<HEAD>
<Script Language="VB" Runat="Server">

Dim key As String="your key goes here", _
      maxResults As Integer, _
      formatString As String="<p><a href=""{1}"">{0}</a><br>{2}<br>{1}-{3}</p>"
      
Sub Page_Load(s As Object, e As EventArgs)
      If Not IsPostBack Then
            lbnext.Visible=False
            lbprev.Visible=False
            lblresults.Visible=False
            headerpanel.Visible=False
      End If
End Sub

Sub Search(s As Object, e As EventArgs)
      resultlist.Text=doQuery(searchtext.Text, 0)
      Session("CurrentRecord")=0
      headerpanel.Visible=True
End Sub

Function doQuery(st As String, rc As Integer)
      Dim totalcount As Integer, _
            displaytitle As String, _
            sb As StringBuilder=New StringBuilder()
      Dim s As GoogleSearchService=New GoogleSearchService(), _
            r As GoogleSearchResult=s.doGoogleSearch( _
                  key, st, rc, maxresults, false, "", false, "", "", "")
            
      
      totalCount=r.estimatedTotalResultsCount
      Dim result As ResultElement
      
      For Each result In r.resultElements
            If result.title <> "" Then
                  displayTitle=result.title
            Else
                  displayTitle=result.URL
            End If
            
            sb.Append(String.Format( _
                  formatString, displayTitle, result.URL, result.snippet, result.cachedSize))
      Next
      
      If r.estimateIsExact And r.endIndex >= totalCount Then
            lbnext.Visible=False
      Else
            lbnext.Visible=True
      End If
      
      If rc=0 Then
            lbprev.Visible=False
      Else
            lbprev.Visible=True
      End If
      
      lbltotalresults.Text=totalcount
      lblresults.Visible=True
      Return sb.ToString()
End Function

Sub NextClick(s As Object, e As EventArgs)
      Session("CurrentRecord")+=maxResults
      resultList.Text=doQuery(searchtext.Text, Session("CurrentRecord"))
End Sub

Sub PreviousClick(s As Object, e As EventArgs)
      Session("CurrentRecord")-=maxResults
      resultList.Text=doQuery(searchtext.Text, Int32.Parse(Session("CurrentRecord")))      
End Sub

</Script>
<TITLE>Google API Example</TITLE>
</HEAD>
<BODY>

<form runat="server">
      <P>
            Google Search: <asp:textbox id="searchtext" runat="server" />
            <asp:button id="btn1" text="Search" runat="server" onclick="search" />
      </P>
      <br>
      <br>
      <asp:panel id="headerpanel" runat="server">
            <p>
                  <asp:label id="lblresults" runat="server" text="Total Results Returned:" />
                  <asp:label id="lbltotalresults" runat="server" />
            </p>
            <p>
                  <asp:label id="resultlist" runat="server" />
            </p>
            <p>
                  <asp:linkbutton id="lbprev" onclick="previousclick" visible="false" runat="server">Previous</asp:linkbutton>
                  <asp:linkbutton id="lbnext" onclick="nextclick" visible="false" runat="server">Next</asp:linkbutton>
            </p>
      </asp:panel>
</form>

</BODY>
</HTML>
0
 
davidlars99Commented:
you can also test and debug web services by using Web Services Studio

http://www.gotdotnet.com/Community/UserSamples/Download.aspx?SampleGuid=65A1D4EA-0F7A-41BD-8494-E916EBC4159C
0
 
davidlars99Commented:
this tool will show you everything in details about what some particular WS requires, it made lots of thing very easy for me...
0
 
ladykhAuthor Commented:
This is the code for when I click the search button and it works to search many sites, but I still cannot get is to search one site?

Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
        Const key As String = "google key"

        Dim gs As New com.google.api.GoogleSearchService()
        Dim r As com.google.api.GoogleSearchResult = gs.doGoogleSearch(key, txtSearch.Text, 0, 10, True, "countryUK", False, "lang_en", "", "")
        Dim x As Integer
        Dim dt As New GoogleResultElement.ResultElementDataTable()
        If r.startIndex = r.endIndex Then
            lblGoogleMessage.Text = "No Results Found"
        Else
            For x = r.startIndex - 1 To r.endIndex - 1
                Dim dr As GoogleResultElement.ResultElementRow = dt.NewResultElementRow
                Dim re As com.google.api.ResultElement = r.resultElements(x)
                dr.summary = re.summary
                dr.URL = re.URL
                dr.snippet = re.snippet
                dr.title = re.title
                dr.CachedSize = re.cachedSize
                dr.relatedInformationPresent = re.relatedInformationPresent
                dr.hostName = re.hostName
                dr.directoryCategory = re.directoryCategory.fullViewableName
                dr.directoryTitle = re.directoryTitle
                dt.Rows.Add(dr)
            Next
            DataGrid1.DataSource = dt
            DataGrid1.DataBind()
            lblGoogleMessage.Text = r.searchComments
        End If
    End Sub
0
 
davidlars99Commented:
> but I still cannot get is to search one site?

I don't get it...
0
 
ladykhAuthor Commented:
I just need it to search the pages in the website I am creating, not all of google. If this is possible?
0
 
davidlars99Commented:
ok, now I think I got you now... are you trying to search your site using google web service..? I think it depends how much info google has about your site, however you can use MS Index Server or any other third party software for your site. There is also a cool feature that you can integrate into your website, here just copy and paste


<FORM method=GET action="http://www.google.com/search">
<input type=hidden name=ie value=UTF-8>
<input type=hidden name=oe value=UTF-8>
<TABLE bgcolor="#FFFFFF"><tr><td>
<A HREF="http://www.google.com/">
<IMG SRC="http://www.google.com/logos/Logo_40wht.gif"
border="0" ALT="Google"></A>
</td>
<td>
<INPUT TYPE=text name=q size=31 maxlength=255 value="">
<INPUT type=submit name=btnG VALUE="Google Search">
<font size=-1>
<input type=hidden name=domains value="PUT YOUR DOMAIN NAME HERE"><br><input type=radio name=sitesearch value=""> WWW <input type=radio name=sitesearch value="PUT YOUR DOMAIN NAME HERE" checked> PUT YOUR DOMAIN NAME HERE <br>
</font>
</td></tr></TABLE>
</FORM>
0
 
ladykhAuthor Commented:
Thanks for your help.
0
 
davidlars99Commented:
you're welcome!
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 6
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now