Search results

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Search MCP server lets your agent work with files on your machine; they are never uploaded. It runs in Docker: replace /path/to/documents with the folder it may use.

claude mcp add groupdocs-search -- docker run --rm -i -v /path/to/documents:/data ghcr.io/groupdocs-search/search-net-mcp:latest
Folders, licensing and more →

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 DocumentCount property returns the number of documents found.
  • The OccurrenceCount property returns the total number of occurrences found.
  • The Truncated property returns a value indicating that the result is truncated: it lacks occurrences that the index has, because a limit of the occurrences specified in the search options is reached (see the Search options page) or, since version 26.11, because a part of the index cannot be read.
  • The Warnings property returns warnings describing the result, separated by line breaks, for example, a warning about the presence of a stop word in a search query. Since version 26.11, the warnings also tell the errors of the search (see below).
  • The NextChunkSearchToken property returns a chunk search token to search for the next chunk, or null if there are no more chunks. For details on search by chunks, see the Search by chunks page.
  • The StartTime property returns the start time of the search.
  • The EndTime property returns the end time of the search.
  • The SearchDuration property returns the search duration.
  • The GetFoundDocument method returns the found document by index.
  • The GetEnumerator method returns an enumerator that iterates through the collection of the documents found.
Note
In the evaluation mode, only the first 10 found documents can be retrieved: the GetFoundDocument method throws LicenseRestrictionException for a document number of 10 or greater, and since version 26.11 an enumeration of the result, for example by foreach or LINQ, throws this exception after the first 10 documents. The DocumentCount property returns the number of all found documents. See Evaluation limitations and licensing.

Since version 26.11, every search reports its errors by the ErrorOccurred event of the index and in the Warnings property of the result. The Search and SearchNext methods throw an exception only for an argument that is not valid (ArgumentNullException for a query or a chunk search token that is null, ArgumentException for a query that cannot be the root of a query) and for a disposed index (ObjectDisposedException). Before, a search with a query in object form and the SearchNext method threw the exception of a failure of the search. The warnings of the errors start as follows:

  • “Search failed: " - the query cannot be parsed or used, the search options cannot be used together, or the search has failed. The result is empty, and it has no token of the next chunk, so a search by chunks ends.
  • “Query part not searched: " - a part of the query cannot be used, for example a regular expression that is not valid. This part finds nothing, and the other parts of the query are searched.
  • “Segment not searched: " or “Some terms not searched: " - a part of the index cannot be read, because its data is damaged, there is not enough memory or a file cannot be read. The search goes on without this part, and the result is truncated.

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

  • The DocumentInfo property returns the document info object. Its members are described below.
  • The Relevance property returns the relevance of the document in the search result.
  • The OccurrenceCount property returns the number of occurrences found in the document.
  • The FoundFields property returns the found document fields.
  • The Terms property returns the found terms. The value is evaluated each time the property is accessed based on the data for each document field found.
  • The TermSequences property returns the found term sequences.
  • The Attributes property returns the attributes associated with the found document. The attributes are retrieved only if the RetrieveAttributes search option is enabled; otherwise, the property returns an empty array. For details, see the Search options page.
  • 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 indexed document is described by an instance of the DocumentInfo class, which contains the following members:

  • The FilePath property returns the file path for a document indexed from a file, or the document key for a document indexed from a stream or a structure.
  • The FileType property returns the file type of the document.
  • The FormatFamily property returns the format family of the document.
  • The InnerPath property returns the inner path of an item of a container document, for example, an item of a ZIP archive or an attachment of an email message.
  • The InnerPathParts property returns the parts of the inner path of an item of a container document.
  • The DocumentSourceKind property returns the kind of the document source: a file, a stream, a structure, previously extracted data, or a temporary file.
  • The ModificationTime property returns the modification time of the document at the time of indexing; for a document indexed from a file, this is the last write time of the file.
  • The IndexedWithError property returns a value indicating whether an error occurred while indexing the document, for example, if the indexing of the document was interrupted by cancellation. Such a document indexed from a file is indexed again by the next Update operation; a document indexed from a stream, a structure or extracted data has to be added again.
  • The Serialize and Deserialize methods serialize the document info to a byte array and deserialize it from a byte array.

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

  • The FieldName property returns the field name.
  • The OccurrenceCount property returns the number of occurrences found.
  • The Terms property returns the terms found.
  • The TermsOccurrences property returns the occurrences of the found terms.
  • The TermSequences property returns the term sequences found.
  • The TermSequencesOccurrences property returns the occurrences of the found term sequences.
  • The Serialize method serializes the current found document field instance to a byte array.
  • The Deserialize method deserializes an instance of found document field from a byte array.

Since version 26.11, a term that several parts of a query find, for example the same word twice, as in “cat OR cat”, overlapping word patterns, or the synonyms and the fuzzy variants of the words of an OR query, is counted once: in the occurrences of a found document and of its fields, in the occurrences of the search result and in the relevance of the document. Before, the occurrences of such a term were counted once for every part of the query that found it.

Since version 26.10, search uses as many threads as there are processor cores by default. The order of the terms found by fuzzy, wildcard, regular expression, numeric range search and spelling correction does not depend on the number of search threads. For details on the number of search threads, see the Search index settings page.

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

C#

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);
 
// Creating 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);
Console.WriteLine("Truncated: " + result.Truncated);
Console.WriteLine("Warnings: " + result.Warnings);
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: " + field.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]);
            }
        }
    }
}

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.