|
int maxSumLength = 100;
// Setup the catalog and search query helper
CSearchManager srchMngr = new CSearchManager();
CSearchCatalogManager srchCatMngr = srchMngr.GetCatalog("SystemIndex");
CSearchQueryHelper srchQueryHelper = srchCatMngr.GetQueryHelper();
// Assemble the query
srchQueryHelper.QuerySelectColumns = "System.Message.FromAddress, System.Message.ToAddress, System.Search.AutoSummary";
srchQueryHelper.QueryWhereRestrictions = "AND CONTAINS(System.Kind, '\"email\"')";
string sqlQuery = srchQueryHelper.GenerateSQLFromUserQuery("share");
// Setup the OLE DB connection
OleDbConnection conn = new OleDbConnection(srchQueryHelper.ConnectionString);
conn.Open();
// Execute the query
OleDbCommand cmd = new OleDbCommand(sqlQuery, conn);
OleDbDataReader srchResult = cmd.ExecuteReader();
// Process the search result and send to output
for (int i = 0; (i < 100) && srchResult.Read(); ++i)
{
string fromAddr = "";
string toAddr = "";
string sumAddr = "";
if (null != srchResult.GetValue(0) && !(srchResult.GetValue(0) is System.DBNull))
{
string[] addrs = (string[])srchResult.GetValue(0);
fromAddr = "From: " + System.String.Join(",", addrs);
}
if (null != srchResult.GetValue(1) && !(srchResult.GetValue(1) is System.DBNull))
{
string[] addrs = (string[])srchResult.GetValue(1);
toAddr = "To: " + System.String.Join(",", addrs);
}
if (null != srchResult.GetValue(2) && !(srchResult.GetValue(2) is System.DBNull))
{
sumAddr = (string)srchResult.GetString(2);
}
textBox1.AppendText("(" + i + ") ");
textBox1.AppendText(fromAddr + " " + toAddr + " ");
textBox1.AppendText("Content: " + (sumAddr.Length <= maxSumLength ? sumAddr : sumAddr.Substring(0, maxSumLength)));
textBox1.AppendText(Environment.NewLine);
}
srchResult.Close();
conn.Close();
|