Search in sources :

Example 21 with QueryTree

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

the class YqlParserTestCase method testFieldAliases.

@Test
public void testFieldAliases() {
    IndexInfoConfig modelConfig = new IndexInfoConfig(new IndexInfoConfig.Builder().indexinfo(new Indexinfo.Builder().name("music").command(new Command.Builder().indexname("title").command("index")).alias(new Alias.Builder().alias("song").indexname("title"))));
    IndexModel model = new IndexModel(modelConfig, (QrSearchersConfig) null);
    IndexFacts indexFacts = new IndexFacts(model);
    ParserEnvironment parserEnvironment = new ParserEnvironment().setIndexFacts(indexFacts);
    YqlParser configuredParser = new YqlParser(parserEnvironment);
    QueryTree x = configuredParser.parse(new Parsable().setQuery("select * from sources * where title contains \"a\" and song contains \"b\";"));
    List<IndexedItem> terms = QueryTree.getPositiveTerms(x);
    assertEquals(2, terms.size());
    for (IndexedItem term : terms) {
        assertEquals("title", term.getIndexName());
    }
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) IndexedItem(com.yahoo.prelude.query.IndexedItem) Parsable(com.yahoo.search.query.parser.Parsable) IndexModel(com.yahoo.prelude.IndexModel) Alias(com.yahoo.search.config.IndexInfoConfig.Indexinfo.Alias) Indexinfo(com.yahoo.search.config.IndexInfoConfig.Indexinfo) QueryTree(com.yahoo.search.query.QueryTree) IndexInfoConfig(com.yahoo.search.config.IndexInfoConfig) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment) Test(org.junit.Test)

Example 22 with QueryTree

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

the class YqlParserTestCase method testWordAlternatives.

@Test
public void testWordAlternatives() {
    QueryTree x = parse("select * from sources * where foo contains alternatives({\"trees\": 1.0, \"tree\": 0.7});");
    Item root = x.getRoot();
    assertSame(WordAlternativesItem.class, root.getClass());
    WordAlternativesItem alternatives = (WordAlternativesItem) root;
    checkWordAlternativesContent(alternatives);
}
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) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) Test(org.junit.Test)

Example 23 with QueryTree

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

the class YqlParserTestCase method testNegativeRange.

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

Example 24 with QueryTree

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

the class YqlParserTestCase method testWordAlternativesWithOrigin.

@Test
public void testWordAlternativesWithOrigin() {
    QueryTree x = parse("select * from sources * where foo contains" + " ([{\"origin\": {\"original\": \" trees \", \"offset\": 1, \"length\": 5}}]" + "alternatives({\"trees\": 1.0, \"tree\": 0.7}));");
    Item root = x.getRoot();
    assertSame(WordAlternativesItem.class, root.getClass());
    WordAlternativesItem alternatives = (WordAlternativesItem) root;
    checkWordAlternativesContent(alternatives);
    Substring origin = alternatives.getOrigin();
    assertEquals(1, origin.start);
    assertEquals(6, origin.end);
    assertEquals("trees", origin.getValue());
    assertEquals(" trees ", origin.getSuperstring());
}
Also used : Substring(com.yahoo.prelude.query.Substring) 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) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) Test(org.junit.Test)

Example 25 with QueryTree

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

the class QueryCanonicalizerTestCase method testRankDuplicateCheapification.

@Test
public void testRankDuplicateCheapification() {
    AndItem and = new AndItem();
    WordItem shoe = new WordItem("shoe", "prod");
    and.addItem(shoe);
    and.addItem(new WordItem("apparel & accessories", "tcnm"));
    RankItem rank = new RankItem();
    rank.addItem(and);
    // rank item which also ossurs in first argument
    rank.addItem(new WordItem("shoe", "prod"));
    for (int i = 0; i < 25; i++) rank.addItem(new WordItem("word" + i, "normbrnd"));
    QueryTree tree = new QueryTree(rank);
    assertTrue(shoe.isRanked());
    assertTrue(shoe.usePositionData());
    QueryCanonicalizer.canonicalize(tree);
    assertFalse(shoe.isRanked());
    assertFalse(shoe.usePositionData());
}
Also used : QueryTree(com.yahoo.search.query.QueryTree) Test(org.junit.Test)

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