Highlighted Results of Exact Phrase Search in Text – GroupDocs.Search for .NET 17.12

GroupDocs.Search for .NET We are pleased to announce the release of version 17.12 of GroupDocs.Search for .NET. GroupDocs.Search for .NET 17.12 has come with 4 enhancements. We have introduced the feature of getting highlighted results of exact phrase search in text. Furthermore, we have improved the calculation of relevance of search results as well as redesigned the syntax of the search query. We would recommend you to enhance your applications using this latest version.

.NET Search API – Enhancements

GroupDocs.Search for .NET includes following enhancements in version 17.12.

Highlighted results of exact phrase search in text

In this enhancement, generating HTML-formatted text with highlighted found terms is implemented for the results of exact phrase search. Following code snippet demonstrates this feature.
string indexFolder = @"c:\MyIndex" ;
string documentsFolder = @"c:\MyDocuments" ;

// Creating index
Index index = new Index(indexFolder);

// Indexing documents
index.AddToIndex(documentsFolder);

// Searching for phrase 'cumulative distribution function'
SearchResults results = index.Search("\"cumulative distribution function\"");

// Generating HTML-formatted text for the first document directly to the file 'HighlightedResults.html'
index.HighlightInText("HighlightedResults.html", results[0]);

Improved calculation of relevance of search results

In this enhancement, the way of calculating the relevance of search results has been changed. Now the following formula is used to calculate the relevance of each found document: R = O / T, where R is relevance; O is occurrence count in the document; T is total word count in document. Following code sample demonstrates its usage.
// Implementing comparer
public class Comparer : IComparer
{
    public int Compare(DocumentResultInfo x, DocumentResultInfo y)
    {
        // Compare y and x in reverse order
        return y.Relevance.CompareTo(x.Relevance);
    }
}
 
...
 
string indexFolder = @"c:\MyIndex";
string documentsFolder = @"c:\MyDocuments";
 
// Creating index
Index index = new Index(indexFolder);
 
// Indexing
index.AddToIndex(documentsFolder);
 
// Creating search parameters object
SearchParameters searchParameters = new SearchParameters();
// Enabling fuzzy search
searchParameters.FuzzySearch.Enabled = true;
// Setting maximum mistake count to 1
searchParameters.FuzzySearch.FuzzyAlgorithm = new TableDiscreteFunction(1);
 
// Searching for term 'database'
// Using fuzzy search allows to find the plural form of the term 'databases'
SearchResults searchResults = index.Search("database", searchParameters);
 
// Creating and filling array for sorting
DocumentResultInfo[] array = new DocumentResultInfo[searchResults.Count];
for (int i = 0; i < array.Length; i++)
{
    array[i] = searchResults[i];
}
 
// Sorting results in array by relevance in descending order
Array.Sort(array, new Comparer());

Improved representation of results of exact phrase search

This enhancement is implemented to store the results of exact phrase search in a more structured and convenient form. Following code sample shows the usage of this feature.
string indexFolder = @"c:\MyIndex";
string documentsFolder = @"c:\MyDocuments";
 
// Creating index
Index index = new Index(indexFolder);
 
// Indexing
index.AddToIndex(documentsFolder);
 
// Creating search parameters object
SearchParameters searchParameters = new SearchParameters();
// Enabling fuzzy search
searchParameters.FuzzySearch.Enabled = true;
// Setting maximum mistake count to 1
searchParameters.FuzzySearch.FuzzyAlgorithm = new TableDiscreteFunction(1);
 
// Searching for phrase 'cumulative distribution function' or phrase 'cumulative density function'
SearchResults searchResults = index.Search("\"cumulative distribution function\" OR \"cumulative density function\"", searchParameters);
 
// Displaying results
foreach (DocumentResultInfo document in searchResults)
{
    Console.WriteLine(document.FileName);
    foreach (DetailedResultInfo field in document.DetailedResults)
    {
        Console.WriteLine(field.FieldName);
        foreach (string[] phrase in field.TermSequences)
        {
            Console.Write("\t");
            foreach (string word in phrase)
            {
                Console.Write(word + " ");
            }
            Console.WriteLine();
        }
    }
}
 
// The results may contain the following phrases:
// cumulative distribution function
// cumulative distribution functions
// cumulative density function
// cumulative density functions

Improved search query syntax

The syntax of the search query language has been redesigned to make it more understandable and conventional. For details, please visit this documentation article.

Available Channels and Resources

Here are a few channels and resources for you to download, try, learn and get technical support on GroupDocs.Search:

Feedback

If you have any suggestions, questions, or queries related to the .NET Search API, we will be happy to hear from you. Just create a forum thread to share your thoughts.