---
title: "Query"
canonical_url: "https://www.nutrient.io/api/csharp/query/"
md_url: "https://www.nutrient.io/api/csharp/query.md"
last_updated: "2026-10-08T08:55:57.713Z"
description: "Entry point for querying document content."
---

Entry point for querying document content. A `Query` holds a built, in-memory search index over a document (or a file / folder / prebuilt index) and answers ranked text-search questions against it — the "index once, query many" model. Build one with the static `CreateIndex` / `CreateIndex` factories, then call `TextSearch` on the returned instance as often as you like. The ranking itself lives in the engine-independent `NativeSDK.Search` assembly; this licensed, bridge-exposed facade applies the entitlement gate and delegates.

```csharp

using Nutrient;

```

The SDK creates this class through factory methods or other SDK objects.

## Methods

### CreateIndex

```csharp

public static Query CreateIndex(Document document)

```

Build a `Query` over any document, regardless of its source format. The document is converted to layout-preserving plain text in memory with the SDK's `TextExporter` (page-boundary markers forced on, then restored) and tokenized + ranked once. Then call `TextSearch` on the returned Query as many times as you like — each query skips this conversion and build. The Query captures the document's settings and is independent of it, so the document may be closed once the Query is built. Hits are reported by their original document page plus an approximate within-page line.

**Parameters**

| Name       | Type                                | Description                                                                                                                                                                                                                                   |
| ---------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `document` | [`Document`](/api/csharp/document/) | An open document of any supported input format. Its `DocumentSettings` (the `SearchSettings` group plus Markdown settings) drives the conversion and later queries — configure it on the document (e.g. via `Document.Open(path, settings)`). |

**Returns:** [`Query`](/api/csharp/query/)

```csharp

public static Query CreateIndex(string input, DocumentSettings settings)

```

Build a `Query` from a file path — a text/Markdown (`.md`/`.txt`) file, a directory of them (searched as one attributed corpus), or a prebuilt index. Any other file is rejected (open other formats as a `Document` and use `CreateIndex`). Then call `TextSearch` on the returned Query. A prebuilt index built from a document keeps its page provenance; plain text reports line ranges.

**Parameters**

| Name       | Type                                                                   | Description                                                                                                                                      |
| ---------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `input`    | `string`                                                               | Path to a UTF-8 text/Markdown (`.md`/`.txt`) file, a directory of them, or a prebuilt index file.                                                |
| `settings` | [`DocumentSettings`](/api/csharp/settings/document/document-settings/) | Document settings; its `SearchSettings` group (algorithm, language, emit-index) drives the build and is captured for the Query's later searches. |

**Returns:** [`Query`](/api/csharp/query/)

### TextSearch

```csharp

public string TextSearch(string query)

```

Ranked BM-25 search over this Query's built index — the "index once, query many" path. No document conversion or index rebuild happens here; only the query runs. Each hit is reported by its original document page (for a document-built index) or line range (for plain text). The per-query knobs (top-k, context, mode, display) come from the settings captured when the Query was built. Returns an empty string when nothing clears the relevance floor.

**Parameters**

| Name    | Type     | Description                                         |
| ------- | -------- | --------------------------------------------------- |
| `query` | `string` | Natural-language query; matched case-insensitively. |

**Returns:** `string`

## Resource management

```csharp

public void Dispose()

```

`Query` implements `IDisposable` and owns native resources. Always call `Dispose()` or use a C# `using` declaration: it is not released automatically.

---

## Related pages

- [Csharp](/api/csharp.md)
- [Data Extraction](/api/csharp/data-extraction.md)
- [Document](/api/csharp/document.md)
- [License](/api/csharp/license.md)
- [Telemetry](/api/csharp/telemetry.md)
- [Vision](/api/csharp/vision.md)

