use of org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig in project cineast by vitrivr.
the class FindSegmentSimilarStagedPostHandler method performPost.
@Override
public SimilarityQueryResultBatch performPost(StagedSimilarityQuery query, Context ctx) {
ConstrainedQueryConfig config = ConstrainedQueryConfig.getApplyingConfig(query.getConfig());
var results = QueryUtil.findSegmentsSimilarStaged(continuousRetrievalLogic, query.getStages(), config);
return new SimilarityQueryResultBatch(results, config.getQueryId().toString());
}
use of org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig in project cineast by vitrivr.
the class CliUtils method retrieveAndLog.
public static void retrieveAndLog(List<Retriever> retrievers, ContinuousRetrievalLogic retrieval, int limit, boolean printDetail, AbstractQueryTermContainer qc) {
System.out.println("Only printing the first " + limit + " results, change with --limit parameter");
DBSelector selector = Config.sharedConfig().getDatabase().getSelectorSupplier().get();
retrievers.forEach(retriever -> {
AtomicBoolean entityExists = new AtomicBoolean(true);
retriever.getTableNames().forEach(table -> {
if (!selector.existsEntity(table)) {
System.out.println("Entity " + table + " does not exist");
entityExists.set(false);
}
});
if (!entityExists.get()) {
System.out.println("Not retrieving for " + retriever.getClass().getSimpleName() + " because entity does not exist");
return;
}
System.out.println("Retrieving for " + retriever.getClass().getSimpleName());
long start = System.currentTimeMillis();
List<SegmentScoreElement> results = retrieval.retrieveByRetriever(qc, retriever, new ConstrainedQueryConfig().setMaxResults(limit));
long stop = System.currentTimeMillis();
System.out.println("Results for " + retriever.getClass().getSimpleName() + ":, retrieved in " + (stop - start) + "ms");
for (SegmentScoreElement e : results) {
System.out.print(e.getSegmentId());
System.out.print(": ");
System.out.println(e.getScore());
if (printDetail) {
CliUtils.printInfoForSegment(e.getSegmentId(), selector, null, true);
}
}
System.out.println();
});
retrieval.shutdown();
}
use of org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig in project cineast by vitrivr.
the class AbstractQueryMessageHandler method handle.
/**
* Handles a {@link Query} message
*
* @param session WebSocketSession for which the message arrived.
* @param message Message of type a that needs to be handled.
*/
public final void handle(Session session, T message) {
if (message == null) {
LOGGER.warn("Received null message. Ignoring.");
return;
}
try {
final QueryConfig qconf = new ConstrainedQueryConfig(message.getQueryConfig());
final String uuid = qconf.getQueryId().toString();
final int max = Math.min(qconf.getMaxResults().orElse(Config.sharedConfig().getRetriever().getMaxResults()), Config.sharedConfig().getRetriever().getMaxResults());
qconf.setMaxResults(max);
final int resultsPerModule = Math.min(qconf.getRawResultsPerModule() == -1 ? Config.sharedConfig().getRetriever().getMaxResultsPerModule() : qconf.getResultsPerModule(), Config.sharedConfig().getRetriever().getMaxResultsPerModule());
qconf.setResultsPerModule(resultsPerModule);
String qid = uuid.substring(0, 3);
Thread.currentThread().setName("query-msg-handler-" + uuid.substring(0, 3));
try {
/* Begin of Query: Send QueryStart Message to Client.
* We could wait for future-completion here, but there will likely never be a case where a simple write would fall behind the first message we send to the client.
* Additionally, QR_START is informational - the client already knows that they sent a request.
*/
this.write(session, new QueryStart(uuid));
/* Execute actual query. */
LOGGER.trace("Executing query with id {} from message {}", qid, message);
final Set<String> segmentIdsForWhichMetadataIsFetched = new HashSet<>();
final Set<String> objectIdsForWhichMetadataIsFetched = new HashSet<>();
this.execute(session, qconf, message, segmentIdsForWhichMetadataIsFetched, objectIdsForWhichMetadataIsFetched);
} catch (Exception e) {
/* Error: Send QueryError Message to Client. */
LOGGER.error("An exception occurred during execution of similarity query message {}.", LogHelper.getStackTrace(e));
this.write(session, new QueryError(uuid, e.getMessage()));
return;
}
/* End of Query: Send QueryEnd Message to Client. */
this.write(session, new QueryEnd(uuid));
} catch (Throwable t) {
t.printStackTrace();
}
}
use of org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig in project cineast by vitrivr.
the class FindSegmentSimilarPostHandler method performPost.
@Override
public SimilarityQueryResultBatch performPost(SimilarityQuery query, Context ctx) {
ConstrainedQueryConfig config = ConstrainedQueryConfig.getApplyingConfig(query.getQueryConfig());
var returnMap = QueryUtil.findSegmentsSimilar(continuousRetrievalLogic, query.getTerms(), config);
return new SimilarityQueryResultBatch(returnMap, config.getQueryId().toString());
}
use of org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig in project cineast by vitrivr.
the class FindSegmentSimilarTemporalPostHandler method performPost.
@Override
public TemporalQueryResult performPost(TemporalQuery query, Context ctx) {
ConstrainedQueryConfig config = ConstrainedQueryConfig.getApplyingConfig(query.getQueryConfig());
var temporalResults = QueryUtil.findSegmentsSimilarTemporal(continuousRetrievalLogic, query, config);
return new TemporalQueryResult(config.getQueryId().toString(), temporalResults);
}
Aggregations