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());
}
}
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);
}
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());
}
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());
}
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());
}
Aggregations