Restricting the search area by means of RestrictSearchArea
The function RestrictSearchArea allows you to specify the search area as a rectangle, an array of rectangles, or a region.
On different pages of the document the sought field is often located differently relative to its name. For example, on some pages the field can be to the right of the name, on the others it can be under the name. In such cases it is advisable to specify the search area as an array of rectangles. See Using Nearest and FuzzyQuality to look for elements about the use of the RestrictSearchArea function in such cases.
It may also be advisable to use the RestrictSearchArea function instead of doubling search constrains that are identical for several elements.
Use this function to describe the search area of the date field or any other field when, for some reason (e.g. low image quality or layout peculiarities), the use of an element of one type is not enough.
Let us see how the RestrictSearchArea function can be used to search for a date field. It is usually recommended to search for date fields with the help of at least two types of elements: Date and Character String. But if the image quality is very low, these two elements may not be enough. See Detecting dates in the case of low quality pre-recognition for more details on how to organize a search for date fields.
Let us see this function at work by taking by running the sample project SearchOfDate.fsp (folder %public%\ABBYY\FlexiCapture\12.0\Samples\FLS\Tips and Tricks\RestrictSearchArea). This project is actually a copy of the project of the same name from the Date\FCS project folder. The search constraints for all the elements in it (DateField, DateAsString and DateAsObjectCollection) were identical and looked as shown in the figure below.
But in the current project, instead of doubling the search constraints in the Relations tab for the elements DateAsString and DateAsObjectCollection, we use the function RestrictSearchArea by writing the following code in the Advanced pre-search relations field on the Advanced tab:
if (DateField.IsNull == FALSE) then Dontfind();
else RestrictSearchArea (DateField.Rect);
This code means that searching for the date field as a string or as an object collection will only be attempted if the program fails to detect it by means of the Date element. And both elements will be looked for in the very area where the element DateField has not been detected. It so happens because the DateField.Rect method restores the rectangle enclosing the hypothesis of the DateField element. Since the hypothesis has not been found, the enclosing rectangle will coincide with the search area. Therefore, we specify a search area for the DateAsString and DateAsObjectCollection elements which coincides with the rectangle enclosing the search area of the undetected DateField element.