createReaderViewSearchAgent

Creates a new ReaderViewSearchAgent using the specified annotationLayer. Use a ReaderViewSearchAgent to highlight search matches in the ReaderView.

When you provide the ReaderViewSearchAgent with a search query, the agent will use the query to search the visible ReaderDocuments in the ReaderView. For each found search match, the agent creates a ReaderViewAnnotation. The agent will continue to search, add and remove ReaderViewAnnotations as necessary when the ReaderView is navigated.

Note that, the search agent will not modify any options on the annotationLayer. You need to manually configure the ReaderViewAnnotationLayer by setting annotationLayer.options and annotationLayer.defaultAnnotationOptions.

The following example shows how to highlight all search matches:

// Create the annotation layer used for highlighting search results.
val annotationLayer = readerView.createAnnotationLayer().also {
it.options =
ReaderViewAnnotationLayerOptions(
layerStyle = mapOf("mix-blend-mode" to "multiply")
)
it.defaultAnnotationOptions = ReaderViewAnnotationOptions(
rangeStyle = mapOf("background-color" to "lightblue")
)
}

val readerDocumentSearch = readingSystemEngine.readerDocumentSearch

// Create the query
val textQuery = readerDocumentSearch.createTextQuery("Paris")

// Create a search agent that will highlight all matches using the annotation layer.
val searchAgent = readerDocumentSearch.createReaderViewSearchAgent(annotationLayer)
searchAgent.setSearchQuery(textQuery)