> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Functions which limit the search area

> Limit element search areas in FlexiLayout advanced pre-search relations with LeftOf, RightOf, Above, Below, Exclude, and RestrictSearchArea functions.

The functions listed in the following table can only be used in the **Advanced pre-search relations** section. Each function specifies a fuzzy rectangle for the search area or adds rectangles to an array of excluded rectangles.

| Definition                                                                                    | Description                                                                                                                                                                                    |
| --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Void LeftOf( XInterval x, Distance offset = 0 )`                                             | Limits the search area to a rectangle which is the result of intersecting the rectangle of the page with the vertical half-plane located to the left of the point `x.End - offset`.            |
| `Void LeftOf( FuzzyRect fuzzyRect, Distance offset = 0 )`                                     | Limits the search area by the vertical half-plane to the left of the point `fuzzyRect.Left.End - offset`.                                                                                      |
| `Void LeftOf( Hypothesis hyp, Distance offset = 0 )`                                          | Limits the search area to a rectangle which is the result of intersecting the rectangle of the page with the vertical half-plane located to the left of the point `hyp.Left.End - offset`.     |
| `Void LeftOf( HypothesisInstances hyps, Distance offset = 0 )`                                | Limits the search area by the vertical half-plane to the left of the point `hyps.Left.End - offset`. Global coordinates are used.                                                              |
| `Void RightOf( XInterval x, Distance offset = 0 )`                                            | Limits the search area to a rectangle which is the result of intersecting the rectangle of the page with the vertical half-plane located to the right of the point `x.Start + offset`.         |
| `Void RightOf( FuzzyRect fuzzyRect, Distance offset = 0 )`                                    | Limits the search area by the vertical half-plane to the right of the point `fuzzyRect.Right.Start + offset`.                                                                                  |
| `Void RightOf( Hypothesis hyp, Distance offset = 0 )`                                         | Limits the search area to a rectangle which is the result of intersecting the rectangle of the page with the vertical half-plane located to the right of the point `hyp.Right.Start + offset`. |
| `Void RightOf( HypothesisInstances hyps, Distance offset = 0 )`                               | Limits the search area by the vertical half-plane to the right of the point `hyps.Right.Start + offset`. Global coordinates are used.                                                          |
| `Void Above( YInterval y, Distance offset = 0 )`                                              | Limits the search area to a rectangle which is the result of intersecting the rectangle of the page with the horizontal half-plane located above the point `y.End - offset`.                   |
| `Void Above( FuzzyRect fuzzyRect, Distance offset = 0 )`                                      | Limits the search area by the horizontal half-plane above the point `fuzzyRect.Top.End - offset`.                                                                                              |
| `Void Above( Hypothesis hyp, Distance offset = 0 )`                                           | Limits the search area to a rectangle which is the result of intersecting the rectangle of the page with the horizontal half-plane located above the point `hyp.Top.End - offset`.             |
| `Void Above( HypothesisInstances hyps, Distance offset = 0 )`                                 | Limits the search area by the horizontal half-plane above the point `hyps.Top.End - offset`. Global coordinates are used.                                                                      |
| `Void Below( YInterval y, Distance offset = 0 )`                                              | Limits the search area to a rectangle which is the result of intersecting the rectangle of the page with the horizontal half-plane located below the point `y.Start + offset`.                 |
| `Void Below( FuzzyRect fuzzyRect, Distance offset = 0 )`                                      | Limits the search area by the horizontal half-plane below the point `fuzzyRect.Bottom.Start + offset`.                                                                                         |
| `Void Below( Hypothesis hyp, Distance offset = 0 )`                                           | Limits the search area to a rectangle which is the result of intersecting the rectangle of the page with the horizontal half-plane located below the point `hyp.Bottom.Start + offset`.        |
| `Void Below( HypothesisInstances hyps, Distance offset = 0 )`                                 | Limits the search area by the horizontal half-plane below the point `hyps.Bottom.Start + offset`. Global coordinates are used.                                                                 |
| `Void Exclude( Hypothesis hyp )`                                                              | Excludes the region of the `hyp` hypothesis from the search area. If the `hyp` hypothesis is not found, excludes the internal rectangle of the search area of the `hyp` hypothesis.            |
| `Void Exclude( Rect rect )`                                                                   | Excludes the `rect` rectangle from the search area.                                                                                                                                            |
| `Void Exclude( RectArray rectArray )`                                                         | Excludes the `rectArray` array of rectangles from the search area.                                                                                                                             |
| `Void ExcludeRect( XInterval left, YInterval top, XInterval right, YInterval bottom )`        | Excludes the fuzzy rectangle described by the ranges `left`, `top`, `right`, and `bottom` from the search area.                                                                                |
| `Void ExcludeSet( ImageObjectSet set )`                                                       | Excludes the array of rectangles of the `set` set of objects from the search area.                                                                                                             |
| `Void Exclude( HypothesisInstances )`                                                         | Excludes the region of the hypothesis instances from the search area.                                                                                                                          |
| `Void RestrictSearchArea( FuzzyRect fuzzyRect )`                                              | Limits the search area to the fuzzy rectangle `fuzzyRect`. Global coordinates are used.                                                                                                        |
| `Void RestrictSearchArea( FuzzyRect, IntArray pages )`                                        | Limits the search area to the fuzzy rectangle `fuzzyRect`. Specify the local coordinates and page range `pages`.                                                                               |
| `Void RestrictSearchArea( FuzzyRect, SearchAreaPageSetType )`                                 | Limits the search area to the fuzzy rectangle `fuzzyRect`. Specify the local coordinates and page range of the type `SearchAreaPageSetType`.                                                   |
| `Void RestrictSearchArea( RectArray rectArray )`                                              | Limits the search area to the array of rectangles `rectArray`. Global coordinates are used.                                                                                                    |
| `Void RestrictSearchArea( RectArray, IntArray pages )`                                        | Limits the search area to the array of rectangles `rectArray`. Specify the local coordinates and page range `pages`.                                                                           |
| `Void RestrictSearchArea( RectArray, SearchAreaPageSetType )`                                 | Limits the search area to the array of rectangles `rectArray`. Specify the local coordinates and page range of the type `SearchAreaPageSetType`.                                               |
| `Void RestrictSearchArea( Region region )`                                                    | Limits the search area to the region `region`. Global coordinates are used.                                                                                                                    |
| `Void RestrictSearchArea( Region, IntArray pages )`                                           | Limits the search area to the region. Specify the local coordinates and page range `pages`.                                                                                                    |
| `Void RestrictSearchArea( Region, SearchAreaPageSetType )`                                    | Limits the search area to the region. Specify the local coordinates and page range of the type `SearchAreaPageSetType`.                                                                        |
| `Void RestrictSearchArea( SearchAreaPageRestriction pageRestriction, IntArray pages )`        | Limits the page range on which to search without limiting the search area on the pages themselves. The `pageRestriction` parameter accepts only one value: `WholePage`.                        |
| `Void RestrictSearchArea( SearchAreaPageRestriction pageRestriction, SearchAreaPageSetType )` | Limits the page range on which to search without limiting the search area on the pages themselves. The `pageRestriction` parameter accepts only one value: `WholePage`.                        |

<Tip>
  You can use the `RSA` alias instead of the full name `RestrictSearchArea`.
</Tip>

<Note>
  Different constraints for the same page are used jointly, and for different pages independently. (The search is performed on the pages for which at least one constraint has been specified.)
</Note>

## Examples of limiting the search area

You can specify that the element search area is located to the right of the intersection area formed by the `Element1` and `Element2` fuzzy rectangles:

```text theme={null}
FuzzyRect intersection = Element1.FuzzyRect AND Element2.FuzzyRect;
RightOf: intersection;
```

You can specify that the boundaries of the search area of the current element are defined by the boundaries of the rectangles of the `ElementName1`, `ElementName2`, and `ElementName3` elements. If any of the elements are not detected, calling this function defines the search area of the current element by the boundaries of the search areas of the corresponding elements:

```text theme={null}
RestrictSearchArea: RectArray(ElementName1.Rect or ElementName2.Rect or ElementName3.Rect);
```

You can specify that the search area of the current element is limited to the region of the `ElementName` element:

```text theme={null}
RestrictSearchArea: ElementName.Region;
```

You can specify that the element must be searched for in the search area on even pages:

```text theme={null}
RestrictSearchArea: searchArea, EvenPages;
```

You can specify that the element must be searched for on pages 2, 4, and 7-9:

```text theme={null}
RestrictSearchArea: WholePage, 2 << 4 << 7 << 8 << 9;
```

You can specify that the element must be searched for on the last page:

```text theme={null}
RestrictSearchArea: WholePage, LastPage;
```

## Auxiliary functions that define the search area

| Definition         | Description                                                                                                                                                                             |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Rect PageRect()`  | The rectangle of the current page in global coordinates, used to specify a search area that depends on the page. The `PageRect` construction can only be used to specify a search area. |
| `Int PageNumber()` | The number of the current page. Use it to specify a search area that depends on the page.                                                                                               |

To specify that the element is located in the bottom half of a page (the exact page is not known in advance), write:

```text theme={null}
Below: PageRect.Top + PageRect.Height / 2;
```

In all other cases, use the construction `Page( N ).Rect` to get the rectangle of page number `N`, or `DocumentRect` to get the rectangle of the entire document. You can also use the `PageNumber` function to specify a search area that depends on the page.

Suppose you have a repeating element `SearchElements.PageHeader`. To search on each page beneath the instances of this element, write:

```text theme={null}
Below: SearchElements.PageHeader.AllInstances.PageAreaGlobal( PageNumber ).FuzzyRect, 0 * dot;
```
