Search in sources :

Example 66 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class SemanticSearcherTestCase method testWeightedSetItem.

// This test is order dependent. Fix it!!
public void testWeightedSetItem() {
    Query q = new Query();
    WeightedSetItem weightedSet = new WeightedSetItem("fieldName");
    weightedSet.addToken("a", 1);
    weightedSet.addToken("b", 2);
    q.getModel().getQueryTree().setRoot(weightedSet);
    assertSemantics("WEIGHTEDSET fieldName{[1]:\"a\",[2]:\"b\"}", q);
}
Also used : Query(com.yahoo.search.Query) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem)

Example 67 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class GroupedResultTestCase method testGroupedResult.

public void testGroupedResult() {
    Result result = new Result(new Query("?query=foo"));
    HitGroup hitGroup1 = new HitGroup("group1", 300);
    hitGroup1.add(new Hit("group1.1", 200));
    HitGroup hitGroup2 = new HitGroup("group2", 600);
    Hit topLevelHit1 = new Hit("toplevel.1", 500);
    Hit topLevelHit2 = new Hit("toplevel.2", 700);
    result.hits().add(hitGroup1);
    result.hits().add(topLevelHit1);
    result.hits().add(hitGroup2);
    result.hits().add(topLevelHit2);
    hitGroup1.add(new Hit("group1.2", 800));
    hitGroup2.add(new Hit("group2.1", 800));
    hitGroup2.add(new Hit("group2.2", 300));
    hitGroup2.add(new Hit("group2.3", 500));
    // Should have 7 concrete hits, ordered as
    // toplevel.2
    // group2
    // group2.1
    // group2.3
    // group2.2
    // toplevel.1
    // group1
    // group1.2
    // group1.1
    // Assert this:
    assertEquals(7, result.getConcreteHitCount());
    assertEquals(4, result.getHitCount());
    Hit topLevel2 = result.hits().get(0);
    assertEquals("toplevel.2", topLevel2.getId().stringValue());
    HitGroup returnedGroup2 = (HitGroup) result.hits().get(1);
    assertEquals(3, returnedGroup2.getConcreteSize());
    assertEquals(3, returnedGroup2.size());
    assertEquals("group2.1", returnedGroup2.get(0).getId().stringValue());
    assertEquals("group2.3", returnedGroup2.get(1).getId().stringValue());
    assertEquals("group2.2", returnedGroup2.get(2).getId().stringValue());
    Hit topLevel1 = result.hits().get(2);
    assertEquals("toplevel.1", topLevel1.getId().stringValue());
    HitGroup returnedGroup1 = (HitGroup) result.hits().get(3);
    assertEquals(2, returnedGroup1.getConcreteSize());
    assertEquals(2, returnedGroup1.size());
    assertEquals("group1.2", returnedGroup1.get(0).getId().stringValue());
    assertEquals("group1.1", returnedGroup1.get(1).getId().stringValue());
}
Also used : Hit(com.yahoo.search.result.Hit) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup)

Example 68 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class TilingTestCase method testTiling2.

/**
 * This result contains center section and meta blocks.
 * <p>
 * Incidentally, this also tests using an old searcher in new search chains.
 */
public void testTiling2() throws IOException {
    Chain<Searcher> chain = new Chain<>("tiling", new TiledResultProducer2());
    // Query it
    Query query = new Query("/tiled?query=foo");
    Result result = callSearchAndSetRenderer(chain, query);
    assertRendered(IOUtils.readFile(new File("src/test/java/com/yahoo/prelude/templates/test/tilingexample2.xml")), result);
}
Also used : Chain(com.yahoo.component.chain.Chain) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) HTTPProviderSearcher(com.yahoo.search.federation.http.HTTPProviderSearcher) File(java.io.File) Result(com.yahoo.search.Result)

Example 69 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class GetRawWordTestCase method testGetRawWord.

@Test
public void testGetRawWord() {
    Query query = new Query("?query=%C4%B0%C5%9EBANKASI%20GAZ%C4%B0EM%C4%B0R&searchChain=vespa");
    assertEquals("AND \u0130\u015EBANKASI GAZ\u0130EM\u0130R", query.getModel().getQueryTree().toString());
    AndItem root = (AndItem) query.getModel().getQueryTree().getRoot();
    {
        WordItem word = (WordItem) root.getItem(0);
        assertEquals("\u0130\u015EBANKASI", word.getRawWord());
        assertEquals(0, word.getOrigin().start);
        assertEquals(9, word.getOrigin().end);
    }
    {
        WordItem word = (WordItem) root.getItem(1);
        assertEquals("GAZ\u0130EM\u0130R", word.getRawWord());
        assertEquals(10, word.getOrigin().start);
        assertEquals(18, word.getOrigin().end);
    }
    assertEquals("Total string is just these words", 18, ((WordItem) root.getItem(0)).getOrigin().getSuperstring().length());
}
Also used : Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 70 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class HitConverterTestCase method requireThatHitHasContext.

@Test
public void requireThatHitHasContext() {
    HitConverter converter = new HitConverter(new MySearcher(), new Query());
    try {
        converter.toSearchHit("69", new FS4Hit(1, createGlobalId(2), 3));
        fail();
    } catch (NullPointerException e) {
    }
}
Also used : FS4Hit(com.yahoo.searchlib.aggregation.FS4Hit) Query(com.yahoo.search.Query) Test(org.junit.Test)

Aggregations

Query (com.yahoo.search.Query)689 Test (org.junit.Test)415 Result (com.yahoo.search.Result)229 Execution (com.yahoo.search.searchchain.Execution)184 Searcher (com.yahoo.search.Searcher)82 QueryProfile (com.yahoo.search.query.profile.QueryProfile)63 Hit (com.yahoo.search.result.Hit)52 Chain (com.yahoo.component.chain.Chain)47 IndexFacts (com.yahoo.prelude.IndexFacts)44 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)37 AndItem (com.yahoo.prelude.query.AndItem)33 WordItem (com.yahoo.prelude.query.WordItem)33 FastHit (com.yahoo.prelude.fastsearch.FastHit)31 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)27 HitGroup (com.yahoo.search.result.HitGroup)24 Item (com.yahoo.prelude.query.Item)21 HashMap (java.util.HashMap)20 CacheKey (com.yahoo.prelude.fastsearch.CacheKey)18 GroupingRequest (com.yahoo.search.grouping.GroupingRequest)18 ArrayList (java.util.ArrayList)18