> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/algolia/docsearch/llms.txt
> Use this file to discover all available pages before exploring further.

# DocSearchHit

> Type definitions for DocSearch hit objects returned from Algolia

# DocSearchHit Types

DocSearch uses several hit type definitions to represent search results at different stages of processing. These types define the structure of search results returned from Algolia and how they're used internally.

## DocSearchHit

The primary type representing a search result from Algolia. This is the base hit type returned from search queries and includes all highlighting and snippet information.

<ResponseField name="objectID" type="string" required>
  Unique identifier for the search result.
</ResponseField>

<ResponseField name="content" type="string | null" required>
  The text content of the search result. May be null for hierarchy-only results.
</ResponseField>

<ResponseField name="query" type="string">
  The search query that produced this result.
</ResponseField>

<ResponseField name="url" type="string" required>
  Full URL to the page, including any anchor.
</ResponseField>

<ResponseField name="url_without_anchor" type="string" required>
  URL to the page without the anchor/hash portion.
</ResponseField>

<ResponseField name="type" type="ContentType" required>
  The type of content this hit represents.

  ```typescript theme={null}
  type ContentType = 'askAI' | 'content' | 'lvl0' | 'lvl1' | 'lvl2' | 'lvl3' | 'lvl4' | 'lvl5' | 'lvl6';
  ```

  * `askAI`: Ask AI suggestion or result
  * `content`: Regular page content
  * `lvl0` through `lvl6`: Hierarchical heading levels
</ResponseField>

<ResponseField name="anchor" type="string | null" required>
  The anchor/hash portion of the URL, if any.
</ResponseField>

### Hierarchy

<ResponseField name="hierarchy" type="object" required>
  Hierarchical structure representing the page organization and headings.

  <Expandable title="Hierarchy Properties">
    <ResponseField name="lvl0" type="string" required>
      Top-level heading (typically site name or main section).
    </ResponseField>

    <ResponseField name="lvl1" type="string" required>
      Second-level heading (typically page title).
    </ResponseField>

    <ResponseField name="lvl2" type="string | null" required>
      Third-level heading (subsection).
    </ResponseField>

    <ResponseField name="lvl3" type="string | null" required>
      Fourth-level heading.
    </ResponseField>

    <ResponseField name="lvl4" type="string | null" required>
      Fifth-level heading.
    </ResponseField>

    <ResponseField name="lvl5" type="string | null" required>
      Sixth-level heading.
    </ResponseField>

    <ResponseField name="lvl6" type="string | null" required>
      Seventh-level heading.
    </ResponseField>
  </Expandable>

  <CodeGroup>
    ```json Example Hierarchy theme={null}
    {
      "lvl0": "Documentation",
      "lvl1": "Getting Started",
      "lvl2": "Installation",
      "lvl3": "React",
      "lvl4": null,
      "lvl5": null,
      "lvl6": null
    }
    ```
  </CodeGroup>
</ResponseField>

### Highlight Results

<ResponseField name="_highlightResult" type="DocSearchHitHighlightResult" required>
  Highlighting information showing which parts of the result matched the search query.

  <Expandable title="DocSearchHitHighlightResult Type">
    ```typescript theme={null}
    interface DocSearchHitHighlightResult {
      content: DocSearchHitAttributeHighlightResult;
      hierarchy: DocSearchHitHighlightResultHierarchy;
      hierarchy_camel: DocSearchHitHighlightResultHierarchy[];
    }
    ```

    <ResponseField name="content" type="DocSearchHitAttributeHighlightResult">
      Highlighting information for the content field.
    </ResponseField>

    <ResponseField name="hierarchy" type="DocSearchHitHighlightResultHierarchy">
      Highlighting information for each hierarchy level.
    </ResponseField>

    <ResponseField name="hierarchy_camel" type="DocSearchHitHighlightResultHierarchy[]">
      Alternative hierarchy highlighting format.
    </ResponseField>
  </Expandable>

  <Expandable title="DocSearchHitAttributeHighlightResult Type">
    ```typescript theme={null}
    interface DocSearchHitAttributeHighlightResult {
      value: string;
      matchLevel: 'full' | 'none' | 'partial';
      matchedWords: string[];
      fullyHighlighted?: boolean;
    }
    ```

    <ResponseField name="value" type="string">
      The highlighted value with `<mark>` tags around matched portions.
    </ResponseField>

    <ResponseField name="matchLevel" type="'full' | 'none' | 'partial'">
      Indicates how well the attribute matched the query.
    </ResponseField>

    <ResponseField name="matchedWords" type="string[]">
      Array of words that matched in this attribute.
    </ResponseField>

    <ResponseField name="fullyHighlighted" type="boolean">
      Whether the entire value was highlighted.
    </ResponseField>
  </Expandable>

  <Expandable title="DocSearchHitHighlightResultHierarchy Type">
    ```typescript theme={null}
    interface DocSearchHitHighlightResultHierarchy {
      lvl0: DocSearchHitAttributeHighlightResult;
      lvl1: DocSearchHitAttributeHighlightResult;
      lvl2: DocSearchHitAttributeHighlightResult;
      lvl3: DocSearchHitAttributeHighlightResult;
      lvl4: DocSearchHitAttributeHighlightResult;
      lvl5: DocSearchHitAttributeHighlightResult;
      lvl6: DocSearchHitAttributeHighlightResult;
    }
    ```

    Contains highlight results for each hierarchy level (lvl0 through lvl6).
  </Expandable>
</ResponseField>

### Snippet Results

<ResponseField name="_snippetResult" type="DocSearchHitSnippetResult" required>
  Snippet information showing contextual excerpts around matched terms.

  <Expandable title="DocSearchHitSnippetResult Type">
    ```typescript theme={null}
    interface DocSearchHitSnippetResult {
      content: DocSearchHitAttributeSnippetResult;
      hierarchy: DocSearchHitHighlightResultHierarchy;
      hierarchy_camel: DocSearchHitHighlightResultHierarchy[];
    }
    ```

    <ResponseField name="content" type="DocSearchHitAttributeSnippetResult">
      Snippet information for the content field.
    </ResponseField>

    <ResponseField name="hierarchy" type="DocSearchHitHighlightResultHierarchy">
      Snippet information for hierarchy levels.
    </ResponseField>

    <ResponseField name="hierarchy_camel" type="DocSearchHitHighlightResultHierarchy[]">
      Alternative hierarchy snippet format.
    </ResponseField>
  </Expandable>

  <Expandable title="DocSearchHitAttributeSnippetResult Type">
    ```typescript theme={null}
    interface DocSearchHitAttributeSnippetResult {
      value: string;
      matchLevel: 'full' | 'none' | 'partial';
    }
    ```

    <ResponseField name="value" type="string">
      The snippet value with `<mark>` tags around matched portions.
    </ResponseField>

    <ResponseField name="matchLevel" type="'full' | 'none' | 'partial'">
      Indicates how well the snippet matched the query.
    </ResponseField>
  </Expandable>
</ResponseField>

### Ranking Information

<ResponseField name="_rankingInfo" type="object">
  Optional ranking information from Algolia explaining why this result was ranked at its position.

  <Expandable title="Ranking Info Properties">
    <ResponseField name="promoted" type="boolean">
      Whether this result was promoted (boosted) in the ranking.
    </ResponseField>

    <ResponseField name="nbTypos" type="number">
      Number of typos in the matched query.
    </ResponseField>

    <ResponseField name="firstMatchedWord" type="number">
      Position of the first matched word.
    </ResponseField>

    <ResponseField name="proximityDistance" type="number">
      Distance between matched words.
    </ResponseField>

    <ResponseField name="geoDistance" type="number">
      Geographic distance (if geo search is used).
    </ResponseField>

    <ResponseField name="geoPrecision" type="number">
      Precision of the geo match.
    </ResponseField>

    <ResponseField name="nbExactWords" type="number">
      Number of exact word matches.
    </ResponseField>

    <ResponseField name="words" type="number">
      Word count metric.
    </ResponseField>

    <ResponseField name="filters" type="number">
      Filter matching score.
    </ResponseField>

    <ResponseField name="userScore" type="number">
      Custom user-defined score.
    </ResponseField>

    <ResponseField name="matchedGeoLocation" type="object">
      Geographic location that matched.

      <Expandable title="Properties">
        <ResponseField name="lat" type="number">
          Latitude.
        </ResponseField>

        <ResponseField name="lng" type="number">
          Longitude.
        </ResponseField>

        <ResponseField name="distance" type="number">
          Distance from search point.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

### Autocomplete Metadata

<ResponseField name="_distinctSeqID" type="number">
  Sequence ID for distinct results (used when `distinct` parameter is enabled).
</ResponseField>

<ResponseField name="__autocomplete_indexName" type="string">
  Internal: The index name this result came from.
</ResponseField>

<ResponseField name="__autocomplete_queryID" type="string">
  Internal: Query ID for analytics tracking.
</ResponseField>

<ResponseField name="__autocomplete_algoliaCredentials" type="object">
  Internal: Algolia credentials for analytics.

  <Expandable title="Properties">
    <ResponseField name="appId" type="string">
      Algolia application ID.
    </ResponseField>

    <ResponseField name="apiKey" type="string">
      Algolia API key.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="__autocomplete_id" type="number">
  Internal: Autocomplete-assigned ID for this hit.
</ResponseField>

## InternalDocSearchHit

Extends `DocSearchHit` with internal metadata used during rendering. This type is used internally by DocSearch components.

```typescript theme={null}
type InternalDocSearchHit = DocSearchHit & {
  __docsearch_parent: InternalDocSearchHit | null;
};
```

<ResponseField name="__docsearch_parent" type="InternalDocSearchHit | null">
  Reference to the parent hit in the hierarchy. Used to group related results and build breadcrumb navigation.

  This creates a tree structure where child results can reference their parent headings.
</ResponseField>

## StoredDocSearchHit

A lightweight version of `DocSearchHit` used for storing hits in localStorage (recent searches, favorites). Excludes highlight and snippet data to reduce storage size.

```typescript theme={null}
type StoredDocSearchHit = Omit<DocSearchHit, '_highlightResult' | '_snippetResult'>;
```

This type includes all properties of `DocSearchHit` except:

* `_highlightResult`: Highlighting information (excluded to save space)
* `_snippetResult`: Snippet information (excluded to save space)

## Usage Examples

<CodeGroup>
  ```tsx Transform Items theme={null}
  <DocSearch
    appId="YOUR_APP_ID"
    apiKey="YOUR_SEARCH_API_KEY"
    indexName="docs"
    transformItems={(items: DocSearchHit[]) => {
      // Filter out certain types
      return items.filter(item => item.type !== 'lvl6');
    }}
  />
  ```

  ```tsx Custom Hit Component theme={null}
  <DocSearch
    appId="YOUR_APP_ID"
    apiKey="YOUR_SEARCH_API_KEY"
    indexName="docs"
    hitComponent={({ hit, children }) => {
      const internalHit = hit as InternalDocSearchHit;
      
      return (
        <a href={hit.url} className="custom-hit">
          <div className="hit-type">{hit.type}</div>
          <div className="hit-hierarchy">
            {hit.hierarchy.lvl0} › {hit.hierarchy.lvl1}
          </div>
          {children}
        </a>
      );
    }}
  />
  ```

  ```tsx Access Highlight Results theme={null}
  function processHits(items: DocSearchHit[]) {
    items.forEach(hit => {
      // Access highlighted content
      const highlightedContent = hit._highlightResult.content.value;
      
      // Check match quality
      const matchLevel = hit._highlightResult.content.matchLevel;
      
      // Get matched words
      const matchedWords = hit._highlightResult.content.matchedWords;
      
      console.log({ highlightedContent, matchLevel, matchedWords });
    });
  }
  ```
</CodeGroup>

## Type Relationships

```mermaid theme={null}
graph TD
    A[DocSearchHit] --> B[InternalDocSearchHit]
    A --> C[StoredDocSearchHit]
    B --> D[Used in hitComponent]
    B --> E[Used in resultsFooterComponent]
    C --> F[Stored in localStorage]
    A --> G[Used in transformItems]
```

* **DocSearchHit**: Base type from Algolia searches
* **InternalDocSearchHit**: Adds parent references for rendering
* **StoredDocSearchHit**: Optimized for localStorage (no highlights/snippets)
