Programing DASL Search

WebDAV Ajax Library provides methods for detecting DASL search support, submitting search queries and requesting custom properties to be returned in search results. You can specify which properties to search and if file content should be searched.

Probing Search Support

The WebDAV server that supports DASL search returns SEARCH token in the Allow header. The WebDAV Ajax Library provides HierarchyItem.GetSupportedFeaturesAsync() method that returns information about features supported by server, that are returned in the OptionsInfo.Features flags enumeration. The GetSupportedFeaturesAsync() call submits OPTIONS request to server and if search is supported the Features.Dasl flag is set.

var webDavSession = new ITHit.WebDAV.Client.WebDavSession();

webDavSession.OpenFolderAsync('https://serv/', null, function(oAsyncResult){
    /** @typedef {ITHit.WebDAV.Client.Folder} oFolder */
    var oFolder = oAsyncResult.Result;

    oFolder.GetSupportedFeaturesAsync(function(oAsyncResult){
        /** @typedef {ITHit.WebDAV.Client.OptionsInfo} oOptionsInfo */
        var oOptionsInfo = oAsyncResult.Result;

        var bSearch = oOptionsInfo.Features & ITHit.WebDAV.Client.Features.Dasl !== 0;
        console.log('Search support: ' + (bSearch ? 'yes' : 'no'));
    });
});

Submitting Search Query

To submit a search request the library provides Folder.SearchByQueryAsync() function. Here is the example of search request:

var webDavSession = new ITHit.WebDAV.Client.WebDavSession();

webDavSession.OpenFolderAsync('https://serv/folder/', null, function(oFolderAsyncResult) {

    /** @typedef {ITHit.WebDAV.Client.Folder} oFolder */
    var oFolder = oFolderAsyncResult.Result;

    // Build search query
    var oSearchQuery = new ITHit.WebDAV.Client.SearchQuery('Sales Report%');

    // By default WebDAV Ajax Client search by DisplayName property.
    // You can add other properties to this list.
    oSearchQuery.LikeProperties.push(new ITHit.WebDAV.Client.PropertyName('creator-displayname', 'DAV:'));
    oSearchQuery.LikeProperties.push(new ITHit.WebDAV.Client.PropertyName('comment', 'DAV:'));

    // Disable search by file content
    oSearchQuery.EnableContains = false;

    oFolder.SearchByQueryAsync(oSearchQuery, function(oAsyncResult) {

        /** @typedef {ITHit.WebDAV.Client.HierarchyItems[]} aItems */
        var aItems = oAsyncResult.Result;

        for (var i = 0, l = aItems.length; i < l; i++) {
            console.log(aItems[i].DisplayName);
        }

    });
});

By default the search will be performed using display name and content. You can use the SearchQuery.LikeProperties list to add more properties to the search list.

Requesting Custom Properties

In many cases you will need additional data being returned with each hierarchy item in search results. For example you will need a peace of text around the search phrase or author that updated the document last time. You can request any additional properties specifying them in a search request in SearchQuery.SelectProperties list. The requested properties will be returned in HierarchyItem.Properties:

var oSearchQuery = new ITHit.WebDAV.Client.SearchQuery('Sales Report%');

// Ask server to return MyNS:snippet property with each item.
var snippetPropName = new ITHit.WebDAV.Client.PropertyName('snippet', 'MyNS:')
oSearchQuery.SearchProperties = [snippetPropName];

oFolder.SearchByQueryAsync(oSearchQuery, function(oAsyncResult) {

/** @typedef {ITHit.WebDAV.Client.HierarchyItems[]} aItems */
var aItems = oAsyncResult.Result;

for (var i = 0, l = aItems.length; i < l; i++) {
    console.log(aItems[i].DisplayName + ' ' +
        aItems[i].Properties.Find(snippetPropName).StringValue());
    }
});

Search Phrase Wildcards and Escaping

To add wildcards to your search phrase use DASL wildcard characters:

  • ‘%’ – to indicate one or more character.
  • ‘_’ – to indicate exactly one character.
new ITHit.WebDAV.Client.SearchQuery('Sales Report 201_');

Note that the WebDAV Ajax Library will pass the search phrase to server without modification. As though if ‘%’, ‘_’ or ‘\’ characters are used in a search phrase, they must be escaped as ‘\%’, ‘\_’ and ‘\\’.