com.groupdocs.search.options

Class SimilarityLevel



  • public class SimilarityLevel
    extends FuzzyAlgorithm
    Represents an algorithm of the fuzzy search that specifies the similarity level. The similarity level algorithm calculates the maximum number of mistakes for a word as inversely proportional to the word length.

    Learn more

    The example demonstrates a typical usage of the class.

     
     String indexFolder = "c:\\MyIndex\\";
     String documentsFolder = "c:\\MyDocuments\\";
     String query = "Einstein";
     Index index = new Index(indexFolder); // Creating an index in the specified folder
     index.add(documentsFolder); // Indexing documents from the specified folder
     SearchOptions options = new SearchOptions();
     options.getFuzzySearch().setEnabled(true); // Enabling the fuzzy search
     options.getFuzzySearch().setFuzzyAlgorithm(new SimilarityLevel(0.8)); // Creating the fuzzy search algorithm
     // This function specifies 0 as the maximum number of mistakes for words from 1 to 4 characters.
     // It specifies 1 as the maximum number of mistakes for words from 5 to 9 characters.
     // It specifies 2 as the maximum number of mistakes for words from 10 to 14 characters. And so on.
     SearchResult result = index.search(query, options); // Search in index
     
     
    • Constructor Detail

      • SimilarityLevel

        public SimilarityLevel(double value)
        Initializes a new instance of the SimilarityLevel class.
        Parameters:
        value - The similarity level value.
    • Method Detail

      • getSimilarityLevel

        public double getSimilarityLevel(int termLength)
        Gets the similarity level value for the specified term length.
        Specified by:
        getSimilarityLevel in class FuzzyAlgorithm
        Parameters:
        termLength - The term length.
        Returns:
        The similarity level value.
      • getMaxMistakeCount

        public int getMaxMistakeCount(int termLength)
        Gets the maximum allowed number of mistakes for the specified term length.
        Specified by:
        getMaxMistakeCount in class FuzzyAlgorithm
        Parameters:
        termLength - The term length.
        Returns:
        The maximum allowed number of mistakes.
      • getByteCount

        protected static int getByteCount(SimilarityLevel algorithm)