Package com.day.cq.search.suggest
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
Modifier and TypeMethodDescriptionvoidAdds suggestions for a given term to the index.voidclose()Closes the index and releases all allocated resources with it, e.g.voiddelete()Deletes the entire index.voidExtracts a suggestion index based on the given terms, weighted by their frequencies.String[]Looks up the suggestions for a given term.voidRemoves the term and its suggestions from the index.voidsave()Saves any single changes made to the index.
-
Method Details
-
read
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
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 applysuggestions- an array of suggestions- Throws:
RepositoryException- if an unexpected repository error occurred
-
remove
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
Deletes the entire index.Changes will be persisted automatically.
- Throws:
RepositoryException- if an unexpected repository error occurred
-
save
Saves any single changes made to the index.- Throws:
RepositoryException- if an unexpected repository error occurred
-
close
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
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 ofTerms, with the string term and the frequencymaxSuggestions- the maximum number of suggestion per termminimize- 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
-