Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Introduction to the Live Search API : Page 3

You can use Live Search on your site through the Live Search Box or by using the Windows Live Search API.


advertisement
Customizing Your Search
There are a number of ways to customize the search and results returned, including:

  • Flags
  • Safe search
  • Searching for images
  • Spelling suggestions
  • Implementing paged or limited result sets
Flags
Setting flags on the search object allows further customization to a search query. Table 1 describes the full list of available flags.

Table 1. SearchFlags Options and Descriptions: The table lists and describes all the available search flags.

SearchFlag

Description



DisableHostCollapsing

Disable the suppression of more than two results from the same top-level URL for this SearchRequest. You should use this when developers want to ensure all results are returned.

DisableSpellCorrectForSpecialWords

Live Search Engine will ignore special words that are used in query operators when checking spelling.

MarkQueryWords

Search terms (query words) are returned, enclosed in a pair of UTF-8 characters, for this SearchRequest. You typically use this feature to highlight query words.

None

No flags are applied for this SearchRequest.


 
Figure 8. Using MarkQueryWords: The figure shows the search query results with query parameters marked in bold text.

As an example, here's a more detailed look at the MarkQueryWords flag. You use MarkQueryWords when you want to highlight query terms returned in the result set. The following code snippet shows how you use this to mark query terms in bold:

SearchRequest sRequest = new SearchRequest(); sRequest.Flags = SearchFlags.MarkQueryWords;

Figure 8 shows the change in the result set.

Safesearch
For users who are concerned with the content that may be returned in results, the API allows users to filter out sexually explicit images and text from search results using the SafeSearchOptions object.

Use SafeSearchOptions.Moderate to filter out explicit images or SafeSearchOptions.Strict to filter both explicit images and text:

SearchRequest sRequest = new SearchRequest(); sRequest.SafeSearch = SafeSearchOptions.Moderate;

 
Figure 9. Image Search: Here's an example response from an Image search.

Searching for Images
You can also use the API to search only for images. Using the SourceType.Image in the Source Request returns full-size and thumbnail image information such as size, height, width, and URI. The following code snippet shows how to use the search source and result fields to return images:

SourceRequest[] sr = new SourceRequest[1]; sr[0].Source = LiveSearch.SourceType.Image; sr[0].ResultFields = ResultFieldMask.Description | ResultFieldMask.Image | ResultFieldMask.Title;

You can see the results of the search in Figure 9. Table 2 shows the full list of valid SourceTypes.

Table 2. SourceType Options: Here's the full list of valid SourceTypes, with descriptions.

SourceType

Description

Image

SourceRequest returns full-size and thumbnail image information including file size, height, width, and URI.

InlineAnswers

SourceRequest returns answer results. InlineAnswers types include Encarta, Finance, Weather, and Movie ShowTimes. This option is reserved for commercial use.

News

SourceRequest returns results from online news services.

Phonebook

SourceRequest returns from online White Pages and Yellow Pages entries.

QueryLocation

SourceRequest returns the location of a local query based on input e.g., "coffee 98052", returns "coffee" in the title, "98052" in the description and the latitude and longitude of the geographic center of the ZIP code. This is limited to U.S. markets only.

Spelling

SourceRequest returns a spelling suggestion.

Web

SourceRequest returns Web page results.


Spelling Suggestions
Checking the spelling of a user's search criteria before performing a search is a great way to improve the usability of your system.

Users often misspell words in their search criteria, so spell-checking a user's search criteria before performing a search is a great way to improve the usability of your system. The following code snippet shows how you can use the Spelling SourceType to determine if the search criteria are spelled correctly:

SearchRequest sRequest = new SearchRequest(); SourceRequest[] sr = new SourceRequest[1]; sr[0].Source = LiveSearch.SourceType.Spelling; sr[0].ResultFields = ResultFieldMask.All; sRequest.Query = "vertual earth";

Implementing Paged or Limited Result Sets
Other great ways to improve usability of your search solution are limiting the total number of records returned or showing the results in a paged fashion. You can get the total number of results as shown below:

SearchResponse resp = serv.Search(sRequest); int total = resp.Responses[0].Total;

To control the number of results returned by a search, set the Count property:

SourceRequest[] sr = new SourceRequest[1]; sr[0].Count = 10;

When implementing a data paging solution, you need to know what page (or what record number for the first record of the page) you wish to display and the total number of records in a page. The API supports an Offset property that represents the record number from which to start retrieving results. The following code snippet retrieves five results starting at record number five:

SourceRequest[] sr = new SourceRequest[1]; sr[0].Count = 5; sr[0].Offset = 5;

This article demonstrated only the basics of a search solution, the possibilities are endless. Here are some useful links to help you get started and find more information:



Bronwen Zande is a director of Soul Solutions, based in Brisbane, Australia.With over 10 years of software development experience, Bronwen�s primary focus is Microsoft Live and .NET development. She is a Windows Live Services MVP and part of the core team that runs the ViaWindowsLive.com community site for Windows Live technologies. When not working with Windows Live, Bronwen helps bring together GeekGirls from around the globe.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date