FAST SharePoint Integration: Execute a Simple Query

This is a continuation in my FAST coding mini-series for SharePoint folk.  The bit of code below executes a search for the term "test" in FAST via a Console application.  Obviously, it’s a hop, skip and jump away to wrap this logic inside a web part or application page:

 

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

namespace Conchango
{
    class InvokeSimpleFASTQuery
    {
        static void Main(string[] args)
        {

            #region Initialize our communication with FAST
            ISearchFactory searchFactory;

            NameValueCollection nameValueCollection = new NameValueCollection();

            nameValueCollection.Add("fastsearchengine", "Com.FastSearch.Esp.Search.Http.HttpSearchFactory");
            nameValueCollection.Add("Com.FastSearch.Esp.Search.Http.QRServers", "fastdemoback:15100");
            nameValueCollection.Add("Com.FastSearch.Esp.Search.Http.RequestMethod", "GET");

            searchFactory = SearchFactory.NewInstance(nameValueCollection);

            #endregion

            #region Launch a query

            string queryString = "test";

            Query query = new Query(queryString);

            query.SetParameter(BaseParameter.CLUSTERING, false);
            query.SetParameter(BaseParameter.NAVIGATION, true);
            query.SetParameter(BaseParameter.NAVIGATION_DEEPHITS, 100);

            ISearchView searchView;
            searchView = searchFactory.GetSearchView("sharepointconn");

            IQueryResult result = searchView.Search(query);

            Console.WriteLine("Total results from search: [" + result.DocCount + "].");

            int docCounter = 0;

            while (docCounter < result.DocCount)
            {

                docCounter++;

                IDocumentSummary thisDocSummary = result.GetDocument(docCounter);

                Console.WriteLine("[" + docCounter + "]: " + thisDocSummary.GetSummaryField("url").StringValue);

            } // while

            Console.ReadLine();
            #endregion

        }
    }
}

It generates the following result:

image

</end>

Subscribe to my blog.

Technorati Tags: ,

2 thoughts on “FAST SharePoint Integration: Execute a Simple Query

  1. Paul Galvin

    Alvin, you probably figured this out already, but here goes…

    I don’t know the answer, but I recall that I was getting zero views because something was wrong in terms of my server port config and that sort of thing. It’s very picky.

    Reply
  2. Alvin

    Got a quick question for you, Paul. I’ve been trying to find out how to create these search views as it keeps returning 0 for GetSearchViewList().Count. Can you point me in the right direction?

    Thanks,
    Alvin

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *