Home > Technical > FAST ESP – Using .NET search API for Query Integration

FAST ESP – Using .NET search API for Query Integration

For detailed discussions, also visit following site for detailed article

http://fastesphelp.com/default.aspx?g=posts&t=11

FActory Interfaces (.NET Search API)

ISearchFactory Interface (.NET Search API)

 

ISearchFactory provides two approaches for connecting to the QRserver:

One approach takes no parameters, but relies on the properties being specified in the

com.fastsearch.esp.search.SearchFactory.properties file.

Default value is the HttpSearchFactory factory instance:

 

ISearchFactory factory = SearchFactory.NewInstance();

 

A second approach requires you to instantiate a Search Factory based on a

System.Collections.Specialized.NameValueCollection object. If the key

com.fastsearch.esp.search.SearchFactory is not found in this collection, the

com.fastsearch.esp.search.http.HttpSearchFactory will be used as factory. If this is the case, the following

variables may be set through this object, where only the first is mandatory:

• List of servers separated by commas. Example: “host1:15100,host2:15100″ etc:

Com.FastSearch.Esp.Search.Http.QRserver

• Certificatefile when using SSL:

Com.FastSearch.Esp.Search.Http.CertiticateFile

• Define which request method you wish to use. GET is default, but POST must be used if the QBE feature

should function properly:

Com.FastSearch.Esp.Search.Http.RequstMethod

57

Using the .NET Search API

• Optional parameter to set if persistent connection will be used. Default is true:

Com.FastSearch.Esp.Search.Http.KeepAlive

• Optional parameter to set the maximum number of connections that the API will make to one qrserver

simultaniously. Default is 10:

Com.FastSearch.Esp.Search.Http.MaxConnections

The NameValueCollection should then be used as an argument:

ISearchFactory factory = SearchFactory.NewInstance(myNameValueCollection);

Search View Interfaces (.NET Search API)

A Search View is used to submit queries to the QRserver.This section introduces the recommended interfaces

used to create and manage a Search View.

ISearchView Interface (.NET Search API)

Information regarding a Search View’s assigned content, structure, enabled features and query result

presentation options can be retrieved through the ISearchView interface. More importantly, this interface

provides methods for executing a query.

• Retrieve an instance of a Search View:

ISearchView searchView = factory.GetSearchView(String viewName);

• Return a list of all Search Views:

ArrayList list = factory.GetSearchViewList();

• Return the content specification for this Search View:

IContentSpecification conSpec = searchView.GetContentSpecification();

• Return the content structure applied for this Search View:

IContentStructure conStruc = searchView.GetContentStructure();

• Return the search specification for this Search View:

ISearchSpecification searchSpec = searchView.GetSearchSpecification();

• Return the result specification for this Search View:

IResultSpecification resultSpec = searchView.GetResultSpecification();

• Return the presentation specification for this Search View:

IPresentationSpecification presentSpec =

searchView.GetPresentationSpecification();

IContentStructure Interface (.NET Search API)

A Search View’s content structure provides a representation of the FAST ESP Index Profile fields and features.

• Return all fields from the Index Profile, used by this Search View:

ArrayList list = conStruc.GetFields();

58

FAST Enterprise Search Platform

• Check whether compression is enabled or not for this Search View. Returns true if enabled:

Boolean compressionStatus = conStruc.IsCompressionEnabled();

• Return an IField instance representing the requested Index Profile field:

IField field = conStruc.GetField(String fieldName);

IContentSpecification Interface (.NET Search API)

The content specification specifies what content is to be searched by the Search View. It will limit the search

to one or more FDS collections and optional filter expressions which can constrain the searchable content in

other ways (by taxonomy or other meta data).

• Return a list of all collections that are applied to this Search View:

ArrayList collections = conSpec.GetCollections();

• Return a list of all filters applied to this Search View:

ArrayList filters = conSpec.GetFilterTerms();

• Decide whether a specific collection is used by a Search View:

Boolean inUse = conSpec.HasCollection(String collection);

ISearchSpecification Interface (.NET Search API)

Defines the search features set for the queries, such as linguistic query parameters.

• Check to see if lemmatization is enabled:

Boolean lemma = searchSpec.IsLemmatizationEnabled(String fieldName);

• Check to see if spell checking is enabled for a certain language:

Boolean spell = searchSpec.IsSpellCheckEnabled(String language);

IResultSpecification Interface (.NET Search API)

Determines what part of the matching documents are returned, in what order they are presented and how

they are presented.

• Return a list of all available navigators:

ArrayList navigators = resultSpec.GetNavigators();

• Return a specific navigator:

INavigator nav = resultSpec.GetNavigator(String name);

• Return a specified result view. Alternatively a list of all specified result views:

IResultView resultView = resultSpec.GetResultView(String name);

The IResultView interface contains methods which return information regarding the specific result view

specified for this View.

• Return the name of the result view:

String resultView = resultView.GetName();

• Return a list of all fields that are part of this result view:

ArrayList resultFields = resultView.GetFields();

59

Using the .NET Search API

IPresentationSpecification Interface (.NET Search API)

This interface includes methods for retrieving specifications on how a given Search View handles scope-search

and how it presents query results. The presentation interface IPresentationSpecification must first be

instantiated.

This interface includes methods for retrieving specifications on how a given Search View handles scope

search and how it presents query results. The presentation interface IPresentationSpecification must first

be instantiated.

• Return the interface providing methods for accessing scope-search specifications:

IScopeSearchSpecification scopeSpec =

presentationSpec.GetScopeSearchSpecification();

• Return the interface providing methods for accessing result presentation specifications:

IResultPresentation resultPres =

presentationSpec.GetResultPresentation();

For a more detailed description of syntax, please see Search API Reference Pages.

Query Interfaces (.NET Search API)

IQuery Interface (.NET Search API)

An instance of the ISearchView interface is a prerequisite to submitting queries. IQuery represents a query

that can be submitted to the Search View.You only need to use this interface in case the query consists of

more query parameters than the actual QUERY string itself.

• Create a new search parameter, specifying the desired type of parameter through the BaseParameter

class. The second parameter enables spell checking by supplying the string value “1″.

query.SetParameter(BaseParameter.CLUSTERING,cbClustered.Checked);

query.SetParameter(BaseParameter.SPELL, cbSpellcheck.Checked ? “1″);

• Retrieve the value of previously set Base Parameters. Similar methods exist for all parameters:

String valueOfSpellPar = query.Spell();

boolean valueOfClusterPar = query.ClusteringEnabled();

• Parameters can then be passed to the IQuery object.

IQuery query = new Query(queryString, pars);

• Submit a query to the QRserver using the IQuery interface:

IQueryResult result = searchView.search(query);

• Submit a query to the QRserver without using the IQuery interface:

IQueryResult result = searchView.search(String queryString);

The connection parameter value specifies for how long one can wait for a query response, before the client

drops the request. This value can be overridden by setting BaseParameter.TIMEOUT.

• For more information regarding available parameters and their settings, refer to the Query Language and

Parameters guide.

• For a more detailed description of syntax, see Search API Reference Pages.

Submitting Queries Using the HTTP Search Engine (.NET Search API)

The following procedure describes how to query the result views without using search views.

60

FAST Enterprise Search Platform

Important: You will not have load balancing or failover functionality when using the HTTP search engine

object directly.

1. Create an instance of the HttpSearchEngine class..

HttpSearchEngine se = searchFactory.GetSearchEngine(new Uri(“http://host:port”));

2. Create a query using the IQuery interface.

IQuery q = new Query(“hello”);

3. Add a parameter to the query, specifying the result-view.

q.setParameter(BaseParameter.RESULT_VIEW, “myresultview”);

Tip: For an overview of the parameters that can be applied to a query, refer to the Query Language

and Parameters documentation.

4. Submit the query.

se.search(q);

Basic Result Processing Interfaces (.NET Search API)

This section describes the recommended interfaces and methods.

Refer to Search API Reference Pages for a complete reference.

IQueryResult Interface (.NET Search API)

The IQueryResult interface represents the result of a query. The result set contains the Document Summary

(containing the textual content of the returned fields), query transformations, Clustering and Navigation

information for the result.

• This method returns the clustering information:

ICluster cluster = result.GetCluster();

• Return query transformations used. By supplying a false parameter, the initial transformations are returned.

Transformations for a resubmitted query can be retrieved by setting the parameter to true:

IQueryTransformations transformations =

result.GetQueryTransformations(false|true);

• Return the number of hits/documents the result contains:

int hits = result.GetDocCount();

IDocumentSummary Interface (.NET Search API)

The IDocumentSummary Interface represents a Document Summary in a QueryResult. The document

summary contains a set of fields defined in the Index Profile of the search engine returning the results.

61

Using the .NET Search API

• Retrieve an instance of the IDocumentSummary interface, representing a document at a given index within

the result:

IDocumentSummary docSum = result.GetDocument(1);

• Return the summary field, specified by the argument, for this document summary:

IDocumentSummaryField sumField = docSum.GetSummaryField(“title”);

• Return an iterator for the summary fields in this document summary:

Collection iterator = docSum.SummaryFields();

IDocumentSummaryField Interface (.NET Search API)

The IDocumentSummaryField Interface represents one result field in an IDocumentSummary. The field is

identified by a name and has a summary attribute of one of the types specified in IDocumentSummaryTypes.

• Retrieve the summary field, specified by the argument, for this document summary.

IDocumentSummaryField sumField =

docSum.getSummaryField(“title”);

• Return the type of this summary field:

FieldType type = sumField.GetType();

• The content of the summary field can be retrieved as an integer, double, string or float. The respective

methods can be found within the interface. Here is an example of returning the summary as an integer:

int summary = sumField.GetIntValue();

Note: Please note the difference between a Search Engine Cluster (a way of grouping Search Engines

within FAST ESP) and a Result Cluster (unsupervised/supervised result clustering used for categorization).

For a more detailed description of syntax, please see Search API Reference Pages.

Query Transformation Interfaces (.NET Search API)

IQueryTransformations Interface (.NET Search API)

The IQueryTransformations Interface is an interface that provides methods to find named modifications or

suggestions contained in the query result.

A query transformation can be one of two types: a modifications or a suggestion. A modification results in

changes to the query that is submitted to the search engine while a suggestion leaves the query unchanged

and is merely returned together with the result as information on how to potentially improve the query.

• Returns a collection containing all the query transformations in this query result:

Collection qtfs = transformations.GetAllQueryTransformations();

• Return a collection containing all the query transformations in this query result that are modifications:

Collection modifications = transformations.GetModifications();

• Return a collection containing all the query transformations in this query result that are suggestions:

Collection suggestions = transformations.GetSuggestions();

• Return the query that was submitted to the search engine:

String submitted_query = transformations.GetSubmittedQuery();

62

FAST Enterprise Search Platform

IQueryTransformation Interface (.NET Search API)

The IQueryTransformation Interface represents one query transformation performed on the submitted query.

The query transformation can be a modification of the original query or just a suggestion on how to improve

the quality of the query.

• Return the action of the transformation:

String action = queryTrans.GetAction();

• Return the name of the transformation:

String name = queryTrans.GetName();

• Return the query after the transformation:

String queryAfterTrans = queryTrans.GetQuery();

Refer to Query Transformations in the Query Language and Parameters Guide, or Search API Reference

Pages for details on available query transformations.

For a more detailed description of syntax, see Search API Reference Pages.

Result Clustering Interfaces (.NET Search API)

ICluster Interface (.NET Search API)

The ICluster Interface represents a clustered view of the documents in a query result. Used in association

with Result Clustering and Categorization.

Only one cluster is returned, which is named default. Within the default cluster there are two types of nodes:

• Supervised: Cluster nodes returned by the Supervised Clustering (categorization) algorithm. The

corresponding type used in the API methods is “S”.

• Unsupervised: Cluster nodes returned by the Unsupervised Clustering algorithm. The corresponding type

used in the API methods is “U”.

• Return the number of top nodes in the cluster:

int top_nodes = cluster.NodeCount();

• Return an iterator of the names of the top nodes in this cluster:

Collection iterator = cluster.NodeNames();

IClusterNode Interface (.NET Search API)

The IClusterNode Interface represents a node (category node for supervised clustering) within the cluster.

Each node contains one or more documents from the result set.

• Return an iterator of the documents in the cluster node:

Collection documents = clusternode.Documents();

• Return a document at a given index:

IDocumentSummary document = clusternode.GetDocument(1);

• Return the type of the node as a String:

String type = clusternode.GetType();

63

Using the .NET Search API

For a more detailed description of syntax, see Search API Reference Pages.

Navigator Interfaces (.NET Search API)

INavigator Interface (.NET Search API)

The INavigator Interface is a navigator in structured content. A Navigator instance represents exactly one

structured “aspect” of a query result, e.g. “size of document”, “author rating” or a discrete element such as

“author’s academic degree”. These elements may be divided into a set of intervals, which are represented

by modifiers.

• Return the human readable name of a given navigator:

String name = navigator.GetDisplayName();

• Return the type of a given navigator:

NavigatorType type = navigator.GetType();

• Return the score, as reported by the search engine:

double score = navigator.GetScore();

• Return an iterator with the modifiers, of type IModifier, used in the navigator:

Collection modifiers = navigator.Modifiers();

IModifier Interface (.NET Search API)

The IModifier Interface is a modifier that represents exactly one interval in exactly one Navigator (a bin) and

is able to produce a modified version of the original query, which will only return results within that interval.

Your application can use an IModifier, in conjunction with a ModifyMode (these are grouped into an

IAdjustment), to retrieve specific information from the associated Navigator.

• Return the internal value of the modifier:

String value = modifier.GetValue();

• Return the number of documents the modifier holds:

int numDoc = modifier.GetCount();

INavigation Interface (.NET Search API)

The INavigation Interface is a type representing a state of navigation. An INavigation can specify several

IAdjustmentGroups, each associated to exactly one INavigator. Each group consists of a set of IAdjustments,

each of which specifies one IModifier and a ModifyMode.

When the user has navigated and signals a new query, apply current navigation state to the query by calling

the instrument method.

• Add a new adjustment group, IAdjustmentGroup, to the specified navigator:

IAdjustmentGroup adjustGroup = navigation.Add(navigator2);

• Apply the navigation changes to the query:

navigation.Instrument(query);

• Clear the contents of the navigation:

navigation.Clear();

64

FAST Enterprise Search Platform

Note: The Navigation/Adjustment API interfaces does not support Scope Navigators. Details on how to

use Scope Navigators can be found in the Query Language and Query Parameters documentation.

IAdjustmentGroup Interface (.NET Search API)

The IAdjustmentGroup Interface is a type that represents a selection of IAdjustments, which are logically

OR’ed. Each adjustment group is in turn AND’ed with the other adjustment groups of an INavigation instance.

• Add an adjustment, IAdjustment, to this group:

IAdjustment adjustment = adjustGroup.Add(modifier);

• Remove a specified IAdjustment:

adjustGroup.Remove(adjustment);

• Return the filterterm produced by this adjustment group alone:

String filterTerm = adjustGroup.GetFilterTerm();

• Clear an adjustmentgroup:

adjustGroup.Clear();

IAdjustment Interface (.NET Search API)

The IAdjustment Interface is a convenience interface that represents an IModifier, ModifyMode pair. Using

these classes, your application can drill-down into (retrieve information) specific to a particular bin (IModifier)

within a Navigator. The ModifyMode governs the scope, depth and constraints of this retrieval. Used as

components of IAdjustmentGroups and INavigation.

• Return the IAdjustmentGroup object owning this adjustment:

IAdjustmentGroup ajustGroup = adjustment.GetAdjustmentGroup();

• Return the filterterm produced by this adjustment alone:

String filter = adjustment.GetFilterTerm();

• Return the IModifier object for this adjustment:

IModifier modifier = adjustment.GetModifier();

• Return the modifiervalue for this adjustment:

String modifierValue = adjustment.GetModifierValue();

• Return this adjustment’s modifymode:

ModifyMode modifyMode = adjustment.GetModifyMode();

• Refer to Navigators for functional details.

• For a more detailed description of syntax, see Search API Reference Pages.

• Refer to Modify Mode or the online API documentation, for more information regarding details on the

supported modes.

Note: The API (including the API online documentation) supports additional navigator types that is

currently not possible to configure within FAST ESP.

Handling Query Errors (.NET Search API)

Query errors will appear as an exception to the Search() method within the ISearchView interface. Instead

of printing the full .NET exception, it is possible to catch the specific exception with its error code and error

message.

65

Using the .NET Search API

Example:

try {

IQueryResult result = searchView.Search(query);

} catch (SearchEngineException e) {

Console.WriteLine(“Error ” + e.Message + “: ” + e.Type.ToString());

}

A nonzero error code indicates query related error messages. Refer to the table in Error messages for a list

of the defined error codes returned and their explanation.

Enable SSL on .NET Search Client

This topic describes how to enable SSL on a .NET Search Client.

Note: The openssl command relies on access to the $FASTSEARCH/bin directory and should therefore

be executed where access to this directory is possible.

1. Generate pkc12 file:

openssl pkcs12 -export -out client.p12 -in Client.pem

2. Import p12 file into Certificate Store (double-click on p12 file, and select personal store as location for

certificate import) .

3. Generate cer file:

openssl x509 -in Client.pem -out client.cer -outform DER

4. Specify client.cer file as parameter when creating the SearchFactory? using this parameter:

Com.FastSearch.Esp.Search.Http.CertificateFile

5. The parameter can be specified using one of the following approaches:

• Set the parameter in App.config

• Set the parameter in Web.config

• Specify the parameter in the NameValueCollection passed as an argument when creating the

SearchFactory.

 

Author: Shyli
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.