document StatisticsWeigher.composeStatsWithPrefix

This commit is contained in:
peter
2013-02-12 21:46:20 +01:00
parent 28f5742c71
commit 8a5a167075
@@ -190,15 +190,35 @@ public class StatisticsWeigher extends CompletionWeigher {
return info == null ? StatisticsInfo.EMPTY : info;
}
/**
* For different prefixes we want to prefer different completion items,
* so we decorate their basic stat-infos depending on prefix.
* For example, consider that an item "fooBar" was chosen with a prefix "foo"
* Then we'll register "fooBar" for each of the sub-prefixes: "", "f", "fo" and "foo"
* and suggest "foobar" whenever we a user types any of those prefixes
*
* If a user has typed "fooB" for which there's no stat-info registered, we want to check
* all of its sub-prefixes: "", "f", "fo", "foo" and see if any of them is associated with a stat-info
* But if the item were "fobia" and the user has typed "fob", we don't want to claim
* that "fooBar" (which matches) is statistically better than "fobia" with prefix "fob" even though both begin with "fo"
* So we only check non-partial sub-prefixes, then ones that had been really typed by the user before completing
*
* @param forWriting controls whether this stat-info will be used for incrementing usage count or for its retrieval (for sorting)
*/
public static StatisticsInfo composeStatsWithPrefix(StatisticsInfo info, final String fullPrefix, boolean forWriting) {
ArrayList<StatisticsInfo> infos = new ArrayList<StatisticsInfo>((fullPrefix.length() + 3) * info.getConjuncts().size());
for (StatisticsInfo conjunct : info.getConjuncts()) {
if (forWriting) {
// some completion contributors may need pure statistical information to speed up searching for frequently chosen items
infos.add(conjunct);
}
for (int i = 0; i <= fullPrefix.length(); i++) {
// if we're incrementing usage count, register all sub-prefixes with "partial" mark
// if we're sorting and any sub-prefix was used as non-partial to choose this completion item, prefer it
infos.add(composeWithPrefix(conjunct, fullPrefix.substring(0, i), forWriting));
}
// if we're incrementing usage count, the full prefix is registered as non-partial
// if we're sorting and the current prefix was used as partial sub-prefix to choose this completion item, prefer it
infos.add(composeWithPrefix(conjunct, fullPrefix, !forWriting));
}
return StatisticsInfo.createComposite(infos);