Filters a search to allow only selected documents from an index to be returned.
The SearchFilter object provides a way to designate which documents can be returned by a search. It is useful in situations where a text search using must be combined with another search such as a search of a database. The database search is done first, and then the results of the database search are used to limit the dtSearch search.
For more information on how SearchFilters can be used to improve search efficiency, see:
Limiting searches with SearchFilters
Document Ids
Search filters do not use names to identify documents because a filter may specify thousands, or hundreds of thousands, of documents, and a table of filenames would take too much memory and would take too long to check. Instead, each document is identified by (a) the index it belongs to, and (b) the document's DocId, a unique integer that is assigned to each document in an index.
A DocId that is selected may be returned in search results. A document that is not selected will not be returned in search results, even if it otherwise satisfies the search request.
If the criteria for the SearchFilter can be expressed as one or more search requests, you can use SelectItemsBySearch to select documents in the SearchFilter.
Indexes and Index identifiers
A search filter can cover any number of indexes. To add an index to a search filter, call addIndex() with the full path to the index. The path must be expressed exactly as it will be expressed in the search job. The AddIndex() method returns an integer that is used to identify that index when selecting and de-selecting documents for the filter. (This makes the selection and de-selection functions, which may be called thousands of times, more effiicent.)
Implementation
A search filter is implemented in the dtSearch Engine using a table of bit vectors, one for each index in the filter. Each bit vector has one bit for each document in its index. For example, a search filter for a single index with 1,000,000 documents would have 1,000,000 bits, or 125 kilobytes of data.
SearchFilter requires the IDisposable Pattern.
Topic |
Description |
The following tables list the members exposed by SearchFilter. | |
The methods of the SearchFilter class are listed here. | |
The properties of the SearchFilter class are listed here. |
SearchFilter Methods |
Description |
Add an index to the filter, returning an integer that can be used to identify the index in the selection functions. | |
Combine this filter with another filter in a logical "AND" operation. | |
Combine this filter with another filter in a logical "AND NOT" operation. | |
Compare two SearchFilters for equality. | |
Returns an array of integers containing the document ids of the documents selected in the filter. | |
Combine this filter with another filter in a logical "OR" operation. | |
Read the search filter from a disk file. | |
Select all of the documents in the index. | |
Set the selection state of a range of document ids, from firstItem to lastItem, to the selection state indicated by fSelected. | |
Set the selection state of an array of document ids to the selection state indicated by fSelected. | |
Select no documents in the index. | |
Save the search filter to a disk file. |
SearchFilter Properties |
Description |
Returns the number of indexes in the SearchFilter. |
Copyright (c) 1998-2023 dtSearch Corp. All rights reserved.
|