use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.
the class ParseTestCase method testExplicitPhrase.
@Test
public void testExplicitPhrase() {
Item root = tester.assertParsed("\"foo bar foobar\"", "\"foo bar foobar\"", Query.Type.ANY);
assertTrue(root instanceof PhraseItem);
assertTrue(((PhraseItem) root).isExplicit());
}
use of com.yahoo.prelude.query.PhraseItem 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));
}
}
}
}
}
use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.
the class InputCheckingSearcher method checkPhrases.
private void checkPhrases(Item queryItem) {
if (queryItem instanceof PhraseItem) {
PhraseItem phrase = (PhraseItem) queryItem;
repeatedConsecutiveTermsInPhraseCheck(phrase);
repeatedTermsInPhraseCheck(phrase);
} else if (queryItem instanceof CompositeItem) {
CompositeItem asComposite = (CompositeItem) queryItem;
for (ListIterator<Item> i = asComposite.getItemIterator(); i.hasNext(); ) {
checkPhrases(i.next());
}
}
}
Aggregations