Welcome to EMC Consulting Blogs Sign in | Join | Help

Paul Galvin's Blog

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: ,
Published 08 April 2008 17:06 by Anonymous
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Hannes Beukes said:

Thanks for this amazing post. Really saved me dayz and dayz of work.

Im busy integrating fast esp to silverlight and u helped tremendously.

beukes2@gmail.com

September 16, 2009 10:19
 

Alison said:

Paul, good evening.

You have a example to use the navigation or modifier to filter a query using the FAST api?

I did a project that do the search. And i get the navigator's and modifier's created in the view collection, but i don't know how to use this result.

November 11, 2009 19:48
 

caitlynbarker said:

thanks for your post it really helps me on my business...keep it up..

<a href="http://www.kpicapital.com/">KPI</a>">http://www.kpicapital.com/">KPI</a>

<a href="http://www.kpicapital.com/">KPI Capital</a>

September 5, 2010 07:19

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server (Personal Edition), by Telligent Systems