Search in sources :

Example 96 with Item

use of com.yahoo.prelude.query.Item 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 97 with Item

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

the class QueryTestCase method testQueryEquality.

/**
 * Tests that query hash and equality is value dependent only
 */
@Test
public void testQueryEquality() {
    String query = "RANK (+(AND \"baz gaz faz\" bazar) -\"foo bar foobar\") foofoo xyzzy";
    String filter = "foofoo -\"foo bar foobar\" xyzzy +\"baz gaz faz\" +bazar";
    Item root1 = parseQuery(query, filter, Query.Type.ANY);
    Item root2 = parseQuery(query, filter, Query.Type.ANY);
    assertEquals(root1.hashCode(), root2.hashCode());
    assertEquals(root1, root2);
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Item(com.yahoo.prelude.query.Item) Test(org.junit.Test)

Example 98 with Item

use of com.yahoo.prelude.query.Item 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 99 with Item

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

the class ParseTestCase method testRangeParsing.

@Test
public void testRangeParsing() {
    Item root = tester.parseQuery("normal:[5;400]", null, Language.UNKNOWN, Query.Type.ANY, TestLinguistics.INSTANCE);
    assertEquals(root.toString(), "normal:[5;400]");
    assertEquals(root.getCode(), 5);
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) Test(org.junit.Test)

Example 100 with Item

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

the class ParseTestCase method testSubstringExtraSpace2.

@Test
public void testSubstringExtraSpace2() {
    Item root = tester.assertParsed("*substring", "* substring *", Query.Type.ANY);
    assertTrue(root instanceof SuffixItem);
}
Also used : SuffixItem(com.yahoo.prelude.query.SuffixItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) Test(org.junit.Test)

Aggregations

Item (com.yahoo.prelude.query.Item)116 AndItem (com.yahoo.prelude.query.AndItem)85 CompositeItem (com.yahoo.prelude.query.CompositeItem)82 WordItem (com.yahoo.prelude.query.WordItem)73 PhraseItem (com.yahoo.prelude.query.PhraseItem)66 NotItem (com.yahoo.prelude.query.NotItem)62 RankItem (com.yahoo.prelude.query.RankItem)60 SubstringItem (com.yahoo.prelude.query.SubstringItem)60 Test (org.junit.Test)58 OrItem (com.yahoo.prelude.query.OrItem)57 PrefixItem (com.yahoo.prelude.query.PrefixItem)53 SuffixItem (com.yahoo.prelude.query.SuffixItem)53 IntItem (com.yahoo.prelude.query.IntItem)52 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)51 NullItem (com.yahoo.prelude.query.NullItem)24 Query (com.yahoo.search.Query)22 EquivItem (com.yahoo.prelude.query.EquivItem)14 NearItem (com.yahoo.prelude.query.NearItem)14 ExactStringItem (com.yahoo.prelude.query.ExactStringItem)12 IndexedItem (com.yahoo.prelude.query.IndexedItem)12