views:

903

answers:

1

I am using object code model to retrieve search result from sharepoint search..Can any one suggest how do i put advanced search option for my search.Do object code model has the feature to perform advanced search.

+1  A: 

Yes, you can perform advanced searches using the FullTextSqlQuery class as shown in the code example below. See also Best Practices: Writing SQL Syntax Queries for Relevant Results in Enterprise Search.

using (SPSite site = new SPSite("http://server"))   // Site Collection URL
using (FullTextSqlQuery query = new FullTextSqlQuery(site))
{
  query.ResultTypes = ResultType.RelevantResults;
  query.EnableStemming = true;
  query.TrimDuplicates = true;
  query.Culture = new CultureInfo(1033);    // Use en-US stemmer and word-breaker
  query.RowLimit = 40;
  query.StartRow = 0;
  query.KeywordInclusion = KeywordInclusion.Allkeywords;   // Implicit AND search
  query.HighlightedSentenceCount = 3;
  query.SiteContext = new Uri("http://server");  // Site Collection URL
  query.QueryText = "SELECT WorkId, Title, Path, HitHighlightedSummary, HitHighlightedProperties, CollapsingStatus, Description, Rank, Size" +
                     " FROM SCOPE()" +
                     " WHERE \"scope\" = 'A Scope'" +
                     " AND FREETEXT(defaultproperties, 'keyword1 keyword2')" +
                     " AND Color = 'Black'" + // Color is a managed property
                     " ORDER BY Rank DESC";            

  ResultTableCollection results = query.Execute();
  ResultTable relevantResults = results[ResultType.RelevantResults];

  // TODO: Process results
};
Lars Fastrup
that works fine... but i need to get results for managed property which are mapped to crawled property of business data with default name as "LOBSystemName.EntityName.ColumnName" which shows error...Can anyone help
kailash
Could you be more specific on the error you get? In the code above you can just add the names of your managed properties to the comma separated list of properties after SELECT.
Lars Fastrup