ReaderViewSearchAgent

A ReaderViewSearchAgent uses a 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.

The ReaderViewSearchAgent has no search query set by default. Call setSearchQuery with a ReaderDocumentSearchQuery to start searching in the visible ReaderDocuments.

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)

Functions

Link copied to clipboard

Gets the SearchResultItem associated with the specified ReaderViewAnnotation. Use this method when:

Link copied to clipboard

Sets or replaces the query that the agent should use for searching.

Link copied to clipboard

Sets the ReaderViewAnnotationOptions to use when rendering ReaderViewAnnotations for the specified SearchResultItems. You can for example use this to highlight a selected search result item in a different color.