Search in sources :

Example 6 with TermItem

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));
                }
            }
        }
    }
}
Also used : TermItem(com.yahoo.prelude.query.TermItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Item(com.yahoo.prelude.query.Item) WordItem(com.yahoo.prelude.query.WordItem) HashMap(java.util.HashMap) TermItem(com.yahoo.prelude.query.TermItem)

Aggregations

TermItem (com.yahoo.prelude.query.TermItem)6 CompositeItem (com.yahoo.prelude.query.CompositeItem)3 WordItem (com.yahoo.prelude.query.WordItem)3 Item (com.yahoo.prelude.query.Item)2 PhraseItem (com.yahoo.prelude.query.PhraseItem)2 Index (com.yahoo.prelude.Index)1 NotItem (com.yahoo.prelude.query.NotItem)1 FlattenedItem (com.yahoo.prelude.semantics.engine.FlattenedItem)1 DispatchForm (com.yahoo.search.query.textserialize.serializer.DispatchForm)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1