Shyli's Enterprise Search Platform Forum
Welcome Guest Active Topics | Log In | Register

New Topic Post Reply Tag as favorite
FAST ESP - Suggested Programming Model (.NET Search API)
shyli Offline
#1 Posted : Thursday, May 14, 2009 11:55:01 AM

Rank: Administration


Posts: 48
Points: 144
Location: USA
Thought this might be useful for folks developing .NET applications to integrate with FAST ESP backend

Create Search Factory (.NET Search API)

Establish the Search Engine factory. The following example will use the default implementation:

Code:
ISearchFactory factory = SearchFactory.NewInstance();


Get Search View (.NET Search API)

Retrieve a list of all available Search Views and iterate through the list to get the one you need:

Code:
ArrayList viewList = factory.GetSearchViewList();


Create Query (.NET Search API)

Assemble a query object (IQuery). Typically, you assemble the object with the search string.

Code:
IQuery query = new Query(queryString.Text);


Assign a set of desired parameters to the query.

Code:

query.SetParameter(BaseParameter.CLUSTERING,cbClustered.Checked);
query.SetParameter(BaseParameter.SPELL, cbSpellcheck.Checked ? "1" : "suggest");


The following parameters enable Navigation (Navigators) and define the maximum number of results for
the Navigation algorithm (10000) results:

Code:

query.SetParameter(BaseParameter.NAVIGATION, true);
query.SetParameter(BaseParameter.NAVIGATION_DEEPHITS,10000);


Submit Query and Retrieve Results (.NET Search API)

Get the search results (IQueryResult).
To do this, use the Search() method exported by the ISearchView object:

Code:
IQueryResult result = searchView.Search(query);


The Search() method is the one that actually performs the search by contacting the QRserver.

Query Result Handling

Following are typical sequence of operations required to iterate over the results returned from the
Search Engine.

Some of the indicated steps may not be applicable for your application's feature set.

The methods all start from a result of type IQueryResult as described above.

Retrieve Document Summaries (.NET Search API)

The following main methods can be applied to a query result of type IQueryResult:
To retrieve a document at position N within the result set:

Code:
IDocumentSummary docSum = result.GetDocument(N);


To retrieve a specific summary field from a document summary:

Code:
IDocumentSummaryField titleField = docSum.GetSummaryField(titleName);


To retrieve the actual value from the document summary field:

Code:
string title = titleField.Summary();


The results may be retrieved using different Search Views. The GetDocument() method exported by the
IQueryResult interface returns the results ordered by relevance (or whatever sorting you specify in the
query).
You can also retrieve the results in a clustered view according to either a predefined taxonomy (supervised
clustering) or according to an on-the-fly generated taxonomy (unsupervised clustering).

Result Clustering (.NET Search API)

To retrieve the results according to the clustered view, use the Cluster property of the IQueryResult object
to get the default cluster (ICluster) and then traverse this cluster and its children as follows:

1. Get the default result cluster:

Code:
ICluster cluster = result.Cluster;


In FAST ESP there is only one cluster returned, where the supervised and unsupervised sub-nodes
represents the supervised (ā€œSā€) and unsupervised (ā€œUā€) clusters, respectively.

2. Create an interator over the nodes within the supervised or unsupervised clustering sub-tree.The example
iterates over all supervised clustering nodes:

Code:
System.Collections.IEnumerator e = cluster.Nodes("S");


3. Iterate over the documents within the supervised clustering nodes. To be able to traverse the clustered
view arbitrarily deep, use a recursive method:

Code:

while ( e.MoveNext())
{
IClusterNode clusterNode = (IClusterNode) e.Current;
System.Collections.IEnumerator s1 = clusterNode.SubNodes();
while ( s1.MoveNext())
{
IClusterNode subNode = (IClusterNode) s1.Current;
System.Collections.IEnumerator d = clusterNode.Documents();
while( d.MoveNext())
{
IDocumentSummary summary = (IDocumentSummary) d.Current;
...
}
}
}


This will return all cluster nodes and all results within the nodes. The IDocumentSummary represents the
returned fields of the query result entry.

4. Information about number of documents within each cluster node can be retrieved as follows:

As found by the result clustering algorithm (i.e. within the extended result set used as basis for
clustering):

Code:
int nodeCount = clusterNode.DocumentCount();


As DocumentCount() but also including documents in sub-nodes of the tree:

Code:
int totalCount = clusterNode.TotalDocumentCount();


Get number of documents within the cluster node and its sub-nodes as found by the Taxonomy Index
function.
In this way the Search Front End may display the total number of hits within the category and
below, even if the number is large.
You may also use this method even if there are no hits returned for
this category (DocumentCount()=0).
In this way it is possible to list all matching categories to the query
with corresponding number of hits.

Code:
int extendedCount = clusterNode.ExtendedDocumentCount();


Navigation (.NET Search API)

Following are the Navigation related methods that can be applied to a query result of type
iquery_result and the individual navigators of type inavigator.

Iterate over the navigators from the IqueryResult method. Each navigator corresponds to an indexed field
that is configured for Navigation in the Index Profile.

Code:
System.Collections.ICollection navigators = null;
try
{
navigators = result.Navigators();
}
catch (Exception)
{}
if (navigators != null && navigators.Count > 0)
{
IEnumerator nav = navigators.GetEnumerator();
while ( nav.MoveNext())
{
INavigator navigator = (INavigator)nav.Current;
string navName = navigator.DisplayName;
...
if ( navigator.Type==no.fast.ds.search.NavigatorType.INTEGER )
{
int minValue = navigator.Min;
...
}
}
}


For each Navigator you can retrieve information relevant for how to present the navigator in the query
result page:
A human readable name for the Navigator:

Code:
string name = navigator.DisplayName;


Return the unit (e.g. `lbs') for the navigator:

Code:
string unit = navigator.Unit;


Return the number of query results within the navigator:

Code:
int hits = navigator.Hits;


Get max/min/mean value for the navigator:

Code:
double max = navigator.Max;
double min = navigator.Min;
double mean = navigator.Mean;


Iterate over the modifiers within the navigator:

Code:
System.Collections.ICollection modifiers = null;
try
{
modifiers = navigator.Modifiers();
}
catch (Exception)
{}
if (modifiers != null && modifiers.Count > 0)
{
IEnumerator mod = modifiers.GetEnumerator();
while ( mod.MoveNext())
{
IModifier modifier = (IModifier) mod.Current;
string modName = modifier.Name;
...
}
}


Each modifier corresponds to a `bin' within the navigator, e.g. a price range. Get the display name and
document count for the modifier:

Code:
string modName = modifier.Name;
int modCount = modifier.Count;


When you want to perform a drill-down query, create an INavigation object and define a set of adjustment
groups (IAdjustmentGroup class):


Code:
INavigation navigation = new Navigation();


Add an Adjustment Group (see section Navigators) to the INavigation object.You typically add a number
of adjustment groups (e.g. identifying one `bin' within the navigator) to the object and then perform a
drill-down query.


Code:
IAdjustmentGroup adjGroup = navigation.Add(navigator);


Add an Adjustment to the IAdjustmentGroup object. The adjustment corresponds to the IModifier object
as discussed above, e.g. a given value range:


Code:
IAdjustment adjustment = adjGroup.Add(modifier);


The default modify mode is applied, i.e. INCLUDE.You may add more than one adjustment to the group,
which corresponds to drilling down into multiple bins within a navigator, e.g. a price range given by two
bins or two discrete values for a string navigator.

Create a drill-down query based on the Adjustment Group defined. The first method creates a new query
based on the drill-down parameters only (i.e. not taking into consideration the original query). The second
method appends the drill-down parameters to the original query (drill-down within the query result set)


Code:
IQuery newQuery = navigation.CreateNavigatedQuery();
IQuery newQuery = navigation.CreateNavigatedQuery(IQuery original);
Freddiemaize
#2 Posted : Wednesday, July 01, 2009 9:27:28 AM

Rank: Guest

Posts: 141
Points: 470
Hey Shyli, You site on FAST ESP (http://shyli.com/?p=74) is wonderful. Bookmarked. Thanks

Freddie
http://freddiemaize.wordpress.com
Guest
#3 Posted : Wednesday, October 28, 2009 7:09:40 AM

Rank: Guest

Posts: 141
Points: 470
where to download "com.fastsearch.esp.search.SearchFactory " packages?
how to use it in visual studio 2008
Guest
#4 Posted : Thursday, October 29, 2009 10:34:17 PM

Rank: Guest

Posts: 141
Points: 470
There is no package called com.fastsearch.esp.search.SearchFactor
You have to get ESP-SearchAPI.dll to use with Visual Studio 2008
It comes with FAST ESP installations.

You may also need other dlls like UserSID.dll and UserSIDLib.dll if you want to do secure search.
Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply Tag as favorite
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.