Search in sources :

Example 1 with PhraseItem

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

Example 2 with PhraseItem

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;
    }
}
Also used : PhraseItem(com.yahoo.prelude.query.PhraseItem) Item(com.yahoo.prelude.query.Item) PhraseItem(com.yahoo.prelude.query.PhraseItem)

Example 3 with PhraseItem

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));
}
Also used : AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 4 with PhraseItem

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));
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 5 with PhraseItem

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));
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Aggregations

PhraseItem (com.yahoo.prelude.query.PhraseItem)33 WordItem (com.yahoo.prelude.query.WordItem)24 Test (org.junit.Test)23 CompositeItem (com.yahoo.prelude.query.CompositeItem)14 AndItem (com.yahoo.prelude.query.AndItem)13 Item (com.yahoo.prelude.query.Item)10 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)9 OrItem (com.yahoo.prelude.query.OrItem)5 PrefixItem (com.yahoo.prelude.query.PrefixItem)4 SubstringItem (com.yahoo.prelude.query.SubstringItem)4 SuffixItem (com.yahoo.prelude.query.SuffixItem)4 Query (com.yahoo.search.Query)4 IntItem (com.yahoo.prelude.query.IntItem)3 NotItem (com.yahoo.prelude.query.NotItem)3 RankItem (com.yahoo.prelude.query.RankItem)3 TermItem (com.yahoo.prelude.query.TermItem)2 PhrasingSearcher (com.yahoo.prelude.querytransform.PhrasingSearcher)2 Searcher (com.yahoo.search.Searcher)2 QueryTree (com.yahoo.search.query.QueryTree)2 Execution (com.yahoo.search.searchchain.Execution)2