Search in sources :

Example 6 with Parsable

use of com.yahoo.search.query.parser.Parsable 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 7 with Parsable

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

the class WashPhrasesTestCase method transformQuery.

private String transformQuery(String rawQuery) {
    Parser parser = ParserFactory.newInstance(Query.Type.ALL, new ParserEnvironment());
    Item root = parser.parse(new Parsable().setQuery(rawQuery)).getRoot();
    if (root instanceof NullItem) {
        return null;
    }
    return root.toString();
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Parsable(com.yahoo.search.query.parser.Parsable) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment) NullItem(com.yahoo.prelude.query.NullItem) Parser(com.yahoo.search.query.parser.Parser) AbstractParser(com.yahoo.prelude.query.parser.AbstractParser)

Example 8 with Parsable

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

the class CJKSearcherTestCase method assertTransformed.

private void assertTransformed(String queryString, String expected, Query.Type mode, Language actualLanguage, Language queryLanguage, Linguistics linguistics) {
    Parser parser = ParserFactory.newInstance(mode, new ParserEnvironment().setIndexFacts(indexFacts).setLinguistics(linguistics));
    Item root = parser.parse(new Parsable().setQuery(queryString).setLanguage(actualLanguage)).getRoot();
    assertFalse(root instanceof NullItem);
    Query query = new Query("?language=" + queryLanguage.languageCode());
    query.getModel().getQueryTree().setRoot(root);
    new Execution(new Chain<Searcher>(new CJKSearcher()), new Execution.Context(null, indexFacts, null, null, linguistics)).search(query);
    assertEquals(expected, query.getModel().getQueryTree().getRoot().toString());
}
Also used : NullItem(com.yahoo.prelude.query.NullItem) Item(com.yahoo.prelude.query.Item) Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Parsable(com.yahoo.search.query.parser.Parsable) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment) CJKSearcher(com.yahoo.prelude.querytransform.CJKSearcher) NullItem(com.yahoo.prelude.query.NullItem) Parser(com.yahoo.search.query.parser.Parser)

Example 9 with Parsable

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

the class ParsingTester method parseQuery.

public Item parseQuery(String query, String filter, Language language, Query.Type type, Linguistics linguistics) {
    Parser parser = ParserFactory.newInstance(type, new ParserEnvironment().setIndexFacts(indexFacts).setLinguistics(linguistics).setSpecialTokens(tokenRegistry.getSpecialTokens("default")));
    Item root = parser.parse(new Parsable().setQuery(query).setFilter(filter).setLanguage(language)).getRoot();
    if (root instanceof NullItem) {
        return null;
    }
    return root;
}
Also used : NullItem(com.yahoo.prelude.query.NullItem) Item(com.yahoo.prelude.query.Item) Parsable(com.yahoo.search.query.parser.Parsable) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment) NullItem(com.yahoo.prelude.query.NullItem) Parser(com.yahoo.search.query.parser.Parser)

Aggregations

Parsable (com.yahoo.search.query.parser.Parsable)9 ParserEnvironment (com.yahoo.search.query.parser.ParserEnvironment)7 Parser (com.yahoo.search.query.parser.Parser)5 Item (com.yahoo.prelude.query.Item)4 NullItem (com.yahoo.prelude.query.NullItem)4 IndexFacts (com.yahoo.prelude.IndexFacts)3 Query (com.yahoo.search.Query)3 QueryTree (com.yahoo.search.query.QueryTree)3 IndexModel (com.yahoo.prelude.IndexModel)2 AndItem (com.yahoo.prelude.query.AndItem)2 CompositeItem (com.yahoo.prelude.query.CompositeItem)2 PhraseItem (com.yahoo.prelude.query.PhraseItem)2 WordItem (com.yahoo.prelude.query.WordItem)2 Execution (com.yahoo.search.searchchain.Execution)2 Chain (com.yahoo.component.chain.Chain)1 SimpleLinguistics (com.yahoo.language.simple.SimpleLinguistics)1 Index (com.yahoo.prelude.Index)1 SearchDefinition (com.yahoo.prelude.SearchDefinition)1 AndSegmentItem (com.yahoo.prelude.query.AndSegmentItem)1 DotProductItem (com.yahoo.prelude.query.DotProductItem)1