Issue with Content
Type managed property in Search for 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
FullTextSqlQuery query = new
FullTextSqlQuery(searchProxy);
query.QueryText = @"SELECT
Title, Path, ContentType FROM SCOPE() WHERE ContentType='My Custom Content
Type'";
query.ResultTypes = ResultType.RelevantResults;
query.RowLimit = 5;
ResultTableCollection rtc = query.Execute();
ResultTable queryResultsTable = rtc[ResultType.RelevantResults];
DataTable result = new
DataTable();
result.Load(queryResultsTable, LoadOption.OverwriteChanges);
myRepeater.DataSource = result;
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."
Source
"Microsoft.Office.Server.Search”
at Microsoft.Office.Server.Search.Administration.SearchServiceApplicationProxy.ThrowBackwardCompatibleException(FaultException`1
ex)
at
Microsoft.Office.Server.Search.Administration.SearchServiceApplicationProxy.DoSpLoadBalancedUriWsOp[T](WebServiceBackedOperation`1
webServiceCall, Int32 timeoutInMilliseconds, Int32 wcfTimeoutInMilliseconds,
String operationName)
at
Microsoft.Office.Server.Search.Administration.SearchServiceApplicationProxy.DoWebServiceBackedOperation[T](String
operationName, Int32 timeoutInMilliseconds, Int32 wcfTimeoutInMilliseconds,
WebServiceBackedOperation`1 webServiceCall)
at
Microsoft.Office.Server.Search.Administration.SearchServiceApplicationProxy.Execute(QueryProperties
properties)
at
Microsoft.Office.Server.Search.Query.Query.Execute()
at
Tieto.DTC.SharePoint.Outokumpu.Web.WebControls.WebParts.OutokumpuPersonalBlogsList.OutokumpuPersonalBlogsListUserControl.getSearchData()
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
- Basic:5(Text)
- ows_ContentType(Text)
Hope this blog will help
you and will save time.
Comments / Feedback are most welcome!
Thanks!