Options
All
  • Public
  • Public/Protected
  • All
Menu

A IReaderViewSearchAgent 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 IReaderViewSearchAgent has no search query set by default. Call setSearchQuery() with a IReaderDocumentSearchQuery 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.
const annotationLayer = readerView.createAnnotationLayer('searchHighlights');
annotationLayer.setLayerOptions({
layerStyle: {
'mix-blend-mode': 'multiply',
},
});
annotationLayer.setDefaultAnnotationOptions({
rangeStyle: {
'background-color': 'lightblue',
},
});

const readerDocumentSearch = readingSystemEngine.getReaderDocumentSearch();

// Create the query
const textQuery = readerDocumentSearch.createTextQuery('Paris');

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

Hierarchy

  • IReaderViewSearchAgent

Index

Methods

clearAllSearchResultItemAnnotationOptions

  • clearAllSearchResultItemAnnotationOptions(): void
  • Clear IReaderViewAnnotationOptions for all ISearchResultItems previously set by setSearchResultItemAnnotationOptions().

    Returns void

getSearchResultItemByAnnotation

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

    • Listening on "annotationClick" to know which ISearchResultItem that was clicked.
    • Listening on "annotationIntersectingVisibleRange" to know which ISearchResultItems that are currently visible in the ReaderView.
    searchHighlightAnnotationLayer.addEngineEventListener('annotationIntersectingVisibleRange', evt => {
    const searchResultItemInView = agent.getSearchResultItemByAnnotation(evt.annotation);
    // Add to list of visible search results.
    });

    Parameters

    Returns ISearchResultItem

setSearchQuery

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

    Removes any annotations previously created by the agent. Set to null to remove all annotations and inactivate the agent.

    Parameters

    Returns void

setSearchResultItemAnnotationOptions

  • Sets the IReaderViewAnnotationOptions 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.

    function onSearchResultListItemClicked(item: ISearchResultItem): void {
    // Highlight the search result item in the ReaderView.
    agent.setSearchResultItemAnnotationOptions([item], {
    rangeClassName: 'selected-item'
    });
    }

    Parameters

    Returns void

Generated using TypeDoc