Skip to content

Commit

Permalink
#85 Changing placeholder to OpenSearch placeholder.
Browse files Browse the repository at this point in the history
Signed-off-by: jzonthemtn <[email protected]>
  • Loading branch information
jzonthemtn committed Feb 4, 2025
1 parent 9a6aa24 commit eb5f0ee
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 159 deletions.
4 changes: 2 additions & 2 deletions scripts/hybrid_query.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
{
"match": {
"title_text": {
"query": "#$query##"
"query": "%SearchText%"
}
}
},
{
"neural": {
"title_embedding": {
"query_text": "#$query##",
"query_text": "%SearchText%",
"k": 50
}
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/run-query-set.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"id_field": "asin",
"k": 10,
"threshold": 1.0,
"query": "{\"_source\": {\"excludes\": [\"title_embedding\"]},\"query\": {\"hybrid\": {\"queries\": [{\"match\": {\"title_text\": {\"query\": \"#$query##\"}}},{\"neural\": {\"title_embedding\": {\"query_text\": \"#$query##\",\"k\": 50}}}]}}}",
"not_used_query": "{\"query\": {\"match\": {\"description\": \"#$query##\"}}}"
"query": "{\"_source\": {\"excludes\": [\"title_embedding\"]},\"query\": {\"hybrid\": {\"queries\": [{\"match\": {\"title_text\": {\"query\": \"%SearchText%\"}}},{\"neural\": {\"title_embedding\": {\"query_text\": \"%SearchText%\",\"k\": 50}}}]}}}",
"not_used_query": "{\"query\": {\"match\": {\"description\": \"%SearchText%\"}}}"
}
154 changes: 0 additions & 154 deletions src/main/java/org/opensearch/eval/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,158 +149,4 @@ public static void main(String[] args) throws Exception {

}

//
// /**
// * The placeholder in the query that gets replaced by the query term when running a query set.
// */
// public static final String QUERY_PLACEHOLDER = "#$query##";
//
// @Override
// protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
//
// // Handle managing query sets.
// if(QUERYSET_MANAGEMENT_URL.equalsIgnoreCase(request.path())) {
//
// // Creating a new query set by sampling the UBI queries.
// if (request.method().equals(RestRequest.Method.POST)) {
//
// final String name = request.param("name");
// final String description = request.param("description");
// final String sampling = request.param("sampling", "pptss");
// final int querySetSize = Integer.parseInt(request.param("query_set_size", "1000"));
//
// // Create a query set by finding all the unique user_query terms.
// if (AllQueriesQuerySampler.NAME.equalsIgnoreCase(sampling)) {
//
// // If we are not sampling queries, the query sets should just be directly
// // indexed into OpenSearch using the `ubi_queries` index directly.
//
// try {
//
// final AllQueriesQuerySamplerParameters parameters = new AllQueriesQuerySamplerParameters(name, description, sampling, querySetSize);
// final AllQueriesQuerySampler sampler = new AllQueriesQuerySampler(client, parameters);
//
// // Sample and index the queries.
// final String querySetId = sampler.sample();
//
// return restChannel -> restChannel.sendResponse(new BytesRestResponse(RestStatus.OK, "{\"query_set\": \"" + querySetId + "\"}"));
//
// } catch(Exception ex) {
// return restChannel -> restChannel.sendResponse(new BytesRestResponse(RestStatus.INTERNAL_SERVER_ERROR, "{\"error\": \"" + ex.getMessage() + "\"}"));
// }


// // Handle the on-demand creation of implicit judgments.
// } else if(IMPLICIT_JUDGMENTS_URL.equalsIgnoreCase(request.path())) {
//
// if (request.method().equals(RestRequest.Method.POST)) {
//
// //final long startTime = System.currentTimeMillis();
// final String clickModel = request.param("click_model", "coec");
// final int maxRank = Integer.parseInt(request.param("max_rank", "20"));
//
// if (CoecClickModel.CLICK_MODEL_NAME.equalsIgnoreCase(clickModel)) {
//
// final CoecClickModelParameters coecClickModelParameters = new CoecClickModelParameters(maxRank);
// final CoecClickModel coecClickModel = new CoecClickModel(client, coecClickModelParameters);
//
// final String judgmentsId;
//
// // TODO: Run this in a separate thread.
// try {
//
// // Create the judgments index.
// createJudgmentsIndex(client);
//
// judgmentsId = coecClickModel.calculateJudgments();
//
// // judgmentsId will be null if no judgments were created (and indexed).
// if(judgmentsId == null) {
// // TODO: Is Bad Request the appropriate error? Perhaps Conflict is more appropriate?
// return restChannel -> restChannel.sendResponse(new BytesRestResponse(RestStatus.BAD_REQUEST, "{\"error\": \"No judgments were created. Check the queries and events data.\"}"));
// }
//
//// final long elapsedTime = System.currentTimeMillis() - startTime;
////
//// final Map<String, Object> job = new HashMap<>();
//// job.put("name", "manual_generation");
//// job.put("click_model", clickModel);
//// job.put("started", startTime);
//// job.put("duration", elapsedTime);
//// job.put("invocation", "on_demand");
//// job.put("judgments_id", judgmentsId);
//// job.put("max_rank", maxRank);
////
//// final String jobId = UUID.randomUUID().toString();
////
//// final IndexRequest indexRequest = new IndexRequest()
//// .index(SearchQualityEvaluationPlugin.COMPLETED_JOBS_INDEX_NAME)
//// .id(jobId)
//// .source(job)
//// .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
////
//// client.index(indexRequest, new ActionListener<>() {
//// @Override
//// public void onResponse(final IndexResponse indexResponse) {
//// LOGGER.debug("Click model job completed successfully: {}", jobId);
//// }
////
//// @Override
//// public void onFailure(final Exception ex) {
//// LOGGER.error("Unable to run job with ID {}", jobId, ex);
//// throw new RuntimeException("Unable to run job", ex);
//// }
//// });
//
// } catch (Exception ex) {
// throw new RuntimeException("Unable to generate judgments.", ex);
// }
//
// return restChannel -> restChannel.sendResponse(new BytesRestResponse(RestStatus.OK, "{\"judgments_id\": \"" + judgmentsId + "\"}"));
//
// } else {
// return restChannel -> restChannel.sendResponse(new BytesRestResponse(RestStatus.BAD_REQUEST, "{\"error\": \"Invalid click model.\"}"));
// }
//
// } else {
// return restChannel -> restChannel.sendResponse(new BytesRestResponse(RestStatus.METHOD_NOT_ALLOWED, "{\"error\": \"" + request.method() + " is not allowed.\"}"));
// }
//
// } else {
// return restChannel -> restChannel.sendResponse(new BytesRestResponse(RestStatus.NOT_FOUND, "{\"error\": \"" + request.path() + " was not found.\"}"));
// }
//
// }
//
// private void createJudgmentsIndex(final NodeClient client) throws Exception {
//
// // If the judgments index does not exist we need to create it.
// final IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest(Constants.JUDGMENTS_INDEX_NAME);
//
// final IndicesExistsResponse indicesExistsResponse = client.admin().indices().exists(indicesExistsRequest).get();
//
// if(!indicesExistsResponse.isExists()) {
//
// // TODO: Read this mapping from a resource file instead.
// final String mapping = "{\n" +
// " \"properties\": {\n" +
// " \"judgments_id\": { \"type\": \"keyword\" },\n" +
// " \"query_id\": { \"type\": \"keyword\" },\n" +
// " \"query\": { \"type\": \"keyword\" },\n" +
// " \"document_id\": { \"type\": \"keyword\" },\n" +
// " \"judgment\": { \"type\": \"double\" },\n" +
// " \"timestamp\": { \"type\": \"date\", \"format\": \"strict_date_time\" }\n" +
// " }\n" +
// " }";
//
// // Create the judgments index.
// final CreateIndexRequest createIndexRequest = new CreateIndexRequest(Constants.JUDGMENTS_INDEX_NAME).mapping(mapping);
//
// // TODO: Don't use .get()
// client.admin().indices().create(createIndexRequest).get();
//
// }
//
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class OpenSearchQuerySetRunner extends AbstractQuerySetRunner {

private static final Logger LOGGER = LogManager.getLogger(OpenSearchQuerySetRunner.class);

public static final String QUERY_PLACEHOLDER = "#$query##";
public static final String QUERY_PLACEHOLDER = "%SearchText%";

/**
* Creates a new query set runner
Expand Down

0 comments on commit eb5f0ee

Please sign in to comment.