use of com.yahoo.prelude.query.TermItem in project vespa by vespa-engine.
the class InputCheckingSearcher method repeatedTermsInPhraseCheck.
private void repeatedTermsInPhraseCheck(PhraseItem phrase) {
if (phrase.getItemCount() > MAX_REPEATED_TERMS_IN_PHRASE) {
Map<String, Count> repeatedCount = new HashMap<>();
for (int i = 0; i < phrase.getItemCount(); ++i) {
Item item = phrase.getItem(i);
if (item instanceof TermItem) {
TermItem term = (TermItem) item;
String current = term.getIndexedString();
Count count = repeatedCount.get(current);
if (count != null) {
if (count.get() >= MAX_REPEATED_TERMS_IN_PHRASE) {
repeatedTermsInPhraseRejections.add();
throw new IllegalArgumentException("Phrase contains more than " + MAX_REPEATED_TERMS_IN_PHRASE + " occurrences of term '" + current + "' in phrase : " + phrase.toString());
}
count.inc();
} else {
repeatedCount.put(current, new Count(1));
}
}
}
}
}
Aggregations