Search in sources :

Example 6 with Substring

use of com.yahoo.prelude.query.Substring 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());
}
Also used : Substring(com.yahoo.prelude.query.Substring) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) IndexedItem(com.yahoo.prelude.query.IndexedItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) RegExpItem(com.yahoo.prelude.query.RegExpItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) QueryTree(com.yahoo.search.query.QueryTree) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) Test(org.junit.Test)

Example 7 with Substring

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

the class NormalizingSearcherTestCase method testLiteralBoost.

@Test
public void testLiteralBoost() {
    Query query = new Query("/search?query=nop&search=cluster1&restrict=type1");
    List<WordAlternativesItem.Alternative> terms = new ArrayList<>();
    Substring origin = new Substring(0, 5, "h\u00F4tels");
    terms.add(new WordAlternativesItem.Alternative("h\u00F4tels", 1.0d));
    terms.add(new WordAlternativesItem.Alternative("h\u00F4tel", 0.7d));
    query.getModel().getQueryTree().setRoot(new WordAlternativesItem("default", true, origin, terms));
    createExecution().search(query);
    WordAlternativesItem w = (WordAlternativesItem) query.getModel().getQueryTree().getRoot();
    assertEquals(4, w.getAlternatives().size());
    boolean foundHotel = false;
    for (WordAlternativesItem.Alternative a : w.getAlternatives()) {
        if ("hotel".equals(a.word)) {
            foundHotel = true;
            assertEquals(.7d * .7d, a.exactness, 1e-15);
        }
    }
    assertTrue("Did not find the expected normalized form \"hotel\".", foundHotel);
}
Also used : Substring(com.yahoo.prelude.query.Substring) Query(com.yahoo.search.Query) ArrayList(java.util.ArrayList) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) Test(org.junit.Test)

Aggregations

Substring (com.yahoo.prelude.query.Substring)7 WordAlternativesItem (com.yahoo.prelude.query.WordAlternativesItem)3 WordItem (com.yahoo.prelude.query.WordItem)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)2 TaggableItem (com.yahoo.prelude.query.TaggableItem)2 NonNull (edu.umd.cs.findbugs.annotations.NonNull)2 Language (com.yahoo.language.Language)1 AndItem (com.yahoo.prelude.query.AndItem)1 AndSegmentItem (com.yahoo.prelude.query.AndSegmentItem)1 ExactStringItem (com.yahoo.prelude.query.ExactStringItem)1 IndexedItem (com.yahoo.prelude.query.IndexedItem)1 Item (com.yahoo.prelude.query.Item)1 PhraseItem (com.yahoo.prelude.query.PhraseItem)1 PrefixItem (com.yahoo.prelude.query.PrefixItem)1 RegExpItem (com.yahoo.prelude.query.RegExpItem)1 SegmentItem (com.yahoo.prelude.query.SegmentItem)1 SubstringItem (com.yahoo.prelude.query.SubstringItem)1 SuffixItem (com.yahoo.prelude.query.SuffixItem)1