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 a warnings describing the result, for example, a warning about the presence of stop word in a search query.
The NextChunkSearchToken property returns a chunk search token to search for the next chunk. 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 containing the file path, the file type, the format family, and the inner document path for items of container documents.
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 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 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.
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: "+document.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: