Persisted Search Folders


Persisted Search Folders

When you use WebDAV, you can use the WebDAV search methods that we looked at earlier. Exchange 2000 and later provide the ability to create persisted search folders when using WebDAV. These search folders are like standard folders in that you can use a URL to access them and query them. You can create search folders in any of your application hierarchies. You cannot, however, create search folders in the MAPI All Public Folders hierarchy. Also, you cannot create search folders using ADO.

Search folders allow you to offload to the server the task of finding new items that meet your SQL search criteria. For example, imagine you have an application that spans 10 folders under the root folder. In each folder, you need to find all the items with a specific property, such as items whose content classes are a certain type ”say, urn:content-classes:mycc . Rather than querying Exchange every time you need to find items that meet this criterion, you can create a top-level search folder. This search folder will asynchronously add links to new items that meet the criterion (or criteria) you specified in the search folder. Your application can query the search folder rather than perform a deep traversal of all the application folders. Plus, Exchange stores and dynamically updates search results without requiring clients to be connected or requery the Exchange database. Search performance should be much greater with a search folder.

Creating a Search Folder

To create a search folder, all you do is issue an MKCOL command. This command also specifies a DAV:searchrequest property that contains the SQL statement you want the search folder to perform. The following JavaScript example shows how to create a search folder:

 function SearchFolderCreate(folderURL, SQLQuery) {     var oXMLHTTP;     oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");          oXMLHTTP.Open("MKCOL", folderURL, false);     strR = "<?xml version='1.0'?>";     strR += "<d:propertyupdate xmlns:d='DAV:'>";     strR += "<d:set><d:prop><d:searchrequest><d:sql>" + SQLQuery + "</d:sql>";     strR += "</d:searchrequest></d:prop></d:set></d:propertyupdate>";     oXMLHTTP.SetRequestHeader("Content-Type:", "text/xml");          oXMLHTTP.send(strR);          if(!Req.Status == "207")     { // Multistatus response         alert("An error has occurred!! ");     } } 

If the command is successful, the server will return a 207 Multi-Status response. Here is an example of a SELECT statement that selects all items that are not hidden or are folders in a public folder tree outside of the MAPI folder tree. You can use this statement as the query in the creation of your search folder.

 var SQLQuery = "SELECT \"DAV:displayname\" FROM Scope('deep traversal of"; SQLQuery += "\"http://server/newtree/\"') WHERE \"DAV:ishidden\" = false"; SQLQuery = "AND \"DAV:isfolder\" = false"; 

Search folders are just like regular folders in that they contain properties, but they are different in that they contain properties unique to them. Table 16-3 lists the special properties for search folders.

Table 16-3: Properties Unique to Search Folders

Property

Description

DAV: resourcetype

Has a value of <DAV:collection/><DAV:searchresults/> if the folder is a search folder.

DAV:searchrequest

Contains the original SQL query for the persisted search. You cannot change this property. If you need to modify your search, you must delete your search folder and re-create it, or create a new search folder.

DAV:searchtype

Set to dynamic by the Web Storage System.

Searching a Persisted Search Folder

To query your search folder, all you do is use the WebDAV Search or PropFind method (described earlier) and then specify the search folder URL. Optionally, you can specify a Range header in your Search queries to return a certain number of rows. For example, you can specify that you want only the first 10 rows or the last 10 rows. The following examples show how to use the Range header with XMLHTTP.

 Set Req = CreateObject("Microsoft.XMLHTTP")    . . . 'Rows 10-20 and 40-50 Req.setRequestHeader "Range", "rows=10-20,40-50" 'Last 10 rows Req.setRequestHeader "Range", "rows=-10" 'From Row 10 to the end of the resultset Req.setRequestHeader "Range", "rows=10-" 'Rows 1-10 and the last 10 rows Req.setRequestHeader " Range", "rows=1-10,-10" 



Programming Microsoft Outlook and Microsoft Exchange 2003
Programming MicrosoftВ® OutlookВ® and Microsoft Exchange 2003, Third Edition (Pro-Developer)
ISBN: 0735614644
EAN: 2147483647
Year: 2003
Pages: 227
Authors: Thomas Rizzo

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net