SearchResult

SearchResult class

Represents a search result matching a search query.

public class SearchResult : IEnumerable<FoundDocument>

Properties

Name Description
DocumentCount { get; } Gets the number of documents found.
EndTime { get; } Gets the end time of the search.
NextChunkSearchToken { get; } Gets a chunk search token for searching the next chunk.
OccurrenceCount { get; } Gets the total number of occurrences found.
SearchDuration { get; } Gets the search duration.
StartTime { get; } Gets the start time of the search.
Truncated { get; } Gets a value indicating that the result is truncated.
Warnings { get; } Gets a warnings describing the result.

Methods

Name Description
GetEnumerator() Returns an enumerator that iterates through the collection of the documents found.
GetFoundDocument(int) Gets the found document by index.

Remarks

Learn more

Examples

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.FuzzySearch.Enabled = true; // Enabling the fuzzy search
options.FuzzySearch.FuzzyAlgorithm = 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
Console.WriteLine("Documents: " + result.DocumentCount);
Console.WriteLine("Total occurrences: " + result.OccurrenceCount);
for (int i = 0; i < result.DocumentCount; i++)
{
    FoundDocument document = result.GetFoundDocument(i);
    Console.WriteLine("\tDocument: " + document.DocumentInfo.FilePath);
    Console.WriteLine("\tOccurrences: " + document.OccurrenceCount);
    for (int j = 0; j < document.FoundFields.Length; j++)
    {
        FoundDocumentField field = document.FoundFields[j];
        Console.WriteLine("\t\tField: " + field.FieldName);
        Console.WriteLine("\t\tOccurrences: " + document.OccurrenceCount);
        // Printing found terms
        if (field.Terms != null)
        {
            for (int k = 0; k < field.Terms.Length; k++)
            {
                Console.WriteLine("\t\t\t" + field.Terms[k].PadRight(20) + field.TermsOccurrences[k]);
            }
        }
        // Printing found phrases
        if (field.TermSequences != null)
        {
            for (int k = 0; k < field.TermSequences.Length; k++)
            {
                string sequence = string.Join(" ", field.TermSequences[k]);
                Console.WriteLine("\t\t\t" + sequence.PadRight(30) + field.TermSequencesOccurrences[k]);
            }
        }
    }
}

See Also