Search.Response, I had to resort to this...
PLEASE Tell me there is a better way!
private void ExecuteAQuery(string
strLookingForWhat)
{
// create the area service object
SearchWebService.QueryService
queryService = CreateSearchService();
const string keywordQueryTemplate
= "<?xml version=\"1.0\" encoding=\"utf-8\" ?><QueryPacket
xmlns=\"urn:Microsoft.Search.Query\" Revision=\"1000
\"><Query
domain=\"QDomain\"><SupportedFormats><Format>urn:M icrosoft.
Search.Response.Document.Document</Format></SupportedFormat
s><Context><QueryText language=\"en-US\"
type=\"STRING\">query_text_placeholder</QueryText></Context
</Query></QueryPacket>";
const string SQLQueryTemplate
= "<?xml version=\"1.0\" encoding=\"utf-8\" ?><QueryPacket
xmlns=\"urn:Microsoft.Search.Query\" Revision=\"1000
\"><Query domain=\"s2003e:81
\"><SupportedFormats><Format>urn:Microsoft.Search. Response.
Document.Document</Format></SupportedFormats><Context><Quer
yText language=\"en-US\"
type=\"MSSQLFT\">query_text_placeholder</QueryText></Contex
t><Range><StartAt>1</StartAt><Count>5</Count></Range></Quer
y></QueryPacket>";
string queryString =
keywordQueryTemplate.Replace("query_text_placehold er",
strLookingForWhat);
// DOES NOT WORK (Internal System
Error Returned):
string queryString2 =
SQLQueryTemplate.Replace("query_text_placeholder",
strLookingForWhat);
// Init results:
string queryResults = null;
try
{
queryResults =
queryService.Query(queryString);
}
catch (Exception ExSheesh)
{
throw (ExSheesh);
}
//
// Load the returned XML into a
Document - first create a New XML Document,
// apply the Response.XSD schema,
then load the XML from the text received:
//
XmlDataDocument NewXmlDoc = new
XmlDataDocument();
// Causes error:
//NewXmlDoc.DataSet.ReadXmlSchema
("e:\\SPSSites\\SPSLive\\Response.xsd");
//NewXmlDoc.DataSet.ReadXmlSchema
("/Response.xsd");
NewXmlDoc.LoadXml(queryResults);
string XmlDocTableName =
NewXmlDoc.NameTable.ToString();
//
// Get the status:
//
XmlNodeList
Response_StatusNodeList = NewXmlDoc.GetElementsByTagName
("Status");
string ActualStatus =
Response_StatusNodeList[0].ChildNodes[0].Value;
XmlElement TheRootElement =
NewXmlDoc.DocumentElement;
XmlNodeList RangeNodeReference =
NewXmlDoc.GetElementsByTagName("Range");
XmlNodeList
RangeNodeContentsReference = RangeNodeReference
[0].ChildNodes;
DataSet PsuedoResultsDS = new
DataSet();
DataTable PsuedoResultsTable = new
DataTable("SearchResults");
//
// Add the columns:
//
DataColumn PRTitle = new DataColumn
("Title",System.Type.GetType("System.String"));
DataColumn PRLinkUrl = new
DataColumn("LinkUrl",System.Type.GetType("System.S tring"));
DataColumn PRFileExt = new
DataColumn("FileExt",System.Type.GetType("System.S tring"));
DataColumn PRDescription = new
DataColumn("Description",System.Type.GetType
("System.String"));
DataColumn PRFileDate = new
DataColumn("FileDate",System.Type.GetType
("System.DateTime"));
PsuedoResultsTable.Columns.Add
(PRTitle);
PsuedoResultsTable.Columns.Add
(PRLinkUrl);
PsuedoResultsTable.Columns.Add
(PRFileExt);
PsuedoResultsTable.Columns.Add
(PRDescription);
PsuedoResultsTable.Columns.Add
(PRFileDate);
PsuedoResultsDS.Tables.Add
(PsuedoResultsTable);
//
// Now check the nodes within
<Range> looking for the result set <Results>:
//
string sTotalItemsReturned = "";
int iTotalItemsReturned = 0;
//
foreach(XmlNode ARangeNode in
RangeNodeContentsReference)
{
if(ARangeNode.Name
== "StartAt")
{
}
if(ARangeNode.Name
== "Count")
{
}
//
// When we find the
<TotalAvailable> node, this tells us how many rows we have
// to process:
//
if(ARangeNode.Name
== "TotalAvailable")
{
//
// Now get how
many were returned (in <Range><TotalAvailable>) and
// convert it to
use for an index:
//
XmlNodeList
TotalValNode = NewXmlDoc.GetElementsByTagName
("TotalAvailable");
sTotalItemsReturned = TotalValNode[0].ChildNodes
[0].InnerText;
if
(sTotalItemsReturned != "")
{
iTotalItemsReturned = Convert.ToInt32
(sTotalItemsReturned);
}
}
//
// When we find the
<Results> node (should be right after TotalAvailable),
// our results are in the
nodes below:
//
if(ARangeNode.Name
== "Results")
{
//
// Get a pointer
to the Row:
//
XmlNodeList
ResultRowNodes = ARangeNode.ChildNodes;
XmlElement
TheActualResultRecord = (XmlElement)ResultRowNodes[0];
//
// Make sure we
got something:
//
if
(iTotalItemsReturned > 0)
{
//
// We did -
each now represents a Row - pull the data out and put
// it into
a new record to save to the dataset:
//
for (int
x=0; x < iTotalItemsReturned; x++)
{
XmlNodeList ColumnsNodes =
TheActualResultRecord.ChildNodes;
DataRow NewDataRow = PsuedoResultsDS.Tables
["SearchResults"].NewRow();
NewDataRow["Title"] = ColumnsNodes[0].InnerText;
string T0 = ColumnsNodes[0].Name;
string T1 = ColumnsNodes[0].InnerText;
NewDataRow["LinkUrl"] = ColumnsNodes[1].ChildNodes
[0].InnerText;
string T2 = ColumnsNodes[1].ChildNodes
[0].InnerText;
NewDataRow["FileExt"] = ColumnsNodes[1].ChildNodes
[0].Attributes[0].InnerText;
string T3 = ColumnsNodes[1].ChildNodes
[0].Attributes[0].InnerText;
NewDataRow["Description"] = ColumnsNodes
[2].InnerText;
string T4 = ColumnsNodes[2].InnerText;
NewDataRow["FileDate"] = Convert.ToDateTime
(ColumnsNodes[3].InnerText);
//
//
Add the new row:
//
PsuedoResultsDS.Tables["SearchResults"].Rows.Add
(NewDataRow);
}
}
}
}
dataGrid1.DataSource =
PsuedoResultsDS;
dataGrid1.SetDataBinding
(PsuedoResultsDS,"SearchResults");
}