Freigeben über


HOW TO : Customize the Enterprise Search in MOSS 2007

+) Customizing the Search is Required for Wild Card Search and Complex Boolean
Search which are not supported OOB in MOSS
+) Customizing the Enterprise Search in Moss Can be Done using FullTextSQLQuery
API
+) Need to create an instance of FullTextSQLQuery Class
+) Need to build the Query property Using Freetext predicate or Contains Predicate
with respect to the Requirement
+) The Following Queries will Explain in Detail about using Contains Predicate and
Freetext Predicate in Search

Implementing Wild card Search

FullTextSqlQuery ftQuery = new FullTextSqlQuery(ServerContext.Current);
ftQuery.QueryText = "SELECT Title, Path, Rank FROM Scope() WHERE
CONTAINS('"Sharepo*"') AND \"Scope\"='All Sites' ORDER BY Rank DESC";

Note : Wildcard search is possible only using Contains Predicate. There wil not be
relevent ranking result if we use contains Predicate. So we cannot expect Relevant
ranking in Wildcard search.

Once we build the Query then we need to Execute the Query and Fetch the results and
can display in the Datagrid. The Following Sample Explains it

ftQuery.ResultTypes = ResultType.RelevantResults;
ResultTableCollection oResultCollection = ftQuery.Execute();
ResultTable oResult = oResultCollection[ResultType.RelevantResults];
DataTable dtResults = new DataTable();
dtResults.TableName = "Result";
dtResults.Load(oResult, LoadOption.OverwriteChanges);
DataSet ds = new DataSet("All_Results");
ds.Tables.Add(dtResults);
datagrid.DataSource = ds.Tables[0];

Implementing Boolean AND and OR Search

Boolean OR and AND Search can be implemented using FREETEXT predicate. the
Following Code Explains how to build the Query for Boolean Search. Frretext
Predicate Search will give the relevant ranking result.

For OR Boolean search: Keyword1 OR Keyword2

FullTextSqlQuery ftQuery = new FullTextSqlQuery(ServerContext.Current);
ftQuery.KeywordInclusion = KeywordInclusion.AnyKeyword // will search for any (OR
operation) keyword in the Freetext Predicate
ftQuery.QueryText = "SELECT Title, Path, Rank FROM Scope() WHERE
FREETEXT(defaultproperties,'Keyword1 Keyword2') AND \"Scope\"='All Sites' ORDER BY
Rank DESC";

Note: If the keywordInclusionProperty is Anykeyword then any keyword which has been
mentioned in the FREETEXT Predicate will be searched for. This will implement the
OR Boolean logic.

For AND Boolean Search: Keyword1 AND Keyword2

FullTextSqlQuery ftQuery = new FullTextSqlQuery(ServerContext.Current);
ftQuery.KeywordInclusion = KeywordInclusion.AllKeywords // will search for All (AND
operation) keywords in the Freetext
Predicate. Default value is Allkeywords.
ftQuery.QueryText = "SELECT Title, Path, Rank FROM Scope() WHERE
FREETEXT(defaultproperties,'Keyword1 Keyword2') AND \"Scope\"='All Sites' ORDER BY
Rank DESC";

Note: If the keywordInclusionProperty is AllKeywords then the search will look for
all the keyword combination in the freetext predicate. This will implement the AND
Boolean logic.

For more Complex Boolean logic with multiple AND and OR logic Multiple Freetext
Predicate Can be used. But will not give the Relevant Ranking.

Cheers!!
SOURAV
ME_Mag_thumb1

Comments