[TUT] Search API

Posts 1–5 of 5 · Page 1 of 1
[TUT] Search API
Search API in VB.net Using the SOAP API of LiveSearch

This was going to be a TUT on using google API search (Soap API) , but the Tut has changed for good reasons, they have discontinued the Google Search API and replaced it with the Search Ajax API (which isn't suitable for us at this time)

Instead this will be a TUT on using Microsoft© Bing SOAP API to add a Search Engine feature to your VB.net application.

1st you will need a AppID you can get that by going to

Code:
http://www.bing.com/developer
if it doesn't show the * = B I N G
Once you get your APPID you need the LiveSearch API, and you are going to need your APPID to get this

Open up VB.Net and in your solutions explorer , right click your project name and click add service reference.

In the addressbar add the following address

Code:
http://api.search.live.net/search.wsdl?AppID=YOUR_APPID
Replace Your_APPID with your actual AppId, You should now see a reference to liveSearch API
On the bottom change the name of the service to something practical , something like "LiveS"
Click Ok, and View your code, adding the reference is not enough, now we need to Import and Declare.


In the Namespace (Upper most part of the code page)

Code:
Imports appname.lsearch
We will also need to use StreamReader , to use this we need to also

Code:
Imports System.Text
Note: Appname = Your application name, so if your app was called Search, it would be search.Lsearch Add a TextBox and Button to your form and a webbrowser to display results

Note: Using a Webbrowser is easiest for this tut, yes you can display results in Listviews etc, but then would need to generate more code for links etc...


Code:
'Button Click Event
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim client As New LiveSearchPortTypeClient()
        Dim request As New SearchRequest()
        Request.AppId = **************** ' * = Your AppID
        request.Sources = New SourceType() {SourceType.Web}
        request.Query = TextBox1.Text
        Dim response As SearchResponse = client.Search(request)
        DisplayResults(response.Web.Results)
    End Sub
'Displays Results in the webbrowser
    Private Sub DisplayResults(ByVal results As WebResult())
        Dim sb As New StringBuilder()
        results.ToList().ForEach(Function(x) sb.Append        (GetFormattedResult(x)))
        WebBrowser1.DocumentText = sb.ToString()
    End Sub

    Private Function GetFormattedResult(ByVal result As WebResult) As String
        Dim formattedResult As String = (("<a href=" & result.Url & ">") + result.Title & "</a><br/>") + result.Description & "<br/><br/>"
        Return formattedResult
    End Function
I gave the code as a method for C&P, I didn't add images but only because I don't have PShop on this laptop, and I'm doing this side by side with work I wasn't leaving this laptop

HAVE FUN!!!!!!! This is number two of my now 10 tut requests , glad to be done with it
Hm, look like i posted a little to late in your other topic (http://www.mpgh.net/forum/33-visual-...oogle-api.html).

I'll read it, looks pretty cool.

EDIT: "adding the reference is not enouph" I think it should be enough.

EDIT2: So, looks nice. Is this suppose to be like a private search engine, using BING's way to search or whatever?
@spelling , Thank you

@ Topic

Example of Uses would be creating a application that searches a specific site and displays it's results, Example: You can use this to create a MPGH.net Search Application, Use the LiveSearch Tip/Trick and Search

Replace

Code:
Request.Query = textbox1.text
With

Code:
request.Query = request.Query + "site:mpgh.net " & TextBox1.Text
and you now have a application that searches MPGH.net for anything you wish, In a sense it's the first Mpgh.net Desktop Search widget now everyone race to make it and take credit for it
Quote Originally Posted by NextGen1 View Post
@spelling , Thank you

@ Topic

Example of Uses would be creating a application that searches a specific site and displays it's results, Example: You can use this to create a MPGH.net Search Application, Use the LiveSearch Tip/Trick and Search

So add Site:mpgh.net + textbox1.text to the query and you now have a application that searches only mpgh.net
Epic win :P

Your welcome too, i read the whole thing and didn't see any others.
Not to double post(ish) I edited above as well but to further the example:

Quote Originally Posted by nextgen1
Replace

Code:
Request.Query = textbox1.text
With

Code:
request.Query = request.Query + "site:mpgh.net " & TextBox1.Text
and you now have a application that searches MPGH.net for anything you wish, In a sense it's the first Mpgh.net Desktop Search widget .......... now everyone race to make it and take credit for it
Posts 1–5 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us