use of com.yahoo.fs4.QueryPacket in project vespa by vespa-engine.
the class FastSearcher method doSearch2.
@Override
public Result doSearch2(Query query, QueryPacket queryPacket, CacheKey cacheKey, Execution execution) {
FS4Channel channel = null;
try {
if (dispatcher.searchCluster().groupSize() == 1)
forceSinglePassGrouping(query);
channel = chooseBackend(query).openChannel();
channel.setQuery(query);
Result result = searchTwoPhase(channel, query, queryPacket, cacheKey);
if (query.properties().getBoolean(Ranking.RANKFEATURES, false)) {
// There is currently no correct choice for which
// summary class we want to fetch at this point. If we
// fetch the one selected by the user it may not
// contain the data we need. If we fetch the default
// one we end up fetching docsums twice unless the
// user also requested the default one.
// ARGH
fill(result, query.getPresentation().getSummary(), execution);
}
return result;
} catch (TimeoutException e) {
return new Result(query, ErrorMessage.createTimeout(e.getMessage()));
} catch (IOException e) {
Result result = new Result(query);
if (query.getTraceLevel() >= 1)
query.trace(getName() + " error response: " + result, false, 1);
result.hits().addError(ErrorMessage.createBackendCommunicationError(getName() + " failed: " + e.getMessage()));
return result;
} finally {
if (channel != null)
channel.close();
}
}
use of com.yahoo.fs4.QueryPacket in project vespa by vespa-engine.
the class FastSearcher method searchTwoPhase.
private Result searchTwoPhase(FS4Channel channel, Query query, QueryPacket queryPacket, CacheKey cacheKey) throws IOException {
if (isLoggingFine())
getLogger().finest("sending query packet");
try {
boolean couldSend = channel.sendPacket(queryPacket);
if (!couldSend)
return new Result(query, ErrorMessage.createBackendCommunicationError("Could not reach '" + getName() + "'"));
} catch (InvalidChannelException e) {
return new Result(query, ErrorMessage.createBackendCommunicationError("Invalid channel " + getName()));
} catch (IllegalStateException e) {
return new Result(query, ErrorMessage.createBackendCommunicationError("Illegal state in FS4: " + e.getMessage()));
}
BasicPacket[] basicPackets;
try {
basicPackets = channel.receivePackets(query.getTimeLeft(), 1);
} catch (ChannelTimeoutException e) {
return new Result(query, ErrorMessage.createTimeout("Timeout while waiting for " + getName()));
} catch (InvalidChannelException e) {
return new Result(query, ErrorMessage.createBackendCommunicationError("Invalid channel for " + getName()));
}
if (basicPackets.length == 0) {
return new Result(query, ErrorMessage.createBackendCommunicationError(getName() + " got no packets back"));
}
if (isLoggingFine())
getLogger().finest("got packets " + basicPackets.length + " packets");
ensureInstanceOf(QueryResultPacket.class, basicPackets[0], getName());
QueryResultPacket resultPacket = (QueryResultPacket) basicPackets[0];
if (isLoggingFine())
getLogger().finest("got query packet. " + "docsumClass=" + query.getPresentation().getSummary());
if (query.getPresentation().getSummary() == null)
query.getPresentation().setSummary(getDefaultDocsumClass());
Result result = new Result(query);
addMetaInfo(query, queryPacket.getQueryPacketData(), resultPacket, result, false);
addUnfilledHits(result, resultPacket.getDocuments(), false, queryPacket.getQueryPacketData(), cacheKey);
Packet[] packets;
PacketWrapper packetWrapper = cacheControl.lookup(cacheKey, query);
if (packetWrapper != null) {
cacheControl.updateCacheEntry(cacheKey, query, resultPacket);
} else {
if (resultPacket.getCoverageFeature() && !resultPacket.getCoverageFull()) {
// Don't add error here, it was done in first phase
// No check if packetWrapper already exists, since incomplete
// first phase data won't be cached anyway.
} else {
packets = new Packet[1];
packets[0] = resultPacket;
cacheControl.cache(cacheKey, query, new DocsumPacketKey[0], packets);
}
}
return result;
}
use of com.yahoo.fs4.QueryPacket in project vespa by vespa-engine.
the class VespaBackEndSearcher method search.
public Result search(Query query, Execution execution) {
// query root should not be null here
Item root = query.getModel().getQueryTree().getRoot();
if (root == null || root instanceof NullItem) {
return new Result(query, ErrorMessage.createNullQuery(query.getHttpRequest().getUri().toString()));
}
if (wantsRPCSummaryFill(query) && summaryNeedsQuery(query)) {
return new Result(query, ErrorMessage.createInvalidQueryParameter("When using dispatch.summaries and your summary/rankprofile require the query, " + " you need to enable ranking.queryCache."));
}
QueryRewrite.optimizeByRestrict(query);
QueryRewrite.optimizeAndNot(query);
QueryRewrite.collapseSingleComposites(query);
root = query.getModel().getQueryTree().getRoot();
if (// root can become null after optimization
root == null || root instanceof NullItem)
return new Result(query);
resolveDocumentDatabase(query);
transformQuery(query);
traceQuery(name, "search", query, query.getOffset(), query.getHits(), 1, Optional.empty());
root = query.getModel().getQueryTree().getRoot();
if (// root can become null after resolving and transformation?
root == null || root instanceof NullItem)
return new Result(query);
QueryPacket queryPacket = QueryPacket.create(query);
int compressionLimit = query.properties().getInteger(PACKET_COMPRESSION_LIMIT, 0);
queryPacket.setCompressionLimit(compressionLimit);
if (compressionLimit != 0)
queryPacket.setCompressionType(query.properties().getString(PACKET_COMPRESSION_TYPE, "lz4"));
if (isLoggingFine())
getLogger().fine("made QueryPacket: " + queryPacket);
Result result = null;
CacheKey cacheKey = null;
if (cacheControl.useCache(query)) {
cacheKey = new CacheKey(queryPacket);
result = getCached(cacheKey, queryPacket.getQueryPacketData(), query);
}
if (result == null) {
result = doSearch2(query, queryPacket, cacheKey, execution);
if (isLoggingFine())
getLogger().fine("Result NOT retrieved from cache");
if (query.getTraceLevel() >= 1)
query.trace(getName() + " dispatch response: " + result, false, 1);
result.trace(getName());
}
return result;
}
use of com.yahoo.fs4.QueryPacket in project vespa by vespa-engine.
the class PacketTestCase method requireThatUncompressablePacketsArentCompressed.
@Test
public void requireThatUncompressablePacketsArentCompressed() throws BufferTooSmallException {
QueryPacket queryPacket = QueryPacket.create(new Query("/?query=aaaaaaaaaaaaaaa"));
ByteBuffer buffer = ByteBuffer.allocate(1024);
int channel = 32;
queryPacket.setCompressionLimit(10);
buffer.clear();
queryPacket.encode(buffer, channel);
buffer.flip();
// size
assertEquals(56, buffer.getInt());
// code
assertEquals(0xda, buffer.getInt());
assertEquals(channel, buffer.getInt());
}
use of com.yahoo.fs4.QueryPacket 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);
}
Aggregations