# TermIndex

Defined in: [packages/term-index/src/term-index.ts:24](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/term-index/src/term-index.ts#L24)

A read-only counted inverted index. Document IDs are zero-based input positions.

## Properties

### size

> `readonly` **size**: `number`

Defined in: [packages/term-index/src/term-index.ts:26](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/term-index/src/term-index.ts#L26)

Number of distinct terms.

***

### documentCount

> `readonly` **documentCount**: `number`

Defined in: [packages/term-index/src/term-index.ts:28](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/term-index/src/term-index.ts#L28)

Number of documents, including those with no terms.

***

### tokenCount

> `readonly` **tokenCount**: `number`

Defined in: [packages/term-index/src/term-index.ts:30](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/term-index/src/term-index.ts#L30)

Total token occurrences, including repeats.

***

### averageDocumentLength

> `readonly` **averageDocumentLength**: `number`

Defined in: [packages/term-index/src/term-index.ts:32](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/term-index/src/term-index.ts#L32)

Tokens per document, or zero if there are no documents.

***

### keys

> `readonly` **keys**: () => `IterableIterator`<`string`>

Defined in: [packages/term-index/src/term-index.ts:34](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/term-index/src/term-index.ts#L34)

Iterate distinct terms in first-seen order.

#### Returns

`IterableIterator`<`string`>

***

### documentLength

> `readonly` **documentLength**: (`id`) => `number` | `undefined`

Defined in: [packages/term-index/src/term-index.ts:36](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/term-index/src/term-index.ts#L36)

Number of tokens in a document. Returns undefined for an absent ID. O(1).

#### Parameters

##### id

`number`

#### Returns

`number` | `undefined`

***

### documentFrequency

> `readonly` **documentFrequency**: (`term`) => `number`

Defined in: [packages/term-index/src/term-index.ts:38](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/term-index/src/term-index.ts#L38)

Number of documents containing the term. Returns zero for an absent term. Expected O(1).

#### Parameters

##### term

`string`

#### Returns

`number`

***

### postings

> `readonly` **postings**: (`term`) => `IterableIterator`<[`TermPosting`](/reference/knotkit/term-index/interfaces/termposting/)>

Defined in: [packages/term-index/src/term-index.ts:40](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/term-index/src/term-index.ts#L40)

Iterate the term’s counted postings in ascending document ID order.

#### Parameters

##### term

`string`

#### Returns

`IterableIterator`<[`TermPosting`](/reference/knotkit/term-index/interfaces/termposting/)>

***

### search

> `readonly` **search**: (`terms`, `options?`) => readonly [`TermHit`](/reference/knotkit/term-index/interfaces/termhit/)\[]

Defined in: [packages/term-index/src/term-index.ts:47](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/term-index/src/term-index.ts#L47)

Rank documents matching any supplied exact term. Ties in score favor lower IDs. Repeated query terms contribute once. The returned array and hits are independent of the index.

#### Parameters

##### terms

readonly `string`\[]

##### options?

[`TermSearchOptions`](/reference/knotkit/term-index/interfaces/termsearchoptions/)

#### Returns

readonly [`TermHit`](/reference/knotkit/term-index/interfaces/termhit/)\[]

#### Throws

With `INVALID_LIMIT` for a limit outside the nonnegative safe integers or `INVALID_TERMS` for an argument other than an array of strings. Eligibility accessor errors propagate.
