Issue With Content Type Managed Property In Search For SharePoint 2010

This blog describe the issue with managed property 'Content Type' in sharePoint 2010

Hello All,

I am working on one custom webpart, in that I have to display the pages having my custom content type. Here I am using the search object model and using FullTextSqlQuery class like as follows,

  1. FullTextSqlQuery query = newFullTextSqlQuery(searchProxy);  
  2. query.QueryText = @ "SELECT Title, Path, ContentType FROM SCOPE() WHERE ContentType='My Custom Content Type'";  
  3. query.ResultTypes = ResultType.RelevantResults;  
  4. query.RowLimit = 5;  
  5. ResultTableCollection rtc = query.Execute();  
  6. ResultTable queryResultsTable = rtc[ResultType.RelevantResults];  
  7. DataTable result = newDataTable();  
  8. result.Load(queryResultsTable, LoadOption.OverwriteChanges);  
  9. myRepeater.DataSource = result;  
  10. myRepeater.DataBind();  

So whenever I executes this code, Execute () throws an following exception

Message "Property doesn't exist or is used in a manner inconsistent with schema settings."

  1. Source "Microsoft.Office.Server.Search”  
  2. at Microsoft.Office.Server.Search.Administration.SearchServiceApplicationProxy.ThrowBackwardCompatibleException(FaultException`1 ex)  
  3. at Microsoft.Office.Server.Search.Administration.SearchServiceApplicationProxy.DoSpLoadBalancedUriWsOp[T](WebServiceBackedOperation`1 webServiceCall, Int32 timeoutInMilliseconds, Int32 wcfTimeoutInMilliseconds, String operationName)  
  4. at Microsoft.Office.Server.Search.Administration.SearchServiceApplicationProxy.DoWebServiceBackedOperation[T](String operationName, Int32 timeoutInMilliseconds, Int32 wcfTimeoutInMilliseconds, WebServiceBackedOperation`1 webServiceCall)  
  5. at Microsoft.Office.Server.Search.Administration.SearchServiceApplicationProxy.Execute(QueryProperties properties)  
  6. at Microsoft.Office.Server.Search.Query.Query.Execute()  
  7. at Tieto.DTC.SharePoint.Outokumpu.Web.WebControls.WebParts.OutokumpuPersonalBlogsList.OutokumpuPersonalBlogsListUserControl.getSearchData()  
  8. at Tieto.DTC.SharePoint.Outokumpu.Web.WebControls.WebParts.OutokumpuPersonalBlogsList.OutokumpuPersonalBlogsListUserControl.Page_Load(Object sender, EventArgs e)  

After going into more delve it found that “Use in scopes” checkbox is not selected for the ContentType managed property in Search Service Application. So to do this,

  1. Go to Search Service Application (From Application Management >> Manage Service Application)
  2. Go to MetaData Properties
  3. From the list of managed properties, Edit ContentType managed property
  4. Check the checkbox “Allow this property to be used in scopes

Even after doing this change there is no change in result. Same exception again.

After doing some googling it found that this is the problem with OOB content type managed metadata property. The above exception is because of Content Type managed property. The OOB content type property doesn't work in queries.

So workaround to this problem which I found is, create new managed property (In my next article I will cover – how to create custom managed property through code) and map this new managed property with crawled properties with which ContentType managed property is mapped.

By default ContentType managed property mapped with two crawled properties

  1. Basic:5(Text)
  2. ows_ContentType(Text)

Hope this blog will help you and will save time.

Comments / Feedback are most welcome!