> ## 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.

# Nearest functions

> Select the hypothesis closest to a point, element, or page edge with Nearest, NearestX, and NearestY functions in FlexiLayout pre-search relations.

**Nearest** functions tell FlexiLayout Studio that, other things being equal, it must select the hypothesis that is nearest to a certain element or point on the image that is specified by the parameters of the **Nearest** function. In the **Advanced pre-search relations** section of the element, you can use only one **Nearest** function.

After the function is applied, only one hypothesis from a group of several hypotheses is selected. The selection occurs when hypotheses are being generated for the element, that is, before the code entered in the **Advanced post-search relations** section is executed.

For more information, see [Search for elements with Nearest and FuzzyQuality](/flexi-capture/fls/tips-tricks/date9).

**Nearest** functions can be used to select hypotheses for any kind of elements except **Groups**, **Repeating Groups**, and **Tables**.

## Nearest functions

| Definition                                 | Description                                                                                                                                                                                                                                          |
| ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Void NearestX( XCoordinate x )`           | Selects the hypothesis nearest to the vertical line which goes through the point `( x, 0 )`.                                                                                                                                                         |
| `Void NearestY( YCoordinate y )`           | Selects the hypothesis nearest to the horizontal line which goes through the point `( 0, y )`.                                                                                                                                                       |
| `Void Nearest( XInterval x, YInterval y )` | Selects the hypothesis nearest to the rectangle `Rect( x.Start, y.Start, x.End, y.End )`.                                                                                                                                                            |
| `Void Nearest( PageEdge )`                 | Selects the hypothesis on each page of the document that is nearest to one of the page edges: top, bottom, right, or left. **Note.** If several hypotheses are at the same distance from the specified boundary, several hypotheses may be selected. |
| `Void Nearest( Hypothesis hyp )`           | Selects the hypothesis nearest to the fuzzy rectangle `hyp.Rect`.                                                                                                                                                                                    |
| `Void Nearest( HypothesisInstances )`      | Selects the hypothesis closest to the set of hypotheses for the specified **Repeating Group** element.                                                                                                                                               |

Example for `NearestX`:

The following code specifies that the sought element is horizontally nearest to the right boundary of the **ElementName** element.

```text theme={null}
NearestX: ElementName.Right.Start;
```

Example for `NearestY`:

The following code specifies that the sought element is vertically nearest to the top boundary of the **ElementName** element.

```text theme={null}
NearestY: ElementName.Top.Start;
```

Example for `Nearest( XInterval x, YInterval y )`:

The following code specifies that the sought element is closest to the center of the **ElementName** element.

```text theme={null}
Nearest: ElementName.XCenter, ElementName.YCenter;
```

The following code specifies that the sought element is closest to the center of the page.

```text theme={null}
Nearest: PageRect.XCenter, PageRect.YCenter;
```

Example for `Nearest( PageEdge )`:

To specify that the current element is closest to the bottom edge of the page, write:

```text theme={null}
Nearest: PageBottom;
```

Example for `Nearest( Hypothesis hyp )`:

The following code specifies that the sought element is closest to the **ElementName** element.

```text theme={null}
Nearest: ElementName;
```
