---
title: "Query"
canonical_url: "https://www.nutrient.io/api/python/query/"
md_url: "https://www.nutrient.io/api/python/query.md"
last_updated: "2026-07-15T14:46:57.766Z"
description: "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 ra…"
---

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.

```python

from nutrient_sdk import Query

```

## Construction

`Query` cannot be instantiated directly. Obtain instances through static factory methods or via other SDK classes.

## Class Methods

### create_index

```python

@classmethod
def create_index(cls, document: Document) -> Query

```

```python

@classmethod
def create_index(cls, input: str, settings: DocumentSettings) -> Query

```

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` *(optional)* | [`Document`](/api/python/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)`). |
| `input` *(optional)*    | `str`                                                                  | Path to a UTF-8 text/Markdown (`.md`/`.txt`) file, a directory of them, or a prebuilt index file.                                                                                                                                             |
| `settings` *(optional)* | [`DocumentSettings`](/api/python/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/python/query/)

---

## Methods

### text_search

```python

def text_search(self, query: str) -> str

```

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` | `str` | Natural-language query; matched case-insensitively. |

**Returns:** `str`

---

---

## Related pages

- [Open a PDF and convert it to a Word document](/api/python.md)
- [Document](/api/python/document.md)
- [License](/api/python/license.md)
- [Telemetry](/api/python/telemetry.md)
- [Vision](/api/python/vision.md)

