ISearchAsyncSearchAsync Method
IT Hit WebDAV Classes Reference
Returns a list of items that correspond to a search request.
Namespace:
ITHit.WebDAV.Server.Search
Assembly:
ITHit.WebDAV.Server (in ITHit.WebDAV.Server.dll) Version: 11.3.10719
Syntax Task<PageResults> SearchAsync(
string searchString,
SearchOptions options,
List<PropertyName> propNames,
Nullable<long> offset,
Nullable<long> nResults
)
Task<PageResults> SearchAsync(
string searchString,
SearchOptions options,
List<PropertyName> propNames,
Nullable<long> offset,
Nullable<long> nResults
)
Function SearchAsync (
searchString As String,
options As SearchOptions,
propNames As List(Of PropertyName),
offset As Nullable(Of Long),
nResults As Nullable(Of Long)
) As Task(Of PageResults)
Function SearchAsync (
searchString As String,
options As SearchOptions,
propNames As List(Of PropertyName),
offset As Nullable(Of Long),
nResults As Nullable(Of Long)
) As Task(Of PageResults)
Task<PageResults^>^ SearchAsync(
String^ searchString,
SearchOptions^ options,
List<PropertyName>^ propNames,
Nullable<long long> offset,
Nullable<long long> nResults
)
Task<PageResults^>^ SearchAsync(
String^ searchString,
SearchOptions^ options,
List<PropertyName>^ propNames,
Nullable<long long> offset,
Nullable<long long> nResults
)
abstract SearchAsync :
searchString : string *
options : SearchOptions *
propNames : List<PropertyName> *
offset : Nullable<int64> *
nResults : Nullable<int64> -> Task<PageResults>
abstract SearchAsync :
searchString : string *
options : SearchOptions *
propNames : List<PropertyName> *
offset : Nullable<int64> *
nResults : Nullable<int64> -> Task<PageResults>
Parameters
- searchString
- Type: SystemString
A phrase to search. - options
- Type: ITHit.WebDAV.Server.SearchSearchOptions
Search parameters. - propNames
- Type: System.Collections.GenericListPropertyName
List of properties to retrieve with each item returned by this method. They will be requested by the
Engine in GetPropertiesAsync(IListPropertyName, Boolean) call.
- offset
- Type: SystemNullableInt64
The number of items to skip before returning the remaining items. - nResults
- Type: SystemNullableInt64
The number of items to return.
Return Value
Type:
TaskPageResultsInstance of
PageResults class that contains items on a requested page and total number of items in search results.
Remarks
This method is called by DavEngineAsync when client application is sending search request.
In your implementation you must return a list of items that correspond to the requested search phrase and options.
The search phrase may contain wildcards:
-
To indicate one or more characters the '%' is passed in search string.
-
To indicate exactly one character the '_' is passed in search string.
To include '%', '_' and '\' characters in the search string thay are escaped with '\' character.
Note that IT Hit Ajax File Browser is using '*' and '?' as wildcard characters. In case included in search they are replaced with '%' and '_'.
Examples The code below is part of 'WebDAVServer.FileSystemStorage.AspNet' C# & VB samples provided with the SDK.
public async Task<PageResults> SearchAsync(string searchString, SearchOptions options, List<PropertyName> propNames, long? offset, long? nResults)
{
bool includeSnippet = propNames.Any(s => s.Name == snippetProperty);
string commandText =
@"SELECT System.ItemPathDisplay" + (includeSnippet ? " ,System.Search.AutoSummary" : string.Empty) + " FROM SystemIndex " +
@"WHERE scope ='file:@Path' AND (System.ItemNameDisplay LIKE '@Name' OR FREETEXT('""@Content""')) " +
@"ORDER BY System.Search.Rank DESC";
commandText = PrepareCommand(commandText,
"@Path", this.dirInfo.FullName,
"@Name", searchString,
"@Content", searchString);
Dictionary<string, string> foundItems = new Dictionary<string, string>();
try
{
using (OleDbConnection connection = new OleDbConnection(windowsSearchProvider))
using(OleDbCommand command = new OleDbCommand(commandText, connection))
{
connection.Open();
using(OleDbDataReader reader = command.ExecuteReader())
{
while (await reader.ReadAsync())
{
string snippet = string.Empty;
if (includeSnippet)
{
snippet = reader.GetValue(1) != DBNull.Value ? reader.GetString(1) : null;
if (!string.IsNullOrEmpty(snippet) && invalidXmlCharsPattern.IsMatch(snippet))
{
snippet = invalidXmlCharsPattern.Replace(snippet, String.Empty);
}
}
foundItems.Add(reader.GetString(0), snippet);
}
}
}
}
catch (OleDbException ex)
{
context.Logger.LogError(ex.Message, ex);
switch (ex.ErrorCode)
{
case -2147217900: throw new DavException("Illegal symbols in search phrase.", DavStatus.CONFLICT);
default: throw new DavException("Unknown error.", DavStatus.INTERNAL_ERROR);
}
}
IList<IHierarchyItemAsync> subtreeItems = new List<IHierarchyItemAsync>();
foreach (string path in foundItems.Keys)
{
IHierarchyItemAsync item = await context.GetHierarchyItemAsync(GetRelativePath(path)) as IHierarchyItemAsync;
if (item == null)
{
continue;
}
if (includeSnippet && item is DavFile)
(item as DavFile).Snippet = HighlightKeywords(searchString.Trim('%'), foundItems[path]);
subtreeItems.Add(item);
}
return new PageResults(offset.HasValue && nResults.HasValue ? subtreeItems.Skip((int)offset.Value).Take((int)nResults.Value) : subtreeItems, subtreeItems.Count);
}
Public Async Function SearchAsync(searchString As String, options As SearchOptions, propNames As List(Of PropertyName), offset As Long?, nResults As Long?) As Task(Of PageResults) Implements ISearchAsync.SearchAsync
Dim includeSnippet As Boolean = propNames.Any(Function(s) s.Name = snippetProperty)
Dim commandText As String = "SELECT System.ItemPathDisplay" & (If(includeSnippet, " ,System.Search.AutoSummary", String.Empty)) & " FROM SystemIndex " & "@Content" & "ORDER BY System.Search.Rank DESC"
commandText = PrepareCommand(commandText,
"@Path", Me.dirInfo.FullName,
"@Name", searchString,
"@Content", searchString)
Dim foundItems As Dictionary(Of String, String) = New Dictionary(Of String, String)()
Try
Using connection As OleDbConnection = New OleDbConnection(windowsSearchProvider)
Using command As OleDbCommand = New OleDbCommand(commandText, connection)
connection.Open()
Using reader As OleDbDataReader = command.ExecuteReader()
While Await reader.ReadAsync()
Dim snippet As String = String.Empty
If includeSnippet Then
snippet = If(reader.GetValue(1) <> DBNull.Value, reader.GetString(1), Nothing)
If Not String.IsNullOrEmpty(snippet) AndAlso invalidXmlCharsPattern.IsMatch(snippet) Then
snippet = invalidXmlCharsPattern.Replace(snippet, [String].Empty)
End If
End If
foundItems.Add(reader.GetString(0), snippet)
End While
End Using
End Using
End Using
Catch ex As OleDbException
context.Logger.LogError(ex.Message, ex)
Select Case ex.ErrorCode
Case -2147217900
Throw New DavException("Illegal symbols in search phrase.", DavStatus.CONFLICT)
Case Else
Throw New DavException("Unknown error.", DavStatus.INTERNAL_ERROR)
End Select
End Try
Dim subtreeItems As IList(Of IHierarchyItemAsync) = New List(Of IHierarchyItemAsync)()
For Each path As String In foundItems.Keys
Dim item As IHierarchyItemAsync = TryCast(Await context.GetHierarchyItemAsync(GetRelativePath(path)), IHierarchyItemAsync)
If item Is Nothing Then
Continue For
End If
If includeSnippet AndAlso TypeOf item Is DavFile Then TryCast(item, DavFile).Snippet = HighlightKeywords(searchString.Trim("%"c), foundItems(path))
subtreeItems.Add(item)
Next
Return New PageResults(If(offset.HasValue AndAlso nResults.HasValue, subtreeItems.Skip(CInt(offset.Value)).Take(CInt(nResults.Value)), subtreeItems), subtreeItems.Count)
End Function
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
See Also