Search in sources :

Example 1 with Highlight

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

the class QueryTestCase method testEncodeQueryPacketWithManyFeatures.

/**
 * This test will tell you if you have screwed up the binary encoding, but it won't tell you how
 */
@Test
public void testEncodeQueryPacketWithManyFeatures() {
    Query query = new Query("/?query=chain" + "&ranking.features.query(foo)=30.3&ranking.features.query(bar)=0" + "&ranking.properties.property.p1=v1&ranking.properties.property.p2=v2" + "&pos.ll=S22.4532;W123.9887&pos.radius=3&pos.attribute=place&ranking.freshness=37" + "&model.searchPath=7/3");
    query.getRanking().setFreshness(new Freshness("123456"));
    query.getRanking().setSorting("+field1 -field2");
    query.getRanking().setProfile("two");
    Highlight highlight = new Highlight();
    highlight.addHighlightTerm("field1", "term1");
    highlight.addHighlightTerm("field1", "term2");
    query.getPresentation().setHighlight(highlight);
    query.prepare();
    QueryPacket packet = QueryPacket.create(query);
    byte[] encoded = packetToBytes(packet);
    byte[] correctBuffer = new byte[] { 0, 0, 1, 23, 0, 0, 0, -38, 0, 0, 0, 0, 0, 16, 0, -122, 0, 10, ignored, ignored, ignored, ignored, 0, 0, 0x40, 0x03, 3, 't', 'w', 'o', 0, 0, 0, 3, 0, 0, 0, 4, 'r', 'a', 'n', 'k', 0, 0, 0, 5, 0, 0, 0, 11, 'p', 'r', 'o', 'p', 'e', 'r', 't', 'y', 46, 'p', '2', 0, 0, 0, 2, 'v', '2', 0, 0, 0, 11, 'p', 'r', 'o', 'p', 'e', 'r', 't', 'y', 46, 'p', '1', 0, 0, 0, 2, 'v', '1', 0, 0, 0, 3, 'f', 'o', 'o', 0, 0, 0, 4, '3', '0', 46, '3', 0, 0, 0, 3, 'b', 'a', 'r', 0, 0, 0, 1, '0', 0, 0, 0, 9, 'v', 'e', 's', 'p', 'a', 46, 'n', 'o', 'w', 0, 0, 0, 6, '1', '2', '3', '4', '5', '6', 0, 0, 0, 14, 'h', 'i', 'g', 'h', 'l', 'i', 'g', 'h', 't', 't', 'e', 'r', 'm', 's', 0, 0, 0, 3, 0, 0, 0, 6, 'f', 'i', 'e', 'l', 'd', '1', 0, 0, 0, 1, '2', 0, 0, 0, 6, 'f', 'i', 'e', 'l', 'd', '1', 0, 0, 0, 5, 't', 'e', 'r', 'm', '1', 0, 0, 0, 6, 'f', 'i', 'e', 'l', 'd', '1', 0, 0, 0, 5, 't', 'e', 'r', 'm', '2', 0, 0, 0, 5, 'm', 'o', 'd', 'e', 'l', 0, 0, 0, 1, 0, 0, 0, 10, 's', 'e', 'a', 'r', 'c', 'h', 'p', 'a', 't', 'h', 0, 0, 0, 3, '7', 47, '3', 0, 0, 0, 15, 43, 'f', 'i', 'e', 'l', 'd', '1', 32, 45, 'f', 'i', 'e', 'l', 'd', '2', 0, 0, 0, 1, 0, 0, 0, 9, 68, 1, 0, 5, 'c', 'h', 'a', 'i', 'n' };
    assertEqualArrays(correctBuffer, encoded);
}
Also used : Highlight(com.yahoo.prelude.query.Highlight) Query(com.yahoo.search.Query) Freshness(com.yahoo.prelude.Freshness) QueryPacket(com.yahoo.fs4.QueryPacket) Test(org.junit.Test)

Example 2 with Highlight

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

the class QueryTestCase method testClone.

@Test
public void testClone() {
    Query q = new Query(httpEncode("/sdfsd.html?query=this+is+a+simple+query&aParameter"));
    q.getPresentation().setHighlight(new Highlight());
    Query p = q.clone();
    assertEquals(q, p);
    assertEquals(q.hashCode(), p.hashCode());
    // Make sure we deep clone all mutable objects
    assertNotSame(q, p);
    assertNotSame(q.getRanking(), p.getRanking());
    assertNotSame(q.getRanking().getFeatures(), p.getRanking().getFeatures());
    assertNotSame(q.getRanking().getProperties(), p.getRanking().getProperties());
    assertNotSame(q.getRanking().getMatchPhase(), p.getRanking().getMatchPhase());
    assertNotSame(q.getRanking().getMatchPhase().getDiversity(), p.getRanking().getMatchPhase().getDiversity());
    assertNotSame(q.getRanking().getSoftTimeout(), p.getRanking().getSoftTimeout());
    assertNotSame(q.getPresentation(), p.getPresentation());
    assertNotSame(q.getPresentation().getHighlight(), p.getPresentation().getHighlight());
    assertNotSame(q.getPresentation().getSummaryFields(), p.getPresentation().getSummaryFields());
    assertNotSame(q.getModel(), p.getModel());
    assertNotSame(q.getModel().getSources(), p.getModel().getSources());
    assertNotSame(q.getModel().getRestrict(), p.getModel().getRestrict());
    assertNotSame(q.getModel().getQueryTree(), p.getModel().getQueryTree());
}
Also used : Highlight(com.yahoo.prelude.query.Highlight) Query(com.yahoo.search.Query) Test(org.junit.Test)

Example 3 with Highlight

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

the class QueryTestCase method testEncodeQueryPacketWithManyFeaturesFresnhessAsString.

/**
 * This test will tell you if you have screwed up the binary encoding, but it won't tell you how
 */
@Test
public void testEncodeQueryPacketWithManyFeaturesFresnhessAsString() {
    Query query = new Query("/?query=chain" + "&ranking.features.query(foo)=30.3&ranking.features.query(bar)=0" + "&ranking.properties.property.p1=v1&ranking.properties.property.p2=v2" + "&pos.ll=S22.4532;W123.9887&pos.radius=3&pos.attribute=place&ranking.freshness=37" + "&model.searchPath=7/3");
    query.getRanking().setFreshness("123456");
    query.getRanking().setSorting("+field1 -field2");
    query.getRanking().setProfile("two");
    Highlight highlight = new Highlight();
    highlight.addHighlightTerm("field1", "term1");
    highlight.addHighlightTerm("field1", "term2");
    query.getPresentation().setHighlight(highlight);
    query.prepare();
    QueryPacket packet = QueryPacket.create(query);
    byte[] encoded = packetToBytes(packet);
    byte[] correctBuffer = new byte[] { 0, 0, 1, 23, 0, 0, 0, -38, 0, 0, 0, 0, 0, 16, 0, -122, 0, 10, ignored, ignored, ignored, ignored, 0, 0, 0x40, 0x03, 3, 't', 'w', 'o', 0, 0, 0, 3, 0, 0, 0, 4, 'r', 'a', 'n', 'k', 0, 0, 0, 5, 0, 0, 0, 11, 'p', 'r', 'o', 'p', 'e', 'r', 't', 'y', 46, 'p', '2', 0, 0, 0, 2, 'v', '2', 0, 0, 0, 11, 'p', 'r', 'o', 'p', 'e', 'r', 't', 'y', 46, 'p', '1', 0, 0, 0, 2, 'v', '1', 0, 0, 0, 3, 'f', 'o', 'o', 0, 0, 0, 4, '3', '0', 46, '3', 0, 0, 0, 3, 'b', 'a', 'r', 0, 0, 0, 1, '0', 0, 0, 0, 9, 'v', 'e', 's', 'p', 'a', 46, 'n', 'o', 'w', 0, 0, 0, 6, '1', '2', '3', '4', '5', '6', 0, 0, 0, 14, 'h', 'i', 'g', 'h', 'l', 'i', 'g', 'h', 't', 't', 'e', 'r', 'm', 's', 0, 0, 0, 3, 0, 0, 0, 6, 'f', 'i', 'e', 'l', 'd', '1', 0, 0, 0, 1, '2', 0, 0, 0, 6, 'f', 'i', 'e', 'l', 'd', '1', 0, 0, 0, 5, 't', 'e', 'r', 'm', '1', 0, 0, 0, 6, 'f', 'i', 'e', 'l', 'd', '1', 0, 0, 0, 5, 't', 'e', 'r', 'm', '2', 0, 0, 0, 5, 'm', 'o', 'd', 'e', 'l', 0, 0, 0, 1, 0, 0, 0, 10, 's', 'e', 'a', 'r', 'c', 'h', 'p', 'a', 't', 'h', 0, 0, 0, 3, '7', 47, '3', 0, 0, 0, 15, 43, 'f', 'i', 'e', 'l', 'd', '1', 32, 45, 'f', 'i', 'e', 'l', 'd', '2', 0, 0, 0, 1, 0, 0, 0, 9, 68, 1, 0, 5, 'c', 'h', 'a', 'i', 'n' };
    assertEqualArrays(correctBuffer, encoded);
}
Also used : Highlight(com.yahoo.prelude.query.Highlight) Query(com.yahoo.search.Query) QueryPacket(com.yahoo.fs4.QueryPacket) Test(org.junit.Test)

Example 4 with Highlight

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

the class PresentationTestCase method testClone.

public void testClone() {
    Query q = new Query("");
    Presentation p = new Presentation(q);
    p.setBolding(true);
    Highlight h = new Highlight();
    h.addHighlightTerm("date", "today");
    p.setHighlight(h);
    Presentation pc = (Presentation) p.clone();
    h.addHighlightTerm("title", "Hello");
    assertTrue(pc.getBolding());
    pc.getHighlight().getHighlightItems();
    assertTrue(pc.getHighlight().getHighlightItems().containsKey("date"));
    assertFalse(pc.getHighlight().getHighlightItems().containsKey("title"));
    assertEquals(p, pc);
}
Also used : Highlight(com.yahoo.prelude.query.Highlight) Query(com.yahoo.search.Query) Presentation(com.yahoo.search.query.Presentation)

Aggregations

Highlight (com.yahoo.prelude.query.Highlight)4 Query (com.yahoo.search.Query)4 Test (org.junit.Test)3 QueryPacket (com.yahoo.fs4.QueryPacket)2 Freshness (com.yahoo.prelude.Freshness)1 Presentation (com.yahoo.search.query.Presentation)1