Created
May 7, 2024 13:16
-
-
Save andreer/055f0d698c19eb96f44fa8ceebcaf763 to your computer and use it in GitHub Desktop.
RankProfileListHandler example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. | |
package ai.vespa.example; | |
import com.google.inject.Inject; | |
import com.yahoo.container.jdisc.HttpRequest; | |
import com.yahoo.container.jdisc.HttpResponse; | |
import com.yahoo.container.jdisc.ThreadedHttpRequestHandler; | |
import com.yahoo.jdisc.Metric; | |
import com.yahoo.search.schema.SchemaInfo; | |
import java.io.IOException; | |
import java.io.OutputStream; | |
import java.nio.charset.StandardCharsets; | |
import java.util.concurrent.Executor; | |
public class RankProfileListHandler extends ThreadedHttpRequestHandler { | |
private final SchemaInfo schemaInfo; | |
@Inject | |
public RankProfileListHandler(Executor executor, Metric metrics, SchemaInfo schemaInfo) { | |
super(executor, metrics, true); | |
this.schemaInfo = schemaInfo; | |
} | |
@Override | |
public HttpResponse handle(HttpRequest request) { | |
return new HttpResponse(200) { | |
@Override | |
public void render(OutputStream outputStream) throws IOException { | |
String rankProfiles = String.join(", ", | |
schemaInfo.schemas().get("music").rankProfiles().keySet().stream() | |
.map(s -> '"' + s + '"').toList()); | |
outputStream.write(("{\"rank-profiles\": [" + rankProfiles + "]}\n").getBytes(StandardCharsets.UTF_8)); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment