You are here: dtSearch.Engine > SearchJob Class
SearchJob Class
dtSearch Engine API for .NET Framework 2.x-4.x
SearchJob Class

Use to search indexes or to search without an index.

Visual Basic
public class SearchJob : NetJobBase;
No members matching the current filter
No members matching the current filter
Search criteria

There are three components to the search request that can be included in a SearchJob: 

(1) Request: The search request, which can be in the "boolean", "all words", or "anywords" syntax, depending on the value of SearchFlags

(2) BooleanConditions: A string in the boolean syntax expressing any conditions that must be satisfied in addition to whatever is in Request. This provides a way to add boolean conditions (such as field criteria) to a user-supplied query, which may be in the all words or any words syntax. 

(3) FileConditions: A string expressing conditions such as filename matches, file size matches, etc., that documents must satisfy. 

For information on the syntax for these values, see: 

Search Requests Overview 

Search results

After a search, to obtain search results, use SearchJob.Results to create a SearchResults object with the documents that were found in the search.

Monitoring and cancelling searches

To receive callbacks during a search with the name of each document as it is found, create an object that implements the ISearchStatusHandler interface and attach it to the SearchJob's StatusHandler

To implement a "Cancel" button, start the search using ExecuteInThread and then use AbortThread to cancel the search. 

In server applications, to limit the amount of time and resources a search can consume, use TimeoutSeconds, MaxFilesToRetrieve, and AutoStopLimit. For more information, see: 

Limiting searches 

Search filters

A search filter represents a set of documents that can be returned in a search. To limit a search to the documents in a search filter, set up a SearchFilter object with the filter to use, and call SearchJob.SetFilter to attach the filter to the SearchJob. Example:

using (dtSearch.Engine.SearchFilter filter = new SearchFilter()) { int iIndex = filter.AddIndex(m_indexPath); // Select the items to include in the filter. int ct = filter.SelectItemsBySearch(iIndex, sampleRequest, true); searchJob.SetFilter(filter); // Now when searchJob is executed, only documents identified by searchFilter can be // retrieved. ...

To generate a search filter based on the results of a search, set WantResultsAsFilter to true. After the search, every document retrieved in the search will be selected in the output search filter, ResultsAsFilter. Note: MaxFilesToRetrieve does not affect outputSearchFilter, which will include everyitem retrieved in the search. However, if AutoStopLimit causes the search to terminate before it is complete, then only items found before the search stopped will be selected in the SearchFilter

For more information, see: SearchFilter


When using the dtSearch Engine API, it is essential to use the IDisposable pattern with all API objects except JobErrorInfo. Otherwise, the .NET garbage collector may take a long time to free memory used by potentially large objects such as SearchResults, resulting in memory depletion in long-running applications. In C# code, use a "using" clause with dtSearch Engine API objects, and in other code call Dispose() when you are done with an object.

dtSearch.Engine.SearchJob searchJob = new dtSearch.Engine.SearchJob(); searchJob.Request = searchRequest.Text; searchJob.IndexesToSearch.Add(indexPath.Text); searchJob.MaxFilesToRetrieve = 100; searchJob.SearchFlags = SearchFlags.dtsSearchDelayDocInfo; searchJob.Execute(); if (searchJob.Errors.Count > 0) // ... display error messages ... else { dtSearch.Engine.SearchResults results; results = searchJob.Results; // ... display search results ... }
Copyright (c) 1998-2019 dtSearch Corp. All rights reserved.