use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.
the class CollapsePhraseSearcher method simplifyPhrases.
private Item simplifyPhrases(Item root) {
if (root == null) {
return root;
} else if (root instanceof PhraseItem) {
return collapsePhrase((PhraseItem) root);
} else if (root instanceof CompositeItem) {
CompositeItem composite = (CompositeItem) root;
ListIterator<Item> i = composite.getItemIterator();
while (i.hasNext()) {
Item original = i.next();
Item transformed = simplifyPhrases(original);
if (original != transformed)
i.set(transformed);
}
return root;
} else {
return root;
}
}
use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.
the class PhraseParser method forcedPhrase.
/**
* Ignores everything but words and numbers
*
* @return a phrase item if several words/numbers was found,
* a word item if only one was found
*/
private Item forcedPhrase() {
Item firstWord = null;
PhraseItem phrase = null;
while (tokens.hasNext()) {
Token token = tokens.next();
if (token.kind != Token.Kind.WORD && token.kind != Token.Kind.NUMBER) {
continue;
}
// Note, this depends on segment never creating AndItems when quoted
// (the second argument) is true.
Item newWord = segment(token);
if (firstWord == null) {
// First pass
firstWord = newWord;
} else if (phrase == null) {
// Second pass
phrase = new PhraseItem();
phrase.addItem(firstWord);
phrase.addItem(newWord);
} else {
// Following passes
phrase.addItem(newWord);
}
}
if (phrase != null) {
return phrase;
} else {
return firstWord;
}
}
use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.
the class WashPhrasesTestCase 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 WashPhrasesTestCase 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 WashPhrasesTestCase 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));
}
Aggregations