Search in sources :

Example 16 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.

the class ParseTestCase method testPlusesAndMinuses.

@Test
public void testPlusesAndMinuses() {
    Item root = tester.assertParsed("\"a b c d d\"", "a+b+c+d--d", Query.Type.ANY);
    assertTrue(root instanceof PhraseItem);
    assertFalse(((PhraseItem) root).isExplicit());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 17 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.

the class ParseTestCase method testSimpleQueryDefaultPhrase.

@Test
public void testSimpleQueryDefaultPhrase() {
    Item root = tester.assertParsed("\"foobar foo bar baz\"", "foobar foo bar baz", Query.Type.PHRASE);
    assertTrue(root instanceof PhraseItem);
    assertFalse(((PhraseItem) root).isExplicit());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 18 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.

the class LowercasingTestCase method slightlyMoreComplexTree.

@Test
public void slightlyMoreComplexTree() {
    Query q = new Query();
    AndItem a0 = new AndItem();
    OrItem o0 = new OrItem();
    PhraseItem p0 = new PhraseItem();
    p0.setIndexName(BAMSE);
    PhraseSegmentItem p1 = new PhraseSegmentItem("Overbuljongterningpakkmesterassistent", true, false);
    p1.setIndexName(BAMSE);
    WordItem tmp;
    tmp = new WordItem("Nalle0", BAMSE, true);
    a0.addItem(tmp);
    tmp = new WordItem("Nalle1", BAMSE, true);
    o0.addItem(tmp);
    tmp = new WordItem("Nalle2", BAMSE, true);
    o0.addItem(tmp);
    a0.addItem(o0);
    tmp = new WordItem("Nalle3", BAMSE, true);
    p0.addItem(tmp);
    p1.addItem(new WordItem("Over", BAMSE, true));
    p1.addItem(new WordItem("buljong", BAMSE, true));
    p1.addItem(new WordItem("terning", BAMSE, true));
    p1.addItem(new WordItem("pakk", BAMSE, true));
    p1.addItem(new WordItem("Mester", BAMSE, true));
    p1.addItem(new WordItem("assistent", BAMSE, true));
    p1.lock();
    p0.addItem(p1);
    a0.addItem(p0);
    q.getModel().getQueryTree().setRoot(a0);
    Result r = execution.search(q);
    AndItem root = (AndItem) r.getQuery().getModel().getQueryTree().getRoot();
    tmp = (WordItem) root.getItem(0);
    assertEquals("nalle0", tmp.getWord());
    OrItem orElement = (OrItem) root.getItem(1);
    tmp = (WordItem) orElement.getItem(0);
    assertEquals("nalle1", tmp.getWord());
    tmp = (WordItem) orElement.getItem(1);
    assertEquals("nalle2", tmp.getWord());
    PhraseItem phrase = (PhraseItem) root.getItem(2);
    tmp = (WordItem) phrase.getItem(0);
    assertEquals("nalle3", tmp.getWord());
    PhraseSegmentItem locked = (PhraseSegmentItem) phrase.getItem(1);
    assertEquals("over", ((WordItem) locked.getItem(0)).getWord());
    assertEquals("buljong", ((WordItem) locked.getItem(1)).getWord());
    assertEquals("terning", ((WordItem) locked.getItem(2)).getWord());
    assertEquals("pakk", ((WordItem) locked.getItem(3)).getWord());
    assertEquals("mester", ((WordItem) locked.getItem(4)).getWord());
    assertEquals("assistent", ((WordItem) locked.getItem(5)).getWord());
}
Also used : Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 19 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.

the class YqlParser method instantiatePhraseItem.

@NonNull
private Item instantiatePhraseItem(String field, OperatorNode<ExpressionOperator> ast) {
    assertHasFunctionName(ast, PHRASE);
    if (getAnnotation(ast, ORIGIN, Map.class, null, ORIGIN_DESCRIPTION, false) != null) {
        return instantiatePhraseSegmentItem(field, ast, false);
    }
    PhraseItem phrase = new PhraseItem();
    phrase.setIndexName(field);
    for (OperatorNode<ExpressionOperator> word : ast.<List<OperatorNode<ExpressionOperator>>>getArgument(1)) {
        if (word.getOperator() == ExpressionOperator.CALL) {
            List<String> names = word.getArgument(0);
            switch(names.get(0)) {
                case PHRASE:
                    if (getAnnotation(word, ORIGIN, Map.class, null, ORIGIN_DESCRIPTION, false) == null) {
                        phrase.addItem(instantiatePhraseItem(field, word));
                    } else {
                        phrase.addItem(instantiatePhraseSegmentItem(field, word, true));
                    }
                    break;
                case ALTERNATIVES:
                    phrase.addItem(instantiateWordAlternativesItem(field, word));
                    break;
                default:
                    throw new IllegalArgumentException("Expected phrase or word alternatives, got " + names.get(0));
            }
        } else {
            phrase.addItem(instantiateWordItem(field, word, phrase.getClass()));
        }
    }
    return leafStyleSettings(ast, phrase);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) LazyMap(com.yahoo.collections.LazyMap) PhraseItem(com.yahoo.prelude.query.PhraseItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 20 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.

the class CJKSearcher method transform.

private Item transform(Item root) {
    if (root instanceof PhraseItem) {
        PhraseItem asPhrase = (PhraseItem) root;
        if (asPhrase.isExplicit() || hasOverlappingTokens(asPhrase))
            return root;
        AndItem replacement = new AndItem();
        for (ListIterator<Item> i = ((CompositeItem) root).getItemIterator(); i.hasNext(); ) {
            Item item = i.next();
            if (item instanceof WordItem)
                replacement.addItem(item);
            else if (item instanceof PhraseSegmentItem) {
                replacement.addItem(new AndSegmentItem((PhraseSegmentItem) item));
            } else
                // should never run, but hey... just convert and hope it's OK :)
                replacement.addItem(item);
        }
        return replacement;
    } else if (root instanceof PhraseSegmentItem) {
        PhraseSegmentItem asSegment = (PhraseSegmentItem) root;
        if (asSegment.isExplicit() || hasOverlappingTokens(asSegment))
            return root;
        else
            return new AndSegmentItem(asSegment);
    } else if (root instanceof SegmentItem) {
        // avoid descending into AndSegmentItems and similar
        return root;
    } else if (root instanceof CompositeItem) {
        for (ListIterator<Item> i = ((CompositeItem) root).getItemIterator(); i.hasNext(); ) {
            Item item = i.next();
            Item transformedItem = transform(item);
            if (item != transformedItem) {
                i.set(transformedItem);
            }
        }
        return root;
    }
    return root;
}
Also used : AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) AndItem(com.yahoo.prelude.query.AndItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) WordItem(com.yahoo.prelude.query.WordItem) ListIterator(java.util.ListIterator) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem)

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