1 Oct 2011

Use Search engine by Code SharePoint

 

Federated Search Object Model:  Can query multiple locations and merge all the results together.

Query Object Model: Query the index of SharePoint and FAST Search Server.

Search Engine Assemblies:
Microsoft.SharePoint.dll
Microsoft.Office.Server.dll
Microsoft.Office.Server.Search.dll

Federated Search Object Model

Important class:

QueryManager class

public sealed class QueryManager : List<LocationList> {
public QueryManager();
public string DefaultFASTSearchSort { get; set; }
public int Timeout { get; set; }
public bool TrimDuplicates { get; set; }
public string UserQuery { get; set; }
public XmlDocument GetResults(LocationList locationList);
public bool IsTriggered(LocationList locationList);
public void SendRequest(LocationList locationList, int count);
}



SearchServiceApplicationProxy class offers a lot of methods for managing federated locations by code


Query Object Model


Query Object Model allows querying only the SharePoint index


Kinds of search queries supported by SharePoint  are:


Keyword Query


SearchServiceApplicationProxy searchServiceProxy =
(SearchServiceApplicationProxy)
SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(site));
KeywordQuery keywordQuery = new KeywordQuery(searchServiceProxy);
// Define the query type
keywordQuery.ResultTypes = ResultType.RelevantResults;
keywordQuery.QueryText = searchTerms;
// Execute the query
ResultTableCollection result = keywordQuery.Execute();



 


 


Full Text SQL Query


SearchServiceApplicationProxy searchServiceProxy =
(SearchServiceApplicationProxy)
SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(site));
FullTextSqlQuery sqlQuery = new FullTextSqlQuery(searchServiceProxy);
// Define the query type
sqlQuery.ResultTypes = ResultType.RelevantResults;
sqlQuery.QueryText = String.Format(
"SELECT Title, Path FROM Scope() WHERE FREETEXT(‘{0}’)", searchTerms);
// Execute the query
ResultTableCollection result = sqlQuery.Execute();



 


 


Query Web Service


This is an ASMX service, which is available only in SharePoint Server 2010, and not in SharePoint Foundation 2010.


relative URL /_vti_bin/search.asmx


Search.asmx service is that internally it works with the Query Object Mode


Query queries the index and returns a generic structured XML response.


QueryEx queries the index and returns a DataSet of ADO.NET, serialized as XML.


QueryText element accepts a type attribute, which can assume a value of:
STRING To execute a keyword query.
MSSQLFT To execute a Full Text SQL query.
FQL ( FAST Query Language)

No comments:

Post a Comment