Search in sources :

Example 1 with IndexedItem

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

the class QueryTestCase method testPositiveTerms.

@Test
public void testPositiveTerms() {
    Query q = new Query(httpEncode("/?query=-a \"b c\" d e"));
    Item i = q.getModel().getQueryTree().getRoot();
    List<IndexedItem> l = QueryTree.getPositiveTerms(i);
    assertEquals(3, l.size());
}
Also used : OrItem(com.yahoo.prelude.query.OrItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) IndexedItem(com.yahoo.prelude.query.IndexedItem) Item(com.yahoo.prelude.query.Item) WordItem(com.yahoo.prelude.query.WordItem) Query(com.yahoo.search.Query) IndexedItem(com.yahoo.prelude.query.IndexedItem) Test(org.junit.Test)

Example 2 with IndexedItem

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

the class YqlParserTestCase method testMoreInheritedAnnotations.

@Test
public void testMoreInheritedAnnotations() {
    final String yqlQuery = "select * from sources * where " + "([{\"ranked\": false}](foo contains \"a\" " + "and ([{\"ranked\": true}](bar contains \"b\" " + "or ([{\"ranked\": false}](foo contains \"c\" " + "and foo contains ([{\"ranked\": true}]\"d\")))))));";
    QueryTree x = parse(yqlQuery);
    List<IndexedItem> terms = QueryTree.getPositiveTerms(x);
    assertEquals(4, terms.size());
    for (IndexedItem term : terms) {
        switch(term.getIndexedString()) {
            case "a":
            case "c":
                assertFalse(((Item) term).isRanked());
                break;
            case "b":
            case "d":
                assertTrue(((Item) term).isRanked());
                break;
            default:
                fail();
        }
    }
}
Also used : IndexedItem(com.yahoo.prelude.query.IndexedItem) QueryTree(com.yahoo.search.query.QueryTree) Test(org.junit.Test)

Example 3 with IndexedItem

use of com.yahoo.prelude.query.IndexedItem 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)

Aggregations

IndexedItem (com.yahoo.prelude.query.IndexedItem)3 Test (org.junit.Test)3 QueryTree (com.yahoo.search.query.QueryTree)2 IndexFacts (com.yahoo.prelude.IndexFacts)1 IndexModel (com.yahoo.prelude.IndexModel)1 AndItem (com.yahoo.prelude.query.AndItem)1 Item (com.yahoo.prelude.query.Item)1 OrItem (com.yahoo.prelude.query.OrItem)1 RankItem (com.yahoo.prelude.query.RankItem)1 WordItem (com.yahoo.prelude.query.WordItem)1 Query (com.yahoo.search.Query)1 IndexInfoConfig (com.yahoo.search.config.IndexInfoConfig)1 Indexinfo (com.yahoo.search.config.IndexInfoConfig.Indexinfo)1 Alias (com.yahoo.search.config.IndexInfoConfig.Indexinfo.Alias)1 Parsable (com.yahoo.search.query.parser.Parsable)1 ParserEnvironment (com.yahoo.search.query.parser.ParserEnvironment)1