Search in sources :

Example 56 with Item

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

the class RewriterFeaturesTestCase method testConvertStringToQTree.

@Test
public final void testConvertStringToQTree() {
    Execution placeholder = new Execution(Context.createContextStub());
    SpecialTokenRegistry tokenRegistry = new SpecialTokenRegistry(new SpecialtokensConfig(new SpecialtokensConfig.Builder().tokenlist(new Tokenlist.Builder().name("default").tokens(new Tokens.Builder().token(ASCII_ELLIPSIS)))));
    placeholder.context().setTokenRegistry(tokenRegistry);
    Query query = new Query();
    query.getModel().setExecution(placeholder);
    Item parsed = RewriterFeatures.convertStringToQTree(query, "a b c " + ASCII_ELLIPSIS);
    assertSame(AndItem.class, parsed.getClass());
    assertEquals(4, ((CompositeItem) parsed).getItemCount());
    assertEquals(ASCII_ELLIPSIS, ((CompositeItem) parsed).getItem(3).toString());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) Execution(com.yahoo.search.searchchain.Execution) SpecialTokenRegistry(com.yahoo.prelude.query.parser.SpecialTokenRegistry) Query(com.yahoo.search.Query) SpecialtokensConfig(com.yahoo.vespa.configdefinition.SpecialtokensConfig) Tokenlist(com.yahoo.vespa.configdefinition.SpecialtokensConfig.Tokenlist) Tokens(com.yahoo.vespa.configdefinition.SpecialtokensConfig.Tokenlist.Tokens) Test(org.junit.Test)

Example 57 with Item

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

the class NGramSearcherTestCase method assertGramsWithSegmentationMixedAndPhrases.

public void assertGramsWithSegmentationMixedAndPhrases(Chain<Searcher> chain) {
    // "first" "second" and "third" are segments in the "test" language
    Item item = parseQuery("a gram14:\"afirstsecondthird b hi\"", Query.Type.ALL);
    Query q = new Query("?query=ignored");
    q.getModel().setLanguage(Language.UNKNOWN);
    q.getModel().getQueryTree().setRoot(item);
    new Execution(chain, createContextStub(indexFacts)).search(q);
    assertEquals("AND a gram14:\"afirstsecondth firstsecondthi irstsecondthir rstsecondthird b hi\"", q.getModel().getQueryTree().toString());
}
Also used : Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query)

Example 58 with Item

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

the class NGramSearcherTestCase method assertGramsWithSegmentationSingleSegment.

public void assertGramsWithSegmentationSingleSegment(Chain<Searcher> chain) {
    // "first" "second" and "third" are segments in the "test" language
    Item item = parseQuery("gram14:first", Query.Type.ANY);
    Query q = new Query("?query=ignored");
    q.getModel().setLanguage(Language.UNKNOWN);
    q.getModel().getQueryTree().setRoot(item);
    new Execution(chain, createContextStub(indexFacts)).search(q);
    assertEquals("gram14:first", q.getModel().getQueryTree().toString());
}
Also used : Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query)

Example 59 with Item

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

the class NGramSearcherTestCase method assertGramsWithSegmentationMixed.

public void assertGramsWithSegmentationMixed(Chain<Searcher> chain) {
    // "first" "second" and "third" are segments in the "test" language
    Item item = parseQuery("a gram14:afirstsecondthird b gram14:hi", Query.Type.ALL);
    Query q = new Query("?query=ignored");
    q.getModel().setLanguage(Language.UNKNOWN);
    q.getModel().getQueryTree().setRoot(item);
    new Execution(chain, createContextStub(indexFacts)).search(q);
    assertEquals("AND a (AND gram14:afirstsecondth gram14:firstsecondthi gram14:irstsecondthir gram14:rstsecondthird) b gram14:hi", q.getModel().getQueryTree().toString());
}
Also used : Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query)

Example 60 with Item

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

the class SerializeItemTestCase method serialize_connectivity.

@Test
public void serialize_connectivity() throws ParseException {
    OrItem orItem = new OrItem();
    {
        WordItem first = new WordItem("first");
        WordItem second = new WordItem("second");
        first.setConnectivity(second, 3.14);
        orItem.addItem(first);
        orItem.addItem(second);
    }
    OrItem deSerialized = serializeThenParse(orItem);
    WordItem first = (WordItem) deSerialized.getItem(0);
    Item second = deSerialized.getItem(1);
    assertThat(first.getConnectedItem(), is(second));
    assertThat(first.getConnectivity(), is(3.14));
}
Also used : OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) EquivItem(com.yahoo.prelude.query.EquivItem) WordItem(com.yahoo.prelude.query.WordItem) OrItem(com.yahoo.prelude.query.OrItem) 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