|
Introduction |
Top Previous Next |
|
The FileLocator Pro Core Search library is a COM based class library to simplify the embedding of the FileLocator Pro search engine functionality into any Windows based application.
The core classes are implemented in FLProCore.dll, which should have been registered during FileLocator Pro installation. To use the classes you will need to reference the DLL to import the type library (e.g. in Visual Studio simply add FLProCore to your References, or with C++ use #import).
The core class is the FLProCoreLib.SearchEngine class.
The search engine can be run in either an asynchronous or synchronous mode. In synchronous mode the calling thread is blocked until the search is completed. In asynchronous mode a new thread is created to run the search and progress information is posted back to the caller through the use of events, while the calling thread is freed to perform other tasks.
The following Visual Basic example shows the search engine running in synchronous, i.e. blocking, mode.
Note: The examples in this documentation often assume that the FLProCoreLib namespace has been imported into the global namespace, e.g. VB : Imports FLProCoreLib C# : using FLProCoreLib;
engineSearch = New SearchEngineClass
engineSearch.SearchCriteria.FileName = "*.txt" engineSearch.SearchCriteria.ContainingText = "search" engineSearch.SearchCriteria.LookIn = "c:\search folder"
Dim listResult As SearchResultItemList = engineSearch.Start( False )
' Output the files, with their text lines and hits to the console
Dim buildText As New System.Text.StringBuilder
For nItem As Integer = 0 To (listResult.Count - 1) ' Each item in the list includes information about the found ' item (e.g. its name and path) and also the list of text lines ' found if this was a content search
Dim item As SearchResultItem = listResult(nItem)
buildText.Append(item.Path) buildText.Append(item.FileName) buildText.Append(vbCrLf)
Dim listText As TextLineList = item.TextLineList
For nText As Integer = 0 To (listText.Count - 1) ' Each text line includes the line number and text found and also ' a list showing where the expression matches occurred.
Dim line As TextLine = listText(nText)
Dim listMatch As FLProCoreLib.TextMatchList = line.TextMatchList For nHit As Integer = 0 To (listMatch.Count - 1) buildText.AppendFormat(" {0}:{1} ", listMatch(nHit).Start, listMatch(nHit).Length) Next buildText.Append(vbCrLf) Next Next
System.Console.Write( buildText.ToString() )
The example shows the core steps for running a search:
|