Implementation:A9T9 RPA searchTextInOCRResponse
| Knowledge Sources | |
|---|---|
| Domains | OCR, Text_Search |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for searching and matching text within OCR recognition results, provided by the Ui.Vision OCR service.
Description
The searchTextInOCRResponse function (`src/services/ocr/index.ts`) takes an OCR response (from `runOCR` or `runOCRLocal`) and a search text string, and finds matching occurrences with their word positions and coordinates. It supports exact-match mode via the `[exact]` bracket syntax (e.g. `[Sign In]` for whole-string matching), wildcard patterns (`*` and `?`), and index-based selection (return the Nth match, 0-based). When `exhaust` is true, it returns all matches.
The function extracts positioned words from the OCR parse results, groups them into sequences matching the search text's word count, filters by full match, and returns the match at the requested index (or all matches if `exhaust` is set). The result includes the matched word objects with their bounding-box coordinates, which are used to compute click targets.
Usage
Call this function after `runOCR` to find a specific text string within the recognized text and get its screen coordinates for clicking or verification.
Code Reference
Source Location
- Repository: A9T9/RPA
- File: src/services/ocr/index.ts
- Lines: L664-L873 (searchTextInOCRResponse)
Signature
export function searchTextInOCRResponse(
data: SearchTextInOCRResponseOptions
): OcrTextSearchResult
interface SearchTextInOCRResponseOptions {
text: string, // Search text (supports [exact] and wildcards)
index: number, // Match index (0-based)
parsedResults: OcrParseResult[], // OCR response data
exhaust: boolean // Return all matches if true
}
interface OcrTextSearchResult {
hit: { words: OcrPositionedWord[], similarity: number } | null,
all: { words: OcrPositionedWord[], similarity: number }[],
exhaust: boolean
}
Import
import { searchTextInOCRResponse } from '@/services/ocr'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| text | string | Yes | Search text; `[exact]` syntax forces whole-string match |
| index | number | Yes | 0-based match index to return |
| parsedResults | OcrParseResult[] | Yes | OCR response from runOCR/runOCRLocal |
| exhaust | boolean | Yes | If true, return all matches in `all` |
Outputs
| Name | Type | Description |
|---|---|---|
| hit | null | The selected match: positioned words with bounding boxes + similarity |
| all | object[] | All matches (each with positioned words + similarity) |
Usage Examples
Find Text in OCR Results
import { runOCR, searchTextInOCRResponse } from '@/services/ocr'
const ocrResponse = await runOCR({ image: screenshotDataURI, /* ... */ })
const result = searchTextInOCRResponse({
text: 'Sign In',
index: 0,
parsedResults: ocrResponse.ParsedResults,
exhaust: false
})
if (result.hit) {
const word = result.hit.words[0]
console.log(`Found at (${word.Left}, ${word.Top})`)
}
Exact Match with Wildcards
// [exact] forces whole-string, case-sensitive match
const result = searchTextInOCRResponse({
text: '[Submit*]', // exact prefix match
index: 0,
parsedResults: ocrResponse.ParsedResults,
exhaust: false
})