use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.
the class XMLRendererTestCase method testImplicitDefaultRender.
@Test
public final void testImplicitDefaultRender() throws Exception {
Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true");
q.getPresentation().setTiming(true);
Result r = new Result(q);
r.setCoverage(new Coverage(500, 1, true));
TimeTracker t = new TimeTracker(new Chain<Searcher>(new UselessSearcher("first"), new UselessSearcher("second"), new UselessSearcher("third")));
ElapsedTimeTestCase.doInjectTimeSource(t, new CreativeTimeSource(new long[] { 1L, 2L, 3L, 4L, 5L, 6L, 7L }));
t.sampleSearch(0, true);
t.sampleSearch(1, true);
t.sampleSearch(2, true);
t.sampleSearch(3, true);
t.sampleSearchReturn(2, true, null);
t.sampleSearchReturn(1, true, null);
t.sampleSearchReturn(0, true, null);
r.getElapsedTime().add(t);
r.getTemplating().setRenderer(d);
FastHit h = new FastHit("http://localhost/", .95);
h.setField("$a", "Hello, world.");
h.setField("b", "foo");
r.hits().add(h);
HitGroup g = new HitGroup("usual");
h = new FastHit("http://localhost/1", .90);
h.setField("c", "d");
g.add(h);
r.hits().add(g);
HitGroup gg = new HitGroup("type grouphit");
gg.types().add("grouphit");
gg.setField("e", "f");
r.hits().add(gg);
r.hits().addError(ErrorMessage.createInternalServerError("boom"));
ByteArrayOutputStream bs = new ByteArrayOutputStream();
ListenableFuture<Boolean> f = d.render(bs, r, null, null);
assertTrue(f.get());
String summary = Utf8.toString(bs.toByteArray());
assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + "<result total-hit-count=\"0\"", summary.substring(0, 67));
assertTrue(summary.contains("<meta type=\"context\">"));
assertTrue(summary.contains("<error code=\"18\">Internal server error.</error>"));
assertTrue(summary.contains("<hit type=\"grouphit\" relevancy=\"1.0\">"));
assertTrue(summary.contains("<hit type=\"summary\" relevancy=\"0.95\">"));
assertEquals(2, occurrences("<error ", summary));
assertTrue(summary.length() > 1000);
}
use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.
the class BlendingSearcherTestCase method testMultipleBackendsWithDuplicateRemoval.
@Test
public void testMultipleBackendsWithDuplicateRemoval() {
DocumentSourceSearcher chain1 = new DocumentSourceSearcher();
DocumentSourceSearcher chain2 = new DocumentSourceSearcher();
Query q = new Query("/search?query=hannibal&search=a,b");
Result r1 = new Result(q);
Result r2 = new Result(q);
r1.setTotalHitCount(1);
r1.hits().add(new FastHit("http://host1.com/", 101));
chain1.addResultSet(q, r1);
r2.hits().add(new FastHit("http://host1.com/", 102));
r2.setTotalHitCount(1);
chain2.addResultSet(q, r2);
BlendingSearcherWrapper blender = new BlendingSearcherWrapper("uri");
blender.addChained(new FillSearcher(chain1), "a");
blender.addChained(new FillSearcher(chain2), "b");
blender.initialize();
q.setWindow(0, 10);
Result cr = new Execution(blender, Execution.Context.createContextStub()).search(q);
assertEquals(1, cr.getHitCount());
assertEquals(101, ((int) cr.hits().get(0).getRelevance().getScore()));
}
use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.
the class BlendingSearcherTestCase method testMultipleBackendsWithErrorMerging.
@Test
public void testMultipleBackendsWithErrorMerging() {
DocumentSourceSearcher chain1 = new DocumentSourceSearcher();
DocumentSourceSearcher chain2 = new DocumentSourceSearcher();
Query q = new Query("/search?query=hannibal&search=a,b");
Result r1 = new Result(q, ErrorMessage.createNoBackendsInService(null));
Result r2 = new Result(q, ErrorMessage.createRequestTooLarge(null));
r1.setTotalHitCount(0);
chain1.addResultSet(q, r1);
r2.hits().add(new FastHit("http://host1.com/", 102));
r2.setTotalHitCount(1);
chain2.addResultSet(q, r2);
BlendingSearcherWrapper blender = new BlendingSearcherWrapper();
blender.addChained(new FillSearcher(chain1), "a");
blender.addChained(new FillSearcher(chain2), "b");
blender.initialize();
q.setWindow(0, 10);
Result cr = new Execution(blender, Execution.Context.createContextStub()).search(q);
assertEquals(2, cr.getHitCount());
assertEquals(1, cr.getConcreteHitCount());
com.yahoo.search.result.ErrorHit errorHit = cr.hits().getErrorHit();
Iterator errorIterator = errorHit.errorIterator();
List<String> errorList = Arrays.asList("Source 'a': No backends in service. Try later", "Source 'b': 2: Request too large");
String a = errorIterator.next().toString();
assertTrue(a, errorList.contains(a));
String b = errorIterator.next().toString();
assertTrue(a, errorList.contains(b));
assertFalse(errorIterator.hasNext());
assertEquals(102, ((int) cr.hits().get(1).getRelevance().getScore()));
assertEquals(com.yahoo.container.protect.Error.NO_BACKENDS_IN_SERVICE.code, cr.hits().getError().getCode());
}
use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.
the class JSONDebugSearcherTestCase method addResult.
private void addResult(Query q, String content, DocumentSourceSearcher docsource) {
Result r = new Result(q);
FastHit hit = new FastHit();
hit.setId("http://abc.html");
hit.setRelevance(new Relevance(1));
hit.setField("jsonfield", new JSONString(content));
r.hits().add(hit);
docsource.addResult(q, r);
}
use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.
the class PartialFillTestCase method testMergeErrors.
@Test
public void testMergeErrors() {
BadFS4 fs4 = new BadFS4();
Query a = new Query("/?query=foo");
Query b = new Query("/?query=bar");
Result r = new Result(new Query("/?query=ignorethis"));
{
FastHit h = new FastHit();
h.setQuery(a);
h.setFillable();
r.hits().add(h);
}
{
FastHit h = new FastHit();
h.setQuery(b);
h.setFillable();
r.hits().add(h);
}
doFill(fs4, r, "default");
ErrorHit eh = r.hits().getErrorHit();
assertNotNull(eh);
ErrorMessage exp_sub = ErrorMessage.createUnspecifiedError("error");
int n = 0;
for (Iterator<? extends com.yahoo.search.result.ErrorMessage> i = eh.errorIterator(); i.hasNext(); ) {
com.yahoo.search.result.ErrorMessage error = i.next();
switch(n) {
case 0:
assertEquals(exp_sub, error);
break;
case 1:
assertEquals(exp_sub, error);
break;
default:
assertTrue(false);
}
n++;
}
}
Aggregations