com.groupdocs.search.results

Class SearchResult

  • All Implemented Interfaces:
    Iterable<FoundDocument>


    public class SearchResult
    extends Object
    implements Iterable<FoundDocument>
    Represents a search result matching a search query.

    Learn more

    The example demonstrates a typical usage of the class.

     
     String indexFolder = "c:\\MyIndex\\";
     String documentFolder = "c:\\MyDocuments\\";
     // Creating an index
     Index index = new Index(indexFolder);
     // Indexing documents from the specified folder
     index.add(documentFolder);
     // Setting 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 = index.search("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 (int j = 0; j < document.getFoundFields().length; j++) {
             FoundDocumentField field = document.getFoundFields()[j];
             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 (int m = 0; m < terms.length; m++) {
                         sequence += terms[m] + " ";
                     }
                     System.out.println("\t\t\t" + sequence + " - " + field.getTermSequencesOccurrences()[k]);
                 }
             }
         }
     }
     
     
    • Constructor Detail

      • SearchResult

        protected SearchResult(FoundDocument[] documents,
                               boolean truncated,
                               String warnings,
                               ChunkSearchToken nextChunkSearchToken,
                               boolean ignoreLicenseRestrictions)

        Initializes a new instance of the SearchResult class.

        Parameters:
        documents - The found documents.
        truncated - The value indicating that results are truncated.
        warnings - The warnings describing the results.
        nextChunkSearchToken - The next chunk search token.
        ignoreLicenseRestrictions - Is license restriction can be ignored.
    • Method Detail

      • getDocumentCount

        public final int getDocumentCount()

        Gets the number of documents found.

        Returns:
        The number of documents found.
      • getOccurrenceCount

        public final int getOccurrenceCount()

        Gets the total number of occurrences found.

        Returns:
        The total number of occurrences found.
      • getTruncated

        public final boolean getTruncated()

        Gets a value indicating that the result is truncated.

        Returns:
        A value indicating that the result is truncated.
      • getWarnings

        public final String getWarnings()

        Gets a warnings describing the result.

        Returns:
        A warnings describing the result.
      • getNextChunkSearchToken

        public final ChunkSearchToken getNextChunkSearchToken()

        Gets a chunk search token for searching the next chunk.

        Returns:
        A chunk search token for searching the next chunk.
      • getStartTime

        public final Date getStartTime()

        Gets the start time of the search.

        Returns:
        The start time of the search.
      • getEndTime

        public final Date getEndTime()

        Gets the end time of the search.

        Returns:
        The end time of the search.
      • getSearchDuration

        public final double getSearchDuration()

        Gets the search duration in seconds.

        Returns:
        The search duration in seconds.
      • getFoundDocument

        public final FoundDocument getFoundDocument(int index)

        Gets the found document by index.

        Parameters:
        index - The index of a found document.
        Returns:
        The found document.
      • iterator

        public final Iterator<FoundDocument> iterator()

        Returns an iterator that iterates through the collection of the documents found.

        Specified by:
        iterator in interface Iterable<FoundDocument>
        Returns:
        An iterator that can be used to iterate through the collection of the found documents.
      • appendWarning

        protected static void appendWarning(SearchResult searchResult,
                                            String warning)
      • setTime

        protected static void setTime(SearchResult searchResult,
                                      com.aspose.ms.System.DateTime startTime,
                                      com.aspose.ms.System.DateTime endTime)