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 due to limits specified in the search options.
The Warnings property returns warnings describing the result, for example, a warning about the presence of a stop word in a search query.
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.
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 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.10, search uses as many threads as there are processor cores by default. Therefore, the order of the terms found by fuzzy, wildcard, regular expression, numeric range search and spelling correction may differ from run to run. To get the same order every time, set the SearchThreads index setting to NumberOfThreads.One. For details, see the Search index settings page.
The following example shows how to print information on the documents found in the console.
C#
stringindexFolder=@"c:\MyIndex\";stringdocumentFolder=@"c:\MyDocuments\";// Creating an indexIndexindex=newIndex(indexFolder);// Indexing documents from the specified folderindex.Add(documentFolder);// Creating search optionsSearchOptionsoptions=newSearchOptions();options.FuzzySearch.Enabled=true;// Enabling the fuzzy searchoptions.FuzzySearch.FuzzyAlgorithm=newTableDiscreteFunction(3);// Setting the maximum number of differences to 3// Search for documents containing the word 'Einstein' or the phrase 'Theory of Relativity'SearchResultresult=index.Search("Einstein OR \"Theory of Relativity\"",options);// Printing the resultConsole.WriteLine("Documents: "+result.DocumentCount);Console.WriteLine("Total occurrences: "+result.OccurrenceCount);for(inti=0;i<result.DocumentCount;i++){FoundDocumentdocument=result.GetFoundDocument(i);Console.WriteLine("\tDocument: "+document.DocumentInfo.FilePath);Console.WriteLine("\tOccurrences: "+document.OccurrenceCount);for(intj=0;j<document.FoundFields.Length;j++){FoundDocumentFieldfield=document.FoundFields[j];Console.WriteLine("\t\tField: "+field.FieldName);Console.WriteLine("\t\tOccurrences: "+field.OccurrenceCount);// Printing found termsif(field.Terms!=null){for(intk=0;k<field.Terms.Length;k++){Console.WriteLine("\t\t\t"+field.Terms[k].PadRight(20)+field.TermsOccurrences[k]);}}// Printing found phrasesif(field.TermSequences!=null){for(intk=0;k<field.TermSequences.Length;k++){stringsequence=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: