Search in sources :

Example 16 with Query

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

the class HTTPProviderSearcher method unmarshal.

/**
 * Unmarshal the result from an http entity. This default implementation calls
 * <code>unmarshal(entity.getContent(), entity.getContentLength(), result)</code>
 * (and does some detailed query tracing).
 *
 * @param entity the entity containing the data to unmarshal
 * @param result the result to which unmarshalled data should be added
 */
public void unmarshal(HttpEntity entity, Result result) throws IOException {
    Query query = result.getQuery();
    long len = entity.getContentLength();
    if (query.getTraceLevel() >= 4)
        query.trace("Received " + len + " bytes response in " + this, false, 4);
    query.trace("Unmarshaling result.", false, 6);
    unmarshal(entity.getContent(), len, result);
    if (query.getTraceLevel() >= 2)
        query.trace("Handled " + len + " bytes response in " + this, false, 2);
}
Also used : Query(com.yahoo.search.Query)

Example 17 with Query

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

the class FastSearcherTestCase method testSinglePhaseCachedSupersets.

@Ignore
public void testSinglePhaseCachedSupersets() {
    Logger.getLogger(FastSearcher.class.getName()).setLevel(Level.ALL);
    MockFSChannel.resetDocstamp();
    FastSearcher fastSearcher = new FastSearcher(new MockBackend(), new FS4ResourcePool(1), new MockDispatcher(Collections.emptyList()), new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(100, 1e64), documentdbInfoConfig);
    CacheControl c = fastSearcher.getCacheControl();
    Result result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 2);
    Query q = new Query("?query=ignored");
    ((WordItem) q.getModel().getQueryTree().getRoot()).setUniqueID(1);
    QueryPacket queryPacket = QueryPacket.create(q);
    CacheKey k = new CacheKey(queryPacket);
    PacketWrapper p = c.lookup(k, q);
    assertEquals(1, p.getResultPackets().size());
    result = doSearch(fastSearcher, new Query("?query=ignored"), 1, 1);
    p = c.lookup(k, q);
    // ensure we don't get redundant QueryResultPacket instances
    // in the cache
    assertEquals(1, p.getResultPackets().size());
    assertEquals(1, result.getConcreteHitCount());
    for (int i = 0; i < result.getHitCount(); i++) {
        assertTrue(result.hits().get(i).isCached());
    }
    result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 1);
    p = c.lookup(k, q);
    assertEquals(1, p.getResultPackets().size());
    assertEquals(1, result.getConcreteHitCount());
    for (int i = 0; i < result.getHitCount(); i++) {
        assertTrue(result.hits().get(i).isCached());
    }
}
Also used : Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) MockBackend(com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend) WordItem(com.yahoo.prelude.query.WordItem) Ignore(org.junit.Ignore)

Example 18 with Query

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

the class FastSearcherTestCase method testSearch.

@Test
public void testSearch() {
    FastSearcher fastSearcher = createFastSearcher();
    // Default cache =100MB
    assertEquals(100, fastSearcher.getCacheControl().capacity());
    Result result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 10);
    Execution execution = new Execution(chainedAsSearchChain(fastSearcher), Execution.Context.createContextStub());
    assertEquals(2, result.getHitCount());
    execution.fill(result);
    assertCorrectHit1((FastHit) result.hits().get(0));
    assertCorrectTypes1((FastHit) result.hits().get(0));
    for (int idx = 0; idx < result.getHitCount(); idx++) {
        assertTrue(!result.hits().get(idx).isCached());
    }
    // Repeat the request a couple of times, to verify whether the packet cache works
    result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 10);
    assertEquals(2, result.getHitCount());
    execution.fill(result);
    assertCorrectHit1((FastHit) result.hits().get(0));
    for (int i = 0; i < result.getHitCount(); i++) {
        assertTrue(result.hits().get(i) + " should be cached", result.hits().get(i).isCached());
    }
    // outside-range cache hit
    result = doSearch(fastSearcher, new Query("?query=ignored"), 6, 3);
    // fill should still work (nop)
    execution.fill(result);
    result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 10);
    assertEquals(2, result.getHitCount());
    assertCorrectHit1((FastHit) result.hits().get(0));
    assertTrue("All hits are cached and the result knows it", result.isCached());
    for (int i = 0; i < result.getHitCount(); i++) {
        assertTrue(result.hits().get(i) + " should be cached", result.hits().get(i).isCached());
    }
    clearCache(fastSearcher);
    result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 10);
    assertEquals(2, result.getHitCount());
    execution.fill(result);
    assertCorrectHit1((FastHit) result.hits().get(0));
    assertTrue("All hits are not cached", !result.isCached());
    for (int i = 0; i < result.getHitCount(); i++) {
        assertTrue(!result.hits().get(i).isCached());
    }
    // Test that partial result sets can be retrieved from the cache
    clearCache(fastSearcher);
    result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 1);
    assertEquals(1, result.getConcreteHitCount());
    execution.fill(result);
    result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 2);
    assertEquals(2, result.getConcreteHitCount());
    execution.fill(result);
    // First hit should be cached but not second hit
    assertTrue(result.hits().get(0).isCached());
    assertFalse(result.hits().get(1).isCached());
    // Check that the entire result set is returned from cache now
    result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 2);
    assertEquals(2, result.getConcreteHitCount());
    execution.fill(result);
    // both first and second should now be cached
    assertTrue(result.hits().get(0).isCached());
    assertTrue(result.hits().get(1).isCached());
    // Tests that the cache _hit_ is not returned if _another_
    // hit is requested
    clearCache(fastSearcher);
    result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 1);
    assertEquals(1, result.getConcreteHitCount());
    result = doSearch(fastSearcher, new Query("?query=ignored"), 1, 1);
    assertEquals(1, result.getConcreteHitCount());
    for (int i = 0; i < result.getHitCount(); i++) {
        assertFalse("Hit " + i + " should not be cached.", result.hits().get(i).isCached());
    }
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 19 with Query

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

the class FastSearcherTestCase method testThatPropertiesAreReencoded.

@Test
public void testThatPropertiesAreReencoded() throws Exception {
    FastSearcher fastSearcher = createFastSearcher();
    // Default cache =100MB
    assertEquals(100, fastSearcher.getCacheControl().capacity());
    Query query = new Query("?query=ignored");
    query.getRanking().setQueryCache(true);
    Result result = doSearch(fastSearcher, query, 0, 10);
    Execution execution = new Execution(chainedAsSearchChain(fastSearcher), Execution.Context.createContextStub());
    assertEquals(2, result.getHitCount());
    execution.fill(result);
    BasicPacket receivedPacket = mockBackend.getChannel().getLastReceived();
    ByteBuffer buf = ByteBuffer.allocate(1000);
    receivedPacket.encode(buf);
    buf.flip();
    byte[] actual = new byte[buf.remaining()];
    buf.get(actual);
    SessionId sessionId = query.getSessionId(false);
    byte IGNORE = 69;
    ByteBuffer answer = ByteBuffer.allocate(1024);
    answer.put(new byte[] { 0, 0, 0, (byte) (145 + sessionId.asUtf8String().getByteLength()), 0, 0, 0, -37, 0, 0, 48, 17, 0, 0, 0, 0, // query timeout
    IGNORE, IGNORE, IGNORE, IGNORE, // "default" - rank profile
    7, 'd', 'e', 'f', 'a', 'u', 'l', 't', 0, 0, 0, 0x03, // 3 property entries (rank, match, caches)
    0, 0, 0, 3, // rank: sessionId => qrserver.0.XXXXXXXXXXXXX.0
    0, 0, 0, 4, 'r', 'a', 'n', 'k', 0, 0, 0, 1, 0, 0, 0, 9, 's', 'e', 's', 's', 'i', 'o', 'n', 'I', 'd' });
    answer.putInt(sessionId.asUtf8String().getBytes().length);
    answer.put(sessionId.asUtf8String().getBytes());
    answer.put(new byte[] { // match: documentdb.searchdoctype => test
    0, 0, 0, 5, 'm', 'a', 't', 'c', 'h', 0, 0, 0, 1, 0, 0, 0, 24, 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 'd', 'b', '.', 's', 'e', 'a', 'r', 'c', 'h', 'd', 'o', 'c', 't', 'y', 'p', 'e', 0, 0, 0, 4, 't', 'e', 's', 't', // sessionId => qrserver.0.XXXXXXXXXXXXX.0
    0, 0, 0, 6, 'c', 'a', 'c', 'h', 'e', 's', 0, 0, 0, 1, 0, 0, 0, 5, 'q', 'u', 'e', 'r', 'y', 0, 0, 0, 4, 't', 'r', 'u', 'e', // flags
    0, 0, 0, 2 });
    byte[] expected = new byte[answer.position()];
    answer.flip();
    answer.get(expected);
    assertEquals(expected.length, actual.length);
    for (int i = 0; i < expected.length; ++i) {
        if (expected[i] == IGNORE) {
            actual[i] = IGNORE;
        }
    }
    assertArrayEquals(expected, actual);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) ByteBuffer(java.nio.ByteBuffer) SessionId(com.yahoo.search.query.SessionId) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 20 with Query

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

the class FastSearcherTestCase method testQueryWithRestrict.

@Test
public void testQueryWithRestrict() {
    mockBackend = new MockBackend();
    DocumentdbInfoConfig documentdbConfigWithOneDb = new DocumentdbInfoConfig(new DocumentdbInfoConfig.Builder().documentdb(new DocumentdbInfoConfig.Documentdb.Builder().name("testDb")));
    FastSearcher fastSearcher = new FastSearcher(mockBackend, new FS4ResourcePool(1), new MockDispatcher(Collections.emptyList()), new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(100, 1e64), documentdbConfigWithOneDb);
    Query query = new Query("?query=foo&model.restrict=testDb");
    query.prepare();
    Result result = doSearch(fastSearcher, query, 0, 10);
    Packet receivedPacket = mockBackend.getChannel().getLastQueryPacket();
    byte[] encoded = QueryTestCase.packetToBytes(receivedPacket);
    byte[] correct = new byte[] { 0, 0, 0, 100, 0, 0, 0, -38, 0, 0, 0, 0, 0, 16, 0, 6, 0, 10, // time left
    QueryTestCase.ignored, // time left
    QueryTestCase.ignored, // time left
    QueryTestCase.ignored, // time left
    QueryTestCase.ignored, 0, 0, 0x40, 0x03, 7, 100, 101, 102, 97, 117, 108, 116, 0, 0, 0, 1, 0, 0, 0, 5, 109, 97, 116, 99, 104, 0, 0, 0, 1, 0, 0, 0, 24, 100, 111, 99, 117, 109, 101, 110, 116, 100, 98, 46, 115, 101, 97, 114, 99, 104, 100, 111, 99, 116, 121, 112, 101, 0, 0, 0, 6, 116, 101, 115, 116, 68, 98, 0, 0, 0, 1, 0, 0, 0, 7, 68, 1, 0, 3, 102, 111, 111 };
    QueryTestCase.assertEqualArrays(correct, encoded);
}
Also used : Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) DocumentdbInfoConfig(com.yahoo.prelude.fastsearch.DocumentdbInfoConfig) MockBackend(com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend) 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