# domain/loaders/search.loader.ts

> 26 lines of code and 7 definitions.

Tree: Site tree
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/tree#file-domain-loaders-search-loader-ts
Source text: https://banes-lab.com/assets/sources/source.d23eed650569346299e9661ae711a4b0f5ce5e6f13644ce9e7ba07beec9065db.generated.txt

## Definitions

- `gather` (lexical_declaration, line 16)
- `loadCorpus` (lexical_declaration, line 27, exported)
- `held` (lexical_declaration, line 9)
- `searchPageOf` (lexical_declaration, line 11)
- `definition` (lexical_declaration, line 12)
- `entries` (lexical_declaration, line 17)
- `pages` (lexical_declaration, line 18)

## Uses

- [core/loaders/definition.loader.ts](https://banes-lab.com/source/tree/core/loaders/definition.loader.ts.md)

## Source

```typescript
import type { SearchCorpus, SearchPage } from "#types/search.types";
import { loadPage, registeredPages } from "#domain/registries/page.registry";
import { EVIDENCE } from "#configuration/constants/evidence.source.constants";
import { LEARNING } from "#assets/learning.generated";
import type { PageEntry } from "#types/page.types";
import { SEARCH_PAGE } from "#core/ids/page.ids";
import { listDefinitions } from "#core/loaders/definition.loader";

let held: Promise<SearchCorpus> | null = null;

const searchPageOf = async function searchPageOf(entry: PageEntry): Promise<readonly SearchPage[]> {
    const definition = await loadPage(entry.id);
    return definition === undefined ? [] : [{ definition, icon: entry.icon }];
};

const gather = async function gather(): Promise<SearchCorpus> {
    const entries = registeredPages().filter((entry) => entry.id !== SEARCH_PAGE);
    const pages = (await Promise.all(entries.map(searchPageOf))).flat();
    return {
        definitions: listDefinitions(),
        evidence: EVIDENCE,
        pages,
        route: LEARNING.flatMap((block) => block.stops.map((stop) => stop.path)),
    };
};

export const loadCorpus = async function loadCorpus(): Promise<SearchCorpus> {
    held ??= gather();
    return held;
};
```
