private void setVisitorParameters(Route route, Visitor.Context context) {
        params.setDocumentSelection(createSelectionString(context.schema(), createQuerySelectionString()));
        params.setTimeoutMs(query.getTimeout()); // Per bucket visitor timeout
        params.setSessionTimeoutMs(query.getTimeout());
        params.setVisitorLibrary("searchvisitor");
        params.setLocalDataHandler(this);
        if (query.properties().getDouble(streamingFromtimestamp) != null) {
            params.setFromTimestamp(query.properties().getDouble(streamingFromtimestamp).longValue());
        }
        if (query.properties().getDouble(streamingTotimestamp) != null) {
            params.setToTimestamp(query.properties().getDouble(streamingTotimestamp).longValue());
        }
        params.setFieldSet(AllFields.NAME); // Streaming searches need to look at _all_ fields by default.
        params.visitInconsistentBuckets(true);
        params.setPriority(DocumentProtocol.Priority.VERY_HIGH);

        if (query.properties().getString(streamingPriority) != null) {
            params.setPriority(DocumentProtocol.getPriorityByName(
                    query.properties().getString(streamingPriority)));
        }

        params.setMaxPending(Integer.MAX_VALUE);
        params.setMaxBucketsPerVisitor(MAX_BUCKETS_PER_VISITOR);
        params.setTraceLevel(inferSessionTraceLevel(query));

        String maxbuckets = query.properties().getString(streamingMaxbucketspervisitor);
        if (maxbuckets != null) {
            params.setMaxBucketsPerVisitor(Integer.parseInt(maxbuckets));
        }

        EncodedData ed = new EncodedData();
        encodeQueryData(query, 0, ed);
        params.setLibraryParameter("query", ed.getEncodedData());
        params.setLibraryParameter("querystackcount", String.valueOf(ed.getReturned()));
        params.setLibraryParameter("searchcluster", context.searchCluster().getBytes(StandardCharsets.UTF_8));
        params.setLibraryParameter("schema", context.schema().getBytes(StandardCharsets.UTF_8));

        var partialSummaryHandler = context.partialSummaryHandler();
        if (partialSummaryHandler != null) {
            params.setLibraryParameter("summaryclass", partialSummaryHandler.askForSummary());
            var summaryFields = partialSummaryHandler.askForFields();
            if (summaryFields != null) {
                params.setLibraryParameter("summary-fields", String.join(" ", summaryFields));
            }
        } else {
            String wantedSummary = query.getPresentation().getSummary();
            Set<String> summaryFields = query.getPresentation().getSummaryFields();
            boolean wantSomeFields = summaryFields != null && !summaryFields.isEmpty();
            if (wantedSummary == null || wantedSummary.equals("default")) {
                params.setLibraryParameter("summaryclass", "default");
                if (wantSomeFields) {
                    params.setLibraryParameter("summary-fields", String.join(" ", summaryFields));
                }
            } else {
                params.setLibraryParameter("summaryclass", wantedSummary);
            }
        }
        params.setLibraryParameter("summarycount", String.valueOf(query.getOffset() + query.getHits()));
        params.setLibraryParameter("rankprofile", query.getRanking().getProfile());
        params.setLibraryParameter("allowslimedocsums", "true");
        params.setLibraryParameter("queryflags", String.valueOf(getQueryFlags(query)));

        ByteBuffer buf = ByteBuffer.allocate(1024);

        if (query.getRanking().getLocation() != null) {
            buf.clear();
            query.getRanking().getLocation().encode(buf);
            buf.flip();
            byte[] af = new byte [buf.remaining()];
            buf.get(af);
            params.setLibraryParameter("location", af);
        }

        if (QueryEncoder.hasEncodableProperties(query)) {
            encodeQueryData(query, 1, ed);
            params.setLibraryParameter("rankproperties", ed.getEncodedData());
        }

        List<Grouping> groupingList = GroupingExecutor.getGroupingList(query);
        if ( ! groupingList.isEmpty()){
            BufferSerializer gbuf = new BufferSerializer(new GrowableByteBuffer());
            gbuf.putInt(null, groupingList.size());
            for(Grouping g: groupingList){
                g.serialize(gbuf);
            }
            gbuf.flip();
            byte [] blob = gbuf.getBytes(null, gbuf.getBuf().limit());
            params.setLibraryParameter("aggregation", blob);
        }

        if (query.getRanking().getSorting() != null) {
            encodeQueryData(query, 3, ed);
            params.setLibraryParameter("sort", ed.getEncodedData());
        }

        params.setRoute(route);
    }
A visitor data handler that performs a query in a content cluster with the
searchvisitor visitor plugin. It collects and merges hits (sorted
descending on rank), summaries (sorted on document id), and
groupings. The resulting data can be fetched when the query has
completed.

@author Ulf Carlin
container-search/src/main/java/com/yahoo/vespa/streamingvisitors/StreamingVisitor.java