@Override public void fill(Result result, String summaryClass, Execution execution) { int worstCase = result.getHitCount(); List<Hit> hits = new ArrayList<>(worstCase); for (Iterator<Hit> i = result.hits().deepIterator(); i.hasNext();) { Hit sniffHit = i.next(); if ( ! (sniffHit instanceof FastHit)) continue; FastHit hit = (FastHit) sniffHit; if (hit.isFilled(summaryClass)) continue; hits.add(hit); } execution.fill(result, summaryClass); highlight(result.getQuery().getPresentation().getBolding(), hits.iterator(), summaryClass, execution.context().getIndexFacts().newSession(result.getQuery())); }
public boolean hasEncodableProperties() { if ( ! ranking.getProperties().isEmpty()) return true; if ( ! ranking.getFeatures().isEmpty()) return true; if ( ranking.getFreshness() != null) return true; if ( model.getSearchPath() != null) return true; if ( model.getDocumentDb() != null) return true; if ( presentation.getHighlight() != null && ! presentation.getHighlight().getHighlightItems().isEmpty()) return true; return false; }
private byte[] getSummaryClassAsUtf8() { if (query.getPresentation().getSummary() != null) { return Utf8.toBytes(query.getPresentation().getSummary()); } return new byte[0]; }
private Result cacheLookupFirstPhase(CacheKey key, QueryPacketData queryPacketData, Query query, int offset, int hits, String summaryClass) { PacketWrapper packetWrapper = cacheControl.lookup(key, query); if (packetWrapper == null) return null; // Check if the cache entry contains the requested hits List<DocumentInfo> documents = packetWrapper.getDocuments(offset, hits); if (documents == null) return null; if (query.getPresentation().getSummary() == null) query.getPresentation().setSummary(getDefaultDocsumClass()); Result result = new Result(query); QueryResultPacket resultPacket = packetWrapper.getFirstResultPacket(); addMetaInfo(query, queryPacketData, resultPacket, result); if (packetWrapper.getNumPackets() == 0) addUnfilledHits(result, documents, true, queryPacketData, key, packetWrapper.distributionKey()); else addCachedHits(result, packetWrapper, summaryClass, documents); return result; }
if (key.last().equals(Presentation.BOLDING)) return query.getPresentation().getBolding(); if (key.last().equals(Presentation.SUMMARY)) return query.getPresentation().getSummary(); if (key.last().equals(Presentation.FORMAT)) return query.getPresentation().getFormat(); if (key.last().equals(Presentation.TIMING)) return query.getPresentation().getTiming(); if (key.last().equals(Presentation.SUMMARY_FIELDS)) return query.getPresentation().getSummaryFields();
/** Used from container SDK, for internal use only */ public Result searchAndFill(Query query, Chain<? extends Searcher> searchChain, SearchChainRegistry registry) { Result errorResult = validateQuery(query); if (errorResult != null) return errorResult; Renderer<Result> renderer = rendererRegistry.getRenderer(query.getPresentation().getRenderer()); // docsumClass null means "unset", so we set it (it might be null // here too in which case it will still be "unset" after we set it :-) if (query.getPresentation().getSummary() == null && renderer instanceof com.yahoo.search.rendering.Renderer) query.getPresentation().setSummary(((com.yahoo.search.rendering.Renderer) renderer).getDefaultSummaryClass()); Execution execution = new Execution(searchChain, new Execution.Context(registry, indexFacts, specialTokens, rendererRegistry, linguistics)); query.getModel().setExecution(execution); execution.trace().setForceTimestamps(query.properties().getBoolean(FORCE_TIMESTAMPS, false)); if (query.properties().getBoolean(DETAILED_TIMING_LOGGING, false)) { // check and set (instead of set directly) to avoid overwriting stuff from prepareForBreakdownAnalysis() execution.context().setDetailedDiagnostics(true); } Result result = execution.search(query); ensureQuerySet(result, query); execution.fill(result, result.getQuery().getPresentation().getSummary()); traceExecutionTimes(query, result); traceVespaVersion(query); traceRequestAttributes(query); return result; }
private void filter(Result result) { Set<String> requestedFields; if (result.getQuery().properties().getBoolean(FIELD_FILTER_DISABLE)) return; if (result.getQuery().getPresentation().getSummaryFields().isEmpty()) return; requestedFields = result.getQuery().getPresentation().getSummaryFields(); for (Iterator<Hit> i = result.hits().unorderedDeepIterator(); i.hasNext();) { Hit h = i.next(); if (h.isMeta()) continue; h.fieldKeys().retainAll(requestedFields); } }
private void renderTime(XMLWriter writer, Result result) { if ( ! result.getQuery().getPresentation().getTiming()) return; final String threeDecimals = "%.3f"; final double milli = .001d; final long now = System.currentTimeMillis(); final long searchTime = now - result.getElapsedTime().first(); final double searchSeconds = ((double) searchTime) * milli; if (result.getElapsedTime().firstFill() != 0L) { final long queryTime = result.getElapsedTime().weightedSearchTime(); final long summaryFetchTime = result.getElapsedTime().weightedFillTime(); final double querySeconds = ((double) queryTime) * milli; final double summarySeconds = ((double) summaryFetchTime) * milli; writer.attribute(QUERY_TIME, String.format(threeDecimals, querySeconds)); writer.attribute(SUMMARY_FETCH_TIME, String.format(threeDecimals, summarySeconds)); } writer.attribute(SEARCH_TIME, String.format(threeDecimals, searchSeconds)); }
/** Returns whether the given query is equal to this */ @Override public boolean equals(Object other) { if (this == other) return true; if ( ! (other instanceof Query)) return false; Query q = (Query) other; if (getOffset() != q.getOffset()) return false; if (getHits() != q.getHits()) return false; if ( ! getPresentation().equals(q.getPresentation())) return false; if ( ! getRanking().equals(q.getRanking())) return false; if ( ! getModel().equals(q.getModel())) return false; // TODO: Compare property settings return true; }
public static void addNativeQueryProfileTypesTo(QueryProfileTypeRegistry registry) { // Add modifiable copies to allow query profile types in this to add to these registry.register(Query.getArgumentType().unfrozen()); registry.register(Ranking.getArgumentType().unfrozen()); registry.register(Model.getArgumentType().unfrozen()); registry.register(Select.getArgumentType().unfrozen()); registry.register(Presentation.getArgumentType().unfrozen()); registry.register(DefaultProperties.argumentType.unfrozen()); }
private void copyPropertiesTo(Query clone) { clone.model = model.cloneFor(clone); clone.select = select.cloneFor(clone); clone.ranking = (Ranking) ranking.clone(); clone.presentation = (Presentation) presentation.clone(); clone.context = getContext(true).cloneFor(clone); // Correct the Query instance in properties clone.properties().setParentQuery(clone); assert (clone.properties().getParentQuery() == clone); clone.setTraceLevel(getTraceLevel()); clone.setHits(getHits()); clone.setOffset(getOffset()); clone.setNoCache(getNoCache()); clone.setGroupingSessionCache(getGroupingSessionCache()); clone.requestId = null; // Each clone should have their own requestId. }
Renderer renderer = toRendererCopy(query.getPresentation().getRenderer()); HttpSearchResponse response = new HttpSearchResponse(getHttpResponseStatus(request, result), result, query, renderer);
getLogger().finest("got query packet. " + "docsumClass=" + query.getPresentation().getSummary()); if (query.getPresentation().getSummary() == null) query.getPresentation().setSummary(searcher.getDefaultDocsumClass());
Set<String> fields = getPresentation().getSummaryFields(); StringBuilder yql = new StringBuilder("select "); if (fields.isEmpty()) {
private void renderTime(XMLWriter writer, Result result) { if (!result.getQuery().getPresentation().getTiming()) { return; } final String threeDecimals = "%.3f"; final double milli = .001d; final long now = System.currentTimeMillis(); final long searchTime = now - result.getQuery().getStartTime(); final double searchSeconds = ((double) searchTime) * milli; if (result.getElapsedTime().firstFill() != 0L) { final long queryTime = result.getElapsedTime().firstFill() - result.getQuery().getStartTime(); final long summaryFetchTime = now - result.getElapsedTime().firstFill(); final double querySeconds = ((double) queryTime) * milli; final double summarySeconds = ((double) summaryFetchTime) * milli; writer.attribute(QUERY_TIME, String.format(threeDecimals, querySeconds)); writer.attribute(SUMMARY_FETCH_TIME, String.format(threeDecimals, summarySeconds)); } writer.attribute(SEARCH_TIME, String.format(threeDecimals, searchSeconds)); }
protected void storeID(Hit hit, Execution execution) { String id = getProperty(hit, blendingField); if (id != null) { documentsToStrip.add(id); } else { if (!result.isFilled(result.getQuery().getPresentation().getSummary())) { fill(result, result.getQuery().getPresentation().getSummary(), execution); id = getProperty(hit, blendingField); if (id != null) { documentsToStrip.add(id); } } } }
query.getPresentation().getSummary(), ", default docsum class=", getDefaultDocsumClass()); if (query.getPresentation().getSummary() == null) { lazyTrace(query, 6, "doSearch2(): No summary class specified in query, using default: ", getDefaultDocsumClass()); query.getPresentation().setSummary(getDefaultDocsumClass()); } else { lazyTrace(query, 6, "doSearch2(): Summary class has been specified in query: ", query.getPresentation().getSummary()); if (result.isFilled(query.getPresentation().getSummary())) { lazyTrace(query, 8, "Result is filled for summary class ", query.getPresentation().getSummary()); } else { lazyTrace(query, 8, "Result is not filled for summary class ", query.getPresentation().getSummary()); FillHitsResult fillHitsResult = fillHits(result, summaryPackets, query.getPresentation().getSummary()); skippedHits = fillHitsResult.skippedHits; if (fillHitsResult.error != null) {
/** * Encodes properties of this query. * * @param buffer the buffer to encode to * @param encodeQueryData true to encode all properties, false to only include session information, not actual query data * @return the encoded length */ public int encodeAsProperties(ByteBuffer buffer, boolean encodeQueryData) { // Make sure we don't encode anything here if we have turned the property feature off // Due to sendQuery we sometimes end up turning this feature on and then encoding a 0 int as the number of // property maps - that's ok (probably we should simplify by just always turning the feature on) if (! hasEncodableProperties()) return 0; int start = buffer.position(); int mapCountPosition = buffer.position(); buffer.putInt(0); // map count will go here int mapCount = 0; // TODO: Push down mapCount += ranking.getProperties().encode(buffer, encodeQueryData); if (encodeQueryData) mapCount += ranking.getFeatures().encode(buffer); // TODO: Push down if (encodeQueryData && presentation.getHighlight() != null) mapCount += MapEncoder.encodeStringMultiMap(Highlight.HIGHLIGHTTERMS, presentation.getHighlight().getHighlightTerms(), buffer); // TODO: Push down if (encodeQueryData) mapCount += MapEncoder.encodeSingleValue("model", "searchpath", model.getSearchPath(), buffer); mapCount += MapEncoder.encodeSingleValue(DocumentDatabase.MATCH_PROPERTY, DocumentDatabase.SEARCH_DOC_TYPE_KEY, model.getDocumentDb(), buffer); mapCount += MapEncoder.encodeMap("caches", createCacheSettingMap(), buffer); buffer.putInt(mapCountPosition, mapCount); return buffer.position() - start; }
@Override public void fill(Result result, String summaryClass, Execution execution) { execution.fill(result, summaryClass); Set<String> summaryFields = result.getQuery().getPresentation().getSummaryFields(); if (summaryFields.isEmpty() || summaryClass == null || result.getQuery().properties().getBoolean(FIELD_FILLER_DISABLE)) { return; } if (intersectionOfAttributes.containsAll(summaryFields)) { if ( ! Execution.ATTRIBUTEPREFETCH.equals(summaryClass)) { execution.fill(result, Execution.ATTRIBUTEPREFETCH); } } else { // Yes, summaryClass may be Execution.ATTRIBUTEPREFETCH here if ( ! summaryDb.hasAll(summaryFields, summaryClass, result.getQuery().getModel().getRestrict())) { execution.fill(result, null); } } }
private void renderTiming() throws IOException { if (!getResult().getQuery().getPresentation().getTiming()) return; double milli = .001d; long now = timeSource.getAsLong(); long searchTime = now - getResult().getElapsedTime().first(); double searchSeconds = searchTime * milli; generator.writeObjectFieldStart(TIMING); if (getResult().getElapsedTime().firstFill() != 0L) { long queryTime = getResult().getElapsedTime().weightedSearchTime(); long summaryFetchTime = getResult().getElapsedTime().weightedFillTime(); double querySeconds = queryTime * milli; double summarySeconds = summaryFetchTime * milli; generator.writeNumberField(QUERY_TIME, querySeconds); generator.writeNumberField(SUMMARY_FETCH_TIME, summarySeconds); } generator.writeNumberField(SEARCH_TIME, searchSeconds); generator.writeEndObject(); }