How To: Retrieve a document's content type classification from a query

Issue

<QueryPacket xmlns="urn:Microsoft.search.Query"><Query><Context><QueryText language='en-us' type='MSSQLFT'>SELECT TITLE,FILENAME,LASTMODIFIEDTIME,PATH,CONTENTTYPE,AUTHOR,DESCRIPTION,WRITE,RANK,SIZE,ISDOCUMENT,SITENAME FROM SCOPE() WHERE FILENAME LIKE 'darknet%' AND ( ISDOCUMENT LIKE '1' OR CONTENTTYPE LIKE 'Folder' ) AND SITENAME LIKE ‘https://tj9’ ORDER BY LASTMODIFIEDTIME DESC</QueryText></Context><Range><StartAt>1</StartAt><Count>10</Count></Range></Query></QueryPacket>

Since we have the need to look at an object’s content type, we thought we could use the managed property named ‘ContentType’ for that. This works as long as the object is not a document. What we have noticed is the managed property ‘ContentType’ is mapped to two crawled properties named ‘Basic:5’ and ‘ows_ContentType’. This overloading seems to cause, for documents, the managed property ‘ContentType’ to contain MIME type. Given that the mapping on the managed property “ContentType’ cannot be altered, Can we use any other managed property that will give us a document’s content type?

 

Cause

"Contenttype” is a combination of two crawled properties that’s why it doesn’t display content type value.
This behavior is by design.

 

Resolutions

[1]
Create a managed properties mapped to “ows_ContentType(Text)”.
In our workaround(in fact this is the proper solution I would say), we are just setting a new managed property by mapping it to “ows_ContentType(Text)” crawled property. This is a recommended way.
I have created two managed properties mapped to “Basic:5(Text)” and “ows_ContentType(Text)”. Then when I select a column mapped to “ows_ContentType(Text)”, in my search query, I get proper expected results, content type names.

 

[2]
Programmatically call a lists web service and get the contenttype values by parsing the returned XML.
listsrv.Lists listService = new listsrv.Lists();
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("admin", "admin");
System.Net.CredentialCache cache = new System.Net.CredentialCache();
cache.Add(new Uri("<https://151596_0>"), "NTLM", cred);
listService.Credentials = cache;
listService.Url = "<https://151596_0/_vti_bin/lists.asmx>";
try
{
XmlNode ndListItems = listService.GetListItems("Shared Documents", null, null, null, null, null, null);
MessageBox.Show(ndListItems.OuterXml);
}
catch (System.Web.Services.Protocols.SoapException ex)
{
MessageBox.Show("Message:\n" + ex.Message + "\nDetail:\n" + ex.Detail.InnerText + "\nStackTrace:\n" + ex.StackTrace);
}