Interface SuggestionIndex


  • public interface SuggestionIndex
    Represents a term suggestion index, with methods for reading from and writing to the index.

    To persist single changes made to the index (add(), remove()), call save(). The possibly large-scale operations index() and delete() will save automatically.

    Note: make sure to close() the index after usage to properly release affected resources, e.g. an underlying JCR session. This should be done in a try/finally block.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void add​(java.lang.String term, java.lang.String[] suggestions)
      Adds suggestions for a given term to the index.
      void close()
      Closes the index and releases all allocated resources with it, e.g.
      void delete()
      Deletes the entire index.
      void index​(java.util.List<Term> terms, int maxSuggestions, boolean minimize)
      Extracts a suggestion index based on the given terms, weighted by their frequencies.
      java.lang.String[] read​(java.lang.String term)
      Looks up the suggestions for a given term.
      void remove​(java.lang.String term)
      Removes the term and its suggestions from the index.
      void save()
      Saves any single changes made to the index.
    • Method Detail

      • read

        java.lang.String[] read​(java.lang.String term)
                         throws RepositoryException
        Looks up the suggestions for a given term.
        Parameters:
        term - partial word to look up in the index; one or more characters
        Returns:
        a list of suggestions or an empty array if no suggestions were found
        Throws:
        RepositoryException - if an unexpected repository error occurred
      • add

        void add​(java.lang.String term,
                 java.lang.String[] suggestions)
          throws RepositoryException
        Adds suggestions for a given term to the index. If the term already exists in the index, the previous suggestions will be overwritten.

        To persist the change, save() must be called.

        Parameters:
        term - partial word for which the suggestions apply
        suggestions - an array of suggestions
        Throws:
        RepositoryException - if an unexpected repository error occurred
      • remove

        void remove​(java.lang.String term)
             throws RepositoryException
        Removes the term and its suggestions from the index.

        To persist the change, save() must be called.

        Parameters:
        term - partial word to remove from the index
        Throws:
        RepositoryException - if an unexpected repository error occurred
      • delete

        void delete()
             throws RepositoryException
        Deletes the entire index.

        Changes will be persisted automatically.

        Throws:
        RepositoryException - if an unexpected repository error occurred
      • close

        void close()
            throws RepositoryException
        Closes the index and releases all allocated resources with it, e.g. the underlying JCR session. After this has been called, all methods will fail if called.
        Throws:
        RepositoryException - if an unexpected repository error occurred
      • index

        void index​(java.util.List<Term> terms,
                   int maxSuggestions,
                   boolean minimize)
            throws RepositoryException
        Extracts a suggestion index based on the given terms, weighted by their frequencies. Will create all partial words starting with one letter, two letters and so on, for which full words exist, and will add up to the given maximum number of suggested terms for each partial word, weighted by the frequency.

        Changes will be persisted automatically.

        Parameters:
        terms - a list of Terms, with the string term and the frequency
        maxSuggestions - the maximum number of suggestion per term
        minimize - Whether the index should be minimized. That means (longer) term prefixes that result in only one suggestion should not be indexed; only the first prefix that will result in this single suggestion would be stored, but not for the remaining letters of the suggested word.
        Throws:
        RepositoryException - if an unexpected repository error occurred