Interface Suggester


  • public interface Suggester
    A service interface for retrieving search suggestions and spell checking. Uses a pre-built index to look up the suggestions. The spell check is done by leveraging the JCR full text search index.

    The index can be created in various ways: by analysing most frequently used terms in the full text index (see SearchIndexSuggestionExtractor), by tracking actual search statistics (see QueryTracker, requires configuration to synchronize with multiple publish instances) or by a custom index creator (use SuggestionIndexManager to create indexes).

    Given that the indexes won't change very often, they should be created in the background, and they can be distributed to publish instances via content packages.

    • Method Detail

      • getSuggestions

        java.lang.String[] getSuggestions​(Session session,
                                          java.lang.String indexName,
                                          java.lang.String term,
                                          boolean spellCheck)
        Returns suggestions for a given term, which can be any partial word of at least one character. Depending on the given context path, different suggestion indexes can be addressed.
        Parameters:
        session - user session to access index
        indexName - a path or name for the suggestion index
        term - partial word to look up suggestions for
        spellCheck - if true, the term will be spell checked if nothing was found and the suggestion look up will be retried with the spell check result
        Returns:
        a list of search suggestions or an empty array if none could be found
      • spellCheck

        java.lang.String spellCheck​(Session session,
                                    java.lang.String term)
        Uses the JCR search index to run a spellcheck for the given word. Uses the custom rep:spellcheck() Xpath function. Will return a single spell checked term or null if the term is already correctly spelled or if no match was found.
        Parameters:
        session - user session to run spellcheck on repository index(es)
        term - the term to spell check
        Returns:
        a correctly spelled term or null
      • getSuggestions

        @Deprecated
        java.lang.String[] getSuggestions​(java.lang.String indexName,
                                          java.lang.String term,
                                          boolean spellCheck)
        Deprecated.
        use the variant with a user session argument: getSuggestions(Session, String, String, boolean)
        Returns suggestions for a given term, which can be any partial word of at least one character. Depending on the given context path, different suggestion indexes can be addressed.
        Parameters:
        indexName - a path or name for the suggestion index
        term - partial word to look up suggestions for
        spellCheck - if true, the term will be spell checked if nothing was found and the suggestion look up will be retried with the spell check result
        Returns:
        a list of search suggestions or an empty array if none could be found
      • spellCheck

        @Deprecated
        java.lang.String spellCheck​(java.lang.String term)
        Deprecated.
        use the variant with a user session argument: spellCheck(Session, String)
        Uses the JCR search index to run a spellcheck for the given word. Uses the custom rep:spellcheck() Xpath function. Will return a single spell checked term or null if the term is already correctly spelled or if no match was found.
        Parameters:
        term - the term to spell check
        Returns:
        a correctly spelled term or null