Search in sources :

Example 6 with ParserEnvironment

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

the class ResegmentingTestCase method setUp.

@Before
public void setUp() throws Exception {
    ParserEnvironment env = new ParserEnvironment();
    parser = new YqlParser(env);
}
Also used : ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment) Before(org.junit.Before)

Example 7 with ParserEnvironment

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

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

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

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

ParserEnvironment (com.yahoo.search.query.parser.ParserEnvironment)10 Parsable (com.yahoo.search.query.parser.Parsable)7 Parser (com.yahoo.search.query.parser.Parser)4 IndexFacts (com.yahoo.prelude.IndexFacts)3 Item (com.yahoo.prelude.query.Item)3 NullItem (com.yahoo.prelude.query.NullItem)3 QueryTree (com.yahoo.search.query.QueryTree)3 IndexModel (com.yahoo.prelude.IndexModel)2 Query (com.yahoo.search.Query)2 Execution (com.yahoo.search.searchchain.Execution)2 YqlParser (com.yahoo.search.yql.YqlParser)2 Before (org.junit.Before)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 AndItem (com.yahoo.prelude.query.AndItem)1 CompositeItem (com.yahoo.prelude.query.CompositeItem)1 IndexedItem (com.yahoo.prelude.query.IndexedItem)1 PhraseItem (com.yahoo.prelude.query.PhraseItem)1