Package com.day.cq.search.suggest
Interface SuggestionIndex
-
public interface SuggestionIndexRepresents a term suggestion index, with methods for reading from and writing to the index.To persist single changes made to the index (
add(),remove()), callsave(). The possibly large-scale operationsindex()anddelete()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 voidadd(java.lang.String term, java.lang.String[] suggestions)Adds 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.voidindex(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.voidremove(java.lang.String term)Removes the term and its suggestions from the index.voidsave()Saves any single changes made to the index.
-
-
-
Method Detail
-
read
java.lang.String[] read(java.lang.String term) throws javax.jcr.RepositoryExceptionLooks 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:
javax.jcr.RepositoryException- if an unexpected repository error occurred
-
add
void add(java.lang.String term, java.lang.String[] suggestions) throws javax.jcr.RepositoryExceptionAdds 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:
javax.jcr.RepositoryException- if an unexpected repository error occurred
-
remove
void remove(java.lang.String term) throws javax.jcr.RepositoryExceptionRemoves 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:
javax.jcr.RepositoryException- if an unexpected repository error occurred
-
delete
void delete() throws javax.jcr.RepositoryExceptionDeletes the entire index.Changes will be persisted automatically.
- Throws:
javax.jcr.RepositoryException- if an unexpected repository error occurred
-
save
void save() throws javax.jcr.RepositoryException
Saves any single changes made to the index.- Throws:
javax.jcr.RepositoryException- if an unexpected repository error occurred
-
close
void close() throws javax.jcr.RepositoryExceptionCloses 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:
javax.jcr.RepositoryException- if an unexpected repository error occurred
-
index
void index(java.util.List<Term> terms, int maxSuggestions, boolean minimize) throws javax.jcr.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 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:
javax.jcr.RepositoryException- if an unexpected repository error occurred
-
-