Search in sources :

Example 6 with QueryTree

use of com.yahoo.search.query.QueryTree in project vespa by vespa-engine.

the class QueryCanonicalizerMicroBenchmark method canonicalize.

private void canonicalize() {
    AndItem and = new AndItem();
    and.addItem(new WordItem("shoe", "prod"));
    and.addItem(new WordItem("apparel & accessories", "tcnm"));
    RankItem rank = new RankItem();
    rank.addItem(and);
    for (int i = 0; i < 25; i++) rank.addItem(new WordItem("word" + i, "normbrnd"));
    QueryTree tree = new QueryTree(rank);
    QueryCanonicalizer.canonicalize(tree);
}
Also used : AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) QueryTree(com.yahoo.search.query.QueryTree) WordItem(com.yahoo.prelude.query.WordItem)

Example 7 with QueryTree

use of com.yahoo.search.query.QueryTree in project vespa by vespa-engine.

the class YqlParser method buildTree.

@NonNull
private QueryTree buildTree(OperatorNode<?> filterPart) {
    Preconditions.checkArgument(filterPart.getArguments().length == 2, "Expected 2 arguments to filter, got %s.", filterPart.getArguments().length);
    populateYqlSources(filterPart.<OperatorNode<?>>getArgument(0));
    OperatorNode<ExpressionOperator> filterExpression = filterPart.getArgument(1);
    populateLinguisticsAnnotations(filterExpression);
    Item root = convertExpression(filterExpression);
    connectItems();
    userQuery = null;
    return new QueryTree(root);
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) NullItem(com.yahoo.prelude.query.NullItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) TaggableItem(com.yahoo.prelude.query.TaggableItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) EquivItem(com.yahoo.prelude.query.EquivItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) ONearItem(com.yahoo.prelude.query.ONearItem) DotProductItem(com.yahoo.prelude.query.DotProductItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) IntItem(com.yahoo.prelude.query.IntItem) WandItem(com.yahoo.prelude.query.WandItem) RegExpItem(com.yahoo.prelude.query.RegExpItem) RangeItem(com.yahoo.prelude.query.RangeItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) QueryTree(com.yahoo.search.query.QueryTree) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 8 with QueryTree

use of com.yahoo.search.query.QueryTree in project vespa by vespa-engine.

the class YqlParserTestCase method testRange.

@Test
public void testRange() {
    QueryTree parsed = parse("select foo from bar where range(baz,1,8);");
    assertEquals("baz:[1;8]", parsed.toString());
}
Also used : QueryTree(com.yahoo.search.query.QueryTree) Test(org.junit.Test)

Example 9 with QueryTree

use of com.yahoo.search.query.QueryTree in project vespa by vespa-engine.

the class YqlParserTestCase method testRegexp.

@Test
public void testRegexp() {
    QueryTree x = parse("select * from sources * where foo matches \"a b\";");
    Item root = x.getRoot();
    assertSame(RegExpItem.class, root.getClass());
    assertEquals("a b", ((RegExpItem) root).stringValue());
}
Also used : WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) IndexedItem(com.yahoo.prelude.query.IndexedItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) RegExpItem(com.yahoo.prelude.query.RegExpItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) QueryTree(com.yahoo.search.query.QueryTree) Test(org.junit.Test)

Example 10 with QueryTree

use of com.yahoo.search.query.QueryTree in project vespa by vespa-engine.

the class AllParser method simplifyUnnecessaryComposites.

// Simplify if there are unnecessary composites due to single elements
protected final Item simplifyUnnecessaryComposites(Item item) {
    if (item == null)
        return null;
    QueryTree root = new QueryTree(item);
    QueryCanonicalizer.canonicalize(root);
    return root.getRoot() instanceof NullItem ? null : root.getRoot();
}
Also used : QueryTree(com.yahoo.search.query.QueryTree)

Aggregations

QueryTree (com.yahoo.search.query.QueryTree)26 Test (org.junit.Test)13 AndItem (com.yahoo.prelude.query.AndItem)7 PhraseItem (com.yahoo.prelude.query.PhraseItem)7 WordItem (com.yahoo.prelude.query.WordItem)7 IndexedItem (com.yahoo.prelude.query.IndexedItem)6 Item (com.yahoo.prelude.query.Item)6 WeakAndItem (com.yahoo.prelude.query.WeakAndItem)6 ExactStringItem (com.yahoo.prelude.query.ExactStringItem)5 PrefixItem (com.yahoo.prelude.query.PrefixItem)5 RegExpItem (com.yahoo.prelude.query.RegExpItem)5 SubstringItem (com.yahoo.prelude.query.SubstringItem)5 SuffixItem (com.yahoo.prelude.query.SuffixItem)5 WordAlternativesItem (com.yahoo.prelude.query.WordAlternativesItem)5 Parsable (com.yahoo.search.query.parser.Parsable)3 ParserEnvironment (com.yahoo.search.query.parser.ParserEnvironment)3 IndexFacts (com.yahoo.prelude.IndexFacts)2 IndexModel (com.yahoo.prelude.IndexModel)2 CompositeItem (com.yahoo.prelude.query.CompositeItem)2 RankItem (com.yahoo.prelude.query.RankItem)2