Introduction to FAST Search API

Microsoft FAST Search for SharePoint provides enterprise search and information retrieval capabilities. FAST provides a API to query documents indexed in the server. The API is available in a proprietary assembly, Esp-SearchApi.

We will write a simple program to perform a search. We use the following namespaces.

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using Com.FastSearch.Esp.Search.Http;
using Com.FastSearch.Esp.Search.Result;

Search method

We write our Search method as follows.

private static IQueryResult Search(string url, string query)
{
    var factory = new HttpSearchFactory( new NameValueCollection 
        {{"Com.FastSearch.Esp.Search.Http.QRServers", url}});
    var engine = factory.GetSearchEngine(new Uri("http://" + url));
    return engine.Search(query);
}

There is quite a lot going on in the method. The method accepts an URL and a search query. URL refers to the FAST server URL. Search Query is what we are searching for in the indexed documents.

HttpSearchFactory is the factory class to instantiate the search engine. We pass the FAST server URL to the factory constructor. We use the GetSearchEngine factory method to get a search engine. The search engine has a Search method which performs the actual search. We pass the search query to the Search method.

The Search method returns a collection of documents. These documents are wrapped into a IQueryResult object.

Main method

Our Main method calls the Search method we defined earlier.

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var result = Search("fast-server-url", "meta.collection:collection-name");
            Console.WriteLine("Documents: " + result.DocCount.ToString());
            Console.ReadKey();
        }
    }
}

We send the query, meta.collection: collection-name to the search engine. This query is quite basic. It gets documents from a FAST collection. As you know, a collection stores the documents. So, this query gets few documents from the collection. We display the number of documents retrieved in the console. And wait for the user to exit the program.

Related Posts

Leave a Reply

Your email address will not be published.