# Filtered Search

> A java.util.function.Predicate<Key> on the search, multiply, attention and MaxSim configs decides which candidate keys a walk may report, and a Progress on every long verb hears its advance and cancels it by answering false, which the call reports as Status.CANCELLED.

`import cloud.unum.usearch.*;` 3.0.0-rc.1 · cabb6603

### Callbacks

A `java.util.function.Predicate<Key>` on the search, multiply, attention and MaxSim configs decides which candidate keys a walk may report, and a `Progress` on every long verb hears its advance and cancels it by answering false, which the call reports as `Status.CANCELLED`. An insertion is all-or-nothing, so its progress handler cannot cancel it. Each runs as an upcall straight into your object, the predicate on the executor’s threads together and the progress handler never concurrently. Neither may throw: an exception escaping a callback terminates the process. A `Predicate<Key>` answers one key at a time, asked as candidates are scored, while a `BatchPredicate` answers an array of keys into an array of admissions, each starting as `false`, and is asked once per traversal round, for a handler that pays per call, such as a lookup in an external database. `predicate(batch, PredicateCost.CHEAP)` asks it as candidates arrive instead.

```java
DenseSearchConfig filtered = new DenseSearchConfig(10).predicate(key -> allowed.contains(key));
DenseSearchConfig looked = new DenseSearchConfig(10).predicate((keys, admissions) -> database.admit(keys, admissions));
DenseSearchConfig watched = new DenseSearchConfig(10).progress((completed, total) -> !cancelRequested());
index.save("index.safegraphs", (completed, total) -> { bar.set(completed, total); return true; });
```

## API

### Types

#### `Progress`

Hears how far a long call has advanced, in whatever units it consumes, and decides whether it goes on.

[Types.java:2067 ↗](https://github.com/unum-cloud/USearch/blob/cabb660355b45ed0d6ade2dc86ca58be01d61e29/java/cloud/unum/usearch/Types.java#L2067)

```java
interface Progress
```

Never called concurrently, and never after the call it was passed to is final.

It must not throw; an exception escaping it terminates the process.

### Functions

#### `PhaseProgress`

Where a plan stands once a call naming it returned.

[Types.java:2127 ↗](https://github.com/unum-cloud/USearch/blob/cabb660355b45ed0d6ade2dc86ca58be01d61e29/java/cloud/unum/usearch/Types.java#L2127)

```java
record PhaseProgress(
    Phase phase,
    long ordinal,
    long completed,
    long total);
```

#### Parameters

| `phase` | | the kind of work in hand. |
| - | - | - |
| `ordinal` | | this phase's position among the ones the plan runs. |
| `completed` | | units of this phase done, entries or islands. |
| `total` | | units of this phase in all. |
