?
Solved

Google web service in asp.net web application

Posted on 2005-03-23
12
Medium Priority
?
196 Views
Last Modified: 2010-04-07
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
Comment
Question by:ladykh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
12 Comments
 
LVL 11

Expert Comment

by:sachiek
ID: 13618304
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
 
LVL 11

Expert Comment

by:sachiek
ID: 13618391
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
 
LVL 11

Expert Comment

by:sachiek
ID: 13618417
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 13

Expert Comment

by:davidlars99
ID: 13618532
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
 
LVL 13

Expert Comment

by:davidlars99
ID: 13618546
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
 
LVL 13

Expert Comment

by:davidlars99
ID: 13618552
this tool will show you everything in details about what some particular WS requires, it made lots of thing very easy for me...
0
 

Author Comment

by:ladykh
ID: 13633661
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
 
LVL 13

Expert Comment

by:davidlars99
ID: 13633812
> but I still cannot get is to search one site?

I don't get it...
0
 

Author Comment

by:ladykh
ID: 13633867
I just need it to search the pages in the website I am creating, not all of google. If this is possible?
0
 
LVL 13

Accepted Solution

by:
davidlars99 earned 2000 total points
ID: 13634145
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
 

Author Comment

by:ladykh
ID: 13634223
Thanks for your help.
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13634233
you're welcome!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question