Search results

Search results are represented by the SearchResult class, an instance of which is returned by the search method of the Index class. The search method of the IndexRepository class also returns an instance of the SearchResult class.

The SearchResult class contains the following members:

  • The getDocumentCount method returns the number of documents found.
  • The getOccurrenceCount method returns the total number of occurrences found.
  • The getTruncated method returns a value indicating that the result is truncated due to limits specified in the search options.
  • The getWarnings method returns a warnings describing the result, for example, a warning about the presence of stop word in a search query.
  • The getNextChunkSearchToken method returns a chunk search token to search for the next chunk. For details on search by chunks, see the Search by chunks page.
  • The getStartTime method returns the start time of the search.
  • The getEndTime method returns the end time of the search.
  • The getSearchDuration method returns the search duration.
  • The getFoundDocument method returns the found document by index.

The found document is represented by an instance of the FoundDocument class. The FoundDocument class contains the following members:

  • The getDocumentInfo method returns the document info object containing the file path, the file type, the format family, and the inner document path for items of container documents.
  • The getRelevance method returns the relevance of the document in the search result.
  • The getOccurrenceCount method returns the number of occurrences found in the document.
  • The getFoundFields method returns the found document fields.
  • The getTerms method returns the found terms. The value is evaluated each time the property is accessed based on the data for each document field found.
  • The getTermSequences method returns the found term sequences.
  • The serialize method serializes the current found document instance to a byte array.
  • The deserialize method deserializes an instance of found document from a byte array.

The found document field is represented by an instance of the FoundDocumentField class. The FoundDocumentField class contains the following members:

The following example shows how to print information on the documents found in the console.

String indexFolder = "c:\\MyIndex\\";
String documentFolder = "c:\\MyDocuments\\";
// Creating an index
Index index = new Index(indexFolder);
// Indexing documents from the specified folder
// Creating search options
SearchOptions options = new SearchOptions();
options.getFuzzySearch().setEnabled(true); // Enabling the fuzzy search
options.getFuzzySearch().setFuzzyAlgorithm(new TableDiscreteFunction(3)); // Setting the maximum number of differences to 3
// Search for documents containing the word 'Einstein' or the phrase 'Theory of Relativity'
SearchResult result ="Einstein OR \"Theory of Relativity\"", options);
// Printing the result
System.out.println("Documents: " + result.getDocumentCount());
System.out.println("Total occurrences: " + result.getOccurrenceCount());
for (int i = 0; i < result.getDocumentCount(); i++) {
    FoundDocument document = result.getFoundDocument(i);
    System.out.println("\tDocument: " + document.getDocumentInfo().getFilePath());
    System.out.println("\tOccurrences: " + document.getOccurrenceCount());
    for (FoundDocumentField field : document.getFoundFields()) {
        System.out.println("\t\tField: " + field.getFieldName());
        System.out.println("\t\tOccurrences: " + document.getOccurrenceCount());
        // Printing found terms
        if (field.getTerms() != null) {
            for (int k = 0; k < field.getTerms().length; k++) {
                System.out.println("\t\t\t" + field.getTerms()[k] + " - " + field.getTermsOccurrences()[k]);
        // Printing found phrases
        if (field.getTermSequences() != null) {
            for (int k = 0; k < field.getTermSequences().length; k++) {
                String[] terms = field.getTermSequences()[k];
                String sequence = "";
                for (String term : terms) {
                    sequence += term + " ";
                System.out.println("\t\t\t" + sequence + " - " + field.getTermSequencesOccurrences()[k]);

More resources

GitHub examples

You may easily run the code from documentation articles and see the features in action in our GitHub examples:

Free online document search App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.