use of com.yahoo.search.result.ErrorMessage in project vespa by vespa-engine.
the class QueryValidatingSearcher method search.
public Result search(Query query, Execution execution) {
if (query.getHits() > 1000) {
Result result = new Result(query);
ErrorMessage error = ErrorMessage.createInvalidQueryParameter("Too many hits (more than 1000) requested.");
result.hits().addError(error);
return result;
}
if (query.getOffset() > 1000) {
Result result = new Result(query);
ErrorMessage error = ErrorMessage.createInvalidQueryParameter("Offset too high (above 1000).");
result.hits().addError(error);
return result;
}
return execution.search(query);
}
use of com.yahoo.search.result.ErrorMessage in project vespa by vespa-engine.
the class ValidatePredicateSearcher method search.
@Override
public Result search(Query query, Execution execution) {
Optional<ErrorMessage> e = validate(query, execution.context().getIndexFacts().newSession(query));
if (e.isPresent()) {
Result r = new Result(query);
r.hits().addError(e.get());
return r;
}
return execution.search(query);
}
use of com.yahoo.search.result.ErrorMessage in project vespa by vespa-engine.
the class ValidateSortingSearcher method search.
@Override
public Result search(Query query, Execution execution) {
if (indexingMode != QrSearchersConfig.Searchcluster.Indexingmode.STREAMING) {
ErrorMessage e = validate(query);
if (e != null) {
Result r = new Result(query);
r.hits().addError(e);
return r;
}
}
return execution.search(query);
}
use of com.yahoo.search.result.ErrorMessage in project vespa by vespa-engine.
the class ResultBuilderTestCase method testSimpleResult.
public void testSimpleResult() {
boolean gotErrorDetails = false;
ResultBuilder r = new ResultBuilder();
Result res = r.parse("file:src/test/java/com/yahoo/prelude/searcher/test/testhit.xml", new Query("?query=a"));
assertEquals(3, res.getConcreteHitCount());
assertEquals(4, res.getHitCount());
ErrorHit e = (ErrorHit) res.hits().get(0);
// is no way of nuking an existing error if the details exist.
for (Iterator<?> i = e.errorIterator(); i.hasNext(); ) {
ErrorMessage err = (ErrorMessage) i.next();
assertEquals(5, err.getCode());
String details = err.getDetailedMessage();
if (details != null) {
gotErrorDetails = true;
assertEquals("An error as ordered", details.trim());
}
}
assertTrue("Error details are missing", gotErrorDetails);
assertEquals(new URI("http://def"), res.hits().get(1).getId());
assertEquals("test/stuff\\tsome/other", res.hits().get(2).getField("category"));
assertEquals("<field>habla</field>" + "<hi>blbl</hi><br /><>&fdlkkgj</field>;lk<a b=\"1\" c=\"2\" />" + "<x><y><z /></y></x>", res.hits().get(3).getField("annoying").toString());
}
use of com.yahoo.search.result.ErrorMessage in project vespa by vespa-engine.
the class BlendingSearcherTestCase method testExistingAndNonExistingBackendCausesBothErrorAndResult.
@Test
public void testExistingAndNonExistingBackendCausesBothErrorAndResult() {
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana&search=first,nonesuch,second");
Result result = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())).search(query);
assertEquals(3, result.getConcreteHitCount());
assertEquals(300.0, result.hits().get(1).getRelevance().getScore(), delta);
assertEquals(200.0, result.hits().get(2).getRelevance().getScore(), delta);
assertEquals(100.0, result.hits().get(3).getRelevance().getScore(), delta);
assertNotNull(result.hits().getError());
ErrorMessage e = result.hits().getError();
// TODO: Do not depend on sources order
assertEquals("Could not resolve source ref 'nonesuch'. Valid source refs are first, second.", e.getDetailedMessage());
}
Aggregations