public final class

SearchResult

extends Object
implements Comparable<T>
java.lang.Object
   ↳ com.pspdfkit.document.search.SearchResult

Class Overview

Represents a result found when searching for text.

Summary

Nested Classes
class SearchResult.TextSnippet The SearchResult.TextSnippet can be extracted with a search result to present a preview text to the user. 
Fields
public final Annotation annotation Annotation that contains the search result.
public final int pageIndex Page number of the page holding the search result.
public final SearchResult.TextSnippet snippet Search result snippet (preview text).
public final TextBlock textBlock The search result text (containing the actual string, indices and text coordinates).
Public Constructors
SearchResult(int pageIndex, TextBlock textBlock, SearchResult.TextSnippet snippet, Annotation annotation)
Private constructor.
Public Methods
int compareTo(SearchResult another)
static SearchResult create(PdfDocument document, Annotation annotation, Range range, int snippetLength)
Create an immutable search result with a preview snippet from annotation text.
static SearchResult create(PdfDocument document, int pageIndex, Range range, int snippetLength)
Creates an immutable search result with a preview snippet from page text
String toString()
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Comparable

Fields

public final Annotation annotation

Annotation that contains the search result. Valid only when search result was found inside annotation contents. When null, search result was found in page text.

public final int pageIndex

Page number of the page holding the search result.

public final SearchResult.TextSnippet snippet

Search result snippet (preview text). May be null if snippet extraction has been turned off.

public final TextBlock textBlock

The search result text (containing the actual string, indices and text coordinates).

Public Constructors

public SearchResult (int pageIndex, TextBlock textBlock, SearchResult.TextSnippet snippet, Annotation annotation)

Private constructor. Use one of the static factory methods instead.

Public Methods

public int compareTo (SearchResult another)

public static SearchResult create (PdfDocument document, Annotation annotation, Range range, int snippetLength)

Create an immutable search result with a preview snippet from annotation text.

Parameters
document Document which contains the search result.
annotation Annotation containing the search result.
range Character range in annotation contents marking the search result.
snippetLength Length of the preview snippet to extract. May be 0 to not extract any snippet.
Returns
  • A search result extracted from the document.

public static SearchResult create (PdfDocument document, int pageIndex, Range range, int snippetLength)

Creates an immutable search result with a preview snippet from page text

Parameters
document Document which contains the search result.
pageIndex 0-indexed page number of the result.
range Character range on the page marking the search result.
snippetLength Length of the preview snippet to extract. May be 0 to not extract any snippet.
Returns
  • A search result extracted from the document.

public String toString ()