Using the Enterprise Search Web Service

Posted Monday, July 30, 2007 4:42 PM by C-Dog's .NET Tip of the Day

I found yet another instance where the documentation on Enterprise Search was purely incorrect. I won't go into the whole process of how Enterprise Search works over a web service because for the most part it is correct. However, what is not correct is the schema you pass it. Here is what it is in the help file.

<QueryText language=xml:lang type='MSSQLFT'>
SELECT Title, Path, Description, Write, Rank, Size FROM Scope() 
WHERE CONTAINS(Description,'SharePoint')
</QueryText>

Here is the XML that actually works.

<QueryPacket xmlns="urn:Microsoft.Search.Query" Revision="1000">
  <Query domain="QDomain">
    <SupportedFormats>
      <Format>
urn:Microsoft.Search.Response.Document.Document
</Format>
    </SupportedFormats>
    <Context>
      <QueryText language="en-US" type="MSSQLFT">
SELECT Title, Path, Description, Write, Rank, Size 
FROM Scope() 
WHERE CONTAINS(Description,'SharePoint')
</QueryText>
    </Context>
  </Query>
</QueryPacket>

So it is mostly correct, but nothing in there says to wrap your QueryText inside a QueryPacket element. I discovered this syntax from a book excerpt I found on MSDN. It has some decent information in it.

Customizing and Extending MOSS 2007 Search

Read the complete post at http://www.dotnettipoftheday.com/blog.aspx?id=378