import { type DescribedFile } from '@variance-authority/sense'; import type { SearchIndex } from '../search-index.js'; import type { Said } from './held-sentence.js'; import type { DeclaredRead, FileMatch } from './search-matches.js'; /** * The repository's own names and files a description reaches, asked by the * words the dependency lexicon asks a package by. * * A description is not a name: `tsconfig custom conditions` is three words an * agent would say about `customConditionsFor`, and neither the phrase nor every * word is in it. So the question is cut into stems by the rule the installed * packages were cut by — the sense addon owns it, stopwords included — and a name * answers when its own words, or the documentation of a row that publishes or * exports it, hold any of the question's distinct stems. Only a row that * {@link carriesMost} of the question is shown or counted, so a concept the * repository lacks is told as a none; how much it holds decides where it sits. A * dictionary term stands for a stem when it reduces to it, so `files` stands for * `file` and `filter` does not. A name its file declares and does not export is in * no row, so the source index answers for it by the same rule, its name and its * doc comment read in the sense addon. A file is described the same way, by the * words of its own name and of the doc it opens with — what it is for, which no * one declaration in it says. The words every package says about itself — * `package`, `module`, `use`, `tool`, `get` and the like — are asked of code and * not of a package, since code is named in them. * * Ordered by how much of the question it holds, each word weighed by how rare it * is among everything the description reached — {@link rarity}, of the `N` * reached and the `n` holding it, counted in this one question and stored nowhere * — times the weight of where it holds it, {@link FIELD_WEIGHTS}, as a * field-weighted ranking weighs a title over a body. A doc word also counts by * how long the doc is, BM25's length term with a held word's count of one: a doc * of the mean length or shorter counts as two, a longer one less, the mean taken * over the doc of every row, declaration and file reached. A long doc holds most * words in passing, and a doc's word stays below a name's however short. That sum * is multiplied by a coordination factor, {@link weightOf}. A name is weighed and * shown through one of its rows, {@link DescribedName.through}, and counts once * in `N` and in the `n` of a word any of its rows holds, so no name's row moves * another's weight. Integers throughout, so the order is counts, never a score, * and a tie is a tie (ADR-0057). `N` is everything reached, the names another * section shows included, so the weight of a word does not move with what is * left. Then the words its name holds, then how many of the question's adjacent * word pairs its doc writes as a phrase, then how many rows publish or export it, in * an area those {@link rowWithin} it, then the name's own rank. A word every doc * says in passing tells nothing about which of them was meant: * `find the repository root` is asked of `repositoryRoot`, not of every doc that * opens on `find` and mentions a root, when most of what was reached says `find`. * A name was chosen for what it does, and a doc that writes the question's phrase * about a name that holds none of it is usually saying what the name is used * with. The phrase — term proximity, counted as the pairs it shares — settles * what the weight and the name leave level. * * The rows shown hold every word anything reached holds: the best holder of a word * no row shown holds takes the place of the last row whose every word another row * shown also holds, so `mermaid chart palette` shows the one name holding * `mermaid` however many names holding `chart` sort before it. The phrase is * counted only for a name that can be shown, since a doc is decoded to count it. */ /** What a reached name is ordered on. */ export interface DescribedKey { /** The question's words it holds, as the question wrote them, in stem order. */ readonly words: readonly string[]; /** Those of them its name holds. */ readonly named: readonly string[]; /** Those of them only its signature holds, neither its name nor its doc; absent on a file, which has no signature. */ readonly signed?: readonly string[]; /** How many of the question's adjacent word pairs its doc writes, by {@link nearOfNative}. */ readonly near: number; /** Rows that publish or export it, in an area only those {@link rowWithin} it. */ readonly rows: number; /** The name id, which is its place in code-unit order; after every name for what is not one. */ readonly rank: number; /** The bytes of the doc it is judged by, absent when it has none: what a word its doc holds is counted against. */ readonly docLength?: number; } /** One name of the search index the description reached. */ export interface DescribedName extends DescribedKey { readonly name: number; /** * The row it is weighed, ordered and shown through: of its published and * exported rows, the one its name's words and that row's doc weigh most by * {@link weightOf}; of those weighing alike, the one whose doc writes the most * of the question's adjacent word pairs, then the first by {@link RowOrder}. */ readonly through: DescribedRow; } /** One published or exported row of the search index. */ export interface DescribedRow { readonly kind: 'published' | 'exported'; readonly row: number; } /** * The order one name's rows are shown in, a total order: of the rows a name * weighs as much through, whose docs write as many of the question's adjacent * word pairs, the first is the one it is shown through. */ export type RowOrder = (a: DescribedRow, b: DescribedRow) => number; /** One declaration no export binds that the description reached: in no row, and ranked after every name that is. */ export interface DescribedDeclaration extends DescribedKey { readonly match: DeclaredRead; } /** One file the description reached by its own name and the doc it opens with. */ export interface DescribedFileHit extends DescribedKey { readonly file: DescribedFile; } /** What a description reached, of any kind. */ export type Described = DescribedName | DescribedDeclaration | DescribedFileHit; /** A name of the search index the description reached, before its doc is read for the phrase. */ export type ReachedName = Omit & Counted & { /** * The rows it can be shown through: the one it is weighed through, then each * other row with a doc weighing as much, by {@link RowOrder}. */ readonly tied: readonly RowPick[]; /** Every row it can still be shown through, the best first. */ readonly picks: readonly RowPick[]; }; /** One row a name could be shown through. */ export type RowPick = Pick & { /** What the row weighs against the question. */ readonly weighs: number; }; /** What one reached thing counts for in every word's rarity and the mean doc length: the same whichever row it is weighed through. */ interface Counted { /** The question's words held anywhere: in its name, or in any doc it could be weighed through. */ readonly holds: readonly string[]; /** The bytes of each doc it could be weighed through. */ readonly docLengths: readonly number[]; } export declare const countedOf: (one: Reached) => Counted; /** What a description reached, a name's phrase not yet counted. */ export type Reached = ReachedName | DescribedDeclaration | DescribedFileHit; /** * Names holding any of the description's distinct stems, unordered; * `undefined` when the question has no word to describe — every word short or * a stopword — so it was not asked. * * `already` names are never reached. `within`, file ids when given, admits a * name by its own words and a doc only through a row {@link rowWithin} the * area and counts only those rows; the index writes a name only for a row of * it, so every name reached has one. `order` is the {@link RowOrder} of the * section showing them. `others`, the declarations and files reached, count in * each word's rarity and in the mean doc length. */ export declare function describedNames(index: SearchIndex, query: string, within: ReadonlySet | undefined, already: ReadonlySet, order: RowOrder, others?: readonly (DescribedDeclaration | DescribedFileHit)[]): readonly ReachedName[] | undefined; /** * The `count` rows of `reached` to show, best first by {@link describedOrderBy} the weight of what they reached: * the best of them, but a word anything reached holds is held by one of them, * its best holder taking the place of the last row a better one did not need. * * The weight of the words held and the words in the name order a row before * its phrase does, so a name's doc is decoded for the phrase only when the name * is level on both with a row that can be shown: in a level the rows above * leave room in, or the best level among a word's holders. A word is weighed * by how rare it is in `population`, everything the description reached, of * which `reached` is what is left to show. */ export declare function describedShown(index: SearchIndex, query: string, reached: readonly Reached[], count: number, population: readonly Reached[]): readonly Described[]; /** * Two rows of one kind level on every count, in every section: the doc's text, * an absent one last, then what a published row declares or the line an * exported one is declared on, then the file, then a published row's specifier, * in code-unit order. Where the index wrote a row follows its package and file * names, which say nothing about the name, so it settles nothing. A published * row has no line, so the file settles two published declarations of one * kind under one doc; otherwise the path and the specifier settle only one name * two files export on one line under one doc, or one declaration two specifiers * publish. */ export declare function rowTextOrder(index: SearchIndex, a: DescribedRow, b: DescribedRow): number; /** * The declarations no export binds, and the files, in `files` when they are * named, whose name and doc hold any of the description's distinct stems; * `undefined` when the question has no word to describe or no checkout * was named, and when its source index is absent or does not read, which the * `declared` section already says. */ export declare function describedDeclarations(root: string | undefined, query: string, files: Iterable | undefined): readonly (DescribedDeclaration | DescribedFileHit)[] | undefined; /** * A described file as a `search` section holds it, with what `said` makes of * the module doc the index recorded; none when it recorded none. */ export declare function fileMatch(file: DescribedFile, said: Said): FileMatch; export {}; //# sourceMappingURL=described.d.ts.map