Exchange全文检索概述
Exchange全文检索概述 0、写在前面本文主要讲述在Windows2000全文索引(Full-Text Index)和全文查询(Full-Text Query)。我们知道为了提高查询的效率,有一种机制叫做“索引(Index)”,索引中存储了关键字和对应的记录在逻辑存储空间中的位置。数据库管理系统(DBMS)中有索引表,相信大家都可以理解,全文检索中也是同样的原理。:创建索引的过程,建立关键字与记录的对应关系。创建完成的索引信息或者以增量的方式修改属性信息。:可以认为是关键字存储的组织形式。CONTAINS:进行关键字的完整单词的匹配,格式为, CONTAINS( [" propertyNAME " | * , ] ' searchspec ' )FREETEXT:与CONTAINS比较类似,但是可以对关键字中每一个单词或者一组单词的多种变化形式进行模糊(Loosely)匹配,格式为, FREETEXT( [" propertyNAME ", ] ' searchspec ' )
这里需要强调的是,对于关键字变换形式的匹配,而不是关键字子串(Substring)的匹配,也就是说可以通过'rose'找到'roses',但是不能够通过'public'找到'republican'。FORMSOF:这个谓词需要包含在CONTAINS或者FREETEXT谓词中使用,通过该谓词修饰,可以对关键字的每一个变换形式进行匹配,关键字的变换形式是由搜索引擎决定的。格式为, FORMSOF( type,"string" [,"string"] )INFLECTIONAL。RANK BY:该谓词通常用来修饰CONTAINS或者FREETEXT谓词,用来表示关键字出现的频度。格式为, RANK BY CLAUSE (Mechanism, Weight) Select "DAV:href","urn:schemas.microsoft.com:fulltextqueryinfo:rank" FROM Scope('DEEP TRAVERSAL OF ""') WHERE FREETEXT('"program" OR "software"') RANK BY WEIGHT(1.0) OR CONTAINS('FORMSOF(INFLECTIONAL,"java") AND "vb"') RANK BY WEIGHT(0.5) private System.Xml.XmlDocument SendSearchRequest(System.String sUrl,System.String sQuery)
{
System.Net.HttpWebRequest oRequest = null;
System.Net.HttpWebResponse oResponse = null;
System.Net.NetworkCredential oCredential = null;
System.IO.Stream oStream = null;
System.Text.UTF8Encoding oEncoder = new System.Text.UTF8Encoding();
System.Byte[] abData = null;
System.Xml.XmlDocument xmldoc = null; if ( sUrl == null || sUrl == String.Empty)
return null;
if (sQuery == null || sQuery == String.Empty)
return null; abData = oEncoder.GetBytes(sQuery);
if (abData == null)
return null; oCredential = new NetworkCredential("administrator","server",String.Empty);
oRequest = (System.Net.HttpWebRequest) WebRequest.Create(sUrl);
if (oRequest != null)
{
// preparing search request
oRequest.ProtocolVersion = HttpVersion.Version11;
oRequest.Method = @"SEARCH";
if (oCredential != null)
oRequest.Credentials = oCredential.GetCredential(new System.Uri(sUrl),String.Empty);
oRequest.ContentType = @"text/xml";
oRequest.ContentLength = abData.Length;
oStream = oRequest.GetRequestStream();
oStream.Write(abData,0,abData.Length);
oStream.Close();
// waiting for response
try
{
oResponse = (System.Net.HttpWebResponse) oRequest.GetResponse();
oRequest = null;
}
catch(System.Exception e)
{
Trace.WriteLine("SendSearchRequest: " + e.Message);
}
if (oResponse != null)
{
oStream = oResponse.GetResponseStream();
// get data from stream
if (oStream != null)
{
try
{
xmldoc = new XmlDocument();
if (xmldoc != null)
{
xmldoc.Load(oStream);
}
}
catch(System.Exception e)
{
Trace.WriteLine("SendSearchRequest: " + e.Message);
}
oStream.Close();
oStream = null;
}
}
oResponse = null;
} return xmldoc;
}
传入参数分别为,需要查询的根路径(可以认为是表名,这里为HTTP URL)和查询语句(格式见上一节),返回的结果为包含查询结果的XMLDocument实例。 private ADODB.RecordsetClass GetQueryResult(System.String sUrl,System.String sQuery)
{
ADODB.RecordsetClass rsResult = null;
ADODB.ConnectionClass cnnExchange = null;
ADODB.CommandClass cmdQuery = null;
System.Object objAffectedRecords = null,objParams = null; if (sUrl == null || sUrl == String.Empty)
return null;
if (sQuery == null || sQuery == String.Empty)
return null; try
{
cnnExchange = new ConnectionClass();
if (cnnExchange == null)
return null;
cnnExchange.Provider = "provider=msdaipp.dso";
cnnExchange.Open(sUrl,String.Empty,String.Empty,0);
}
catch (System.Exception e)
{
Trace.WriteLine("GetQueryResult: Create connection failed! " + e.Message);
cnnExchange = null;
return null;
} cmdQuery = new CommandClass();
if (cmdQuery != null)
{
cmdQuery.ActiveConnection = cnnExchange;
cmdQuery.CommandType = CommandTypeEnum.adCmdText;
cmdQuery.CommandText = sQuery;
try
{
rsResult = (ADODB.RecordsetClass) cmdQuery.Execute(out objAffectedRecords,ref objParams,0);
}
catch (System.Exception e)
{
Trace.WriteLine("GetQueryResult: Query data failed! " + e.Message);
}
cmdQuery = null;
}
cnnExchange = null; return rsResult;
}
传入参数分别为,需要查询的根路径(可以认为是表名)和查询语句,返回的结果为包含查询结果的Recordset实例。需要强调的是MSADIPP的Provider不支持在打开连接时指定访问用户名和口令。