use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.
the class CollapsePhraseSearcherTestCase method testPositive2.
@Test
public void testPositive2() {
AndItem root = new AndItem();
root.addItem(new WordItem("a"));
CompositeItem embedded = new AndItem();
embedded.addItem(new WordItem("bcd"));
CompositeItem phrase = new PhraseItem();
phrase.addItem(new WordItem("def"));
embedded.addItem(phrase);
root.addItem(embedded);
root.addItem(new WordItem("e"));
assertEquals("AND a (AND bcd def) e", transformQuery(root));
}
use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.
the class CollapsePhraseSearcherTestCase method testNegative3.
@Test
public void testNegative3() {
AndItem root = new AndItem();
root.addItem(new WordItem("a"));
CompositeItem embedded = new AndItem();
embedded.addItem(new WordItem("bcd"));
CompositeItem phrase = new PhraseItem();
phrase.addItem(new WordItem("def"));
phrase.addItem(new WordItem("ghi"));
embedded.addItem(phrase);
root.addItem(embedded);
root.addItem(new WordItem("e"));
assertEquals("AND a (AND bcd \"def ghi\") e", transformQuery(root));
}
use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.
the class CollapsePhraseSearcherTestCase method testPositive1.
@Test
public void testPositive1() {
AndItem root = new AndItem();
root.addItem(new WordItem("a"));
PhraseItem embedded = new PhraseItem();
embedded.addItem(new WordItem("bcd"));
root.addItem(embedded);
root.addItem(new WordItem("e"));
assertEquals("AND a bcd e", transformQuery(root));
}
use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.
the class CollapsePhraseSearcherTestCase method testSimplePositive.
@Test
public void testSimplePositive() {
PhraseItem root = new PhraseItem();
root.addItem(new WordItem("abc"));
assertEquals("abc", transformQuery(root));
}
use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.
the class InputCheckingSearcher method repeatedConsecutiveTermsInPhraseCheck.
private void repeatedConsecutiveTermsInPhraseCheck(PhraseItem phrase) {
if (phrase.getItemCount() > MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE) {
String prev = null;
int repeatedCount = 0;
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();
if (prev != null) {
if (prev.equals(current)) {
repeatedCount++;
if (repeatedCount >= MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE) {
repeatedConsecutiveTermsInPhraseRejections.add();
throw new IllegalArgumentException("More than " + MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE + " ocurrences of term '" + current + "' in a row detected in phrase : " + phrase.toString());
}
} else {
repeatedCount = 0;
}
}
prev = current;
} else {
prev = null;
repeatedCount = 0;
}
}
}
}
Aggregations