use of com.yelp.nrtsearch.server.grpc.GrpcServer in project nrtsearch by Yelp.
the class ScoreScriptTest method testScriptDocValuesIndexField.
@Test
public void testScriptDocValuesIndexField() throws Exception {
GrpcServer.TestServer testAddDocs = new GrpcServer.TestServer(grpcServer, false, Mode.STANDALONE);
new GrpcServer.IndexAndRoleManager(grpcServer).createStartIndexAndRegisterFields(Mode.STANDALONE, 0, false, "registerFieldsScriptTest.json");
AddDocumentResponse addDocumentResponse = testAddDocs.addDocuments("addDocs.csv");
// manual refresh
grpcServer.getBlockingStub().refresh(RefreshRequest.newBuilder().setIndexName(grpcServer.getTestIndex()).build());
SearchResponse searchResponse = grpcServer.getBlockingStub().search(SearchRequest.newBuilder().setIndexName(grpcServer.getTestIndex()).addRetrieveFields("test_doc_values").setStartHit(0).setTopHits(10).build());
assertEquals(2, searchResponse.getHitsCount());
assertEquals(1.5, searchResponse.getHits(0).getFieldsOrThrow("test_doc_values").getFieldValue(0).getDoubleValue(), Math.ulp(1.5));
assertEquals(1.5, searchResponse.getHits(1).getFieldsOrThrow("test_doc_values").getFieldValue(0).getDoubleValue(), Math.ulp(1.5));
}
use of com.yelp.nrtsearch.server.grpc.GrpcServer in project nrtsearch by Yelp.
the class ScoreScriptTest method testScriptUsingScore.
@Test
public void testScriptUsingScore() throws Exception {
GrpcServer.TestServer testAddDocs = new GrpcServer.TestServer(grpcServer, true, Mode.STANDALONE);
// 2 docs addDocuments
testAddDocs.addDocuments();
// manual refresh
grpcServer.getBlockingStub().refresh(RefreshRequest.newBuilder().setIndexName(grpcServer.getTestIndex()).build());
VirtualField virtualField = VirtualField.newBuilder().setName("test_field").setScript(Script.newBuilder().setLang("test_lang").setSource("verify_score").build()).build();
SearchResponse searchResponse = grpcServer.getBlockingStub().search(SearchRequest.newBuilder().setIndexName(grpcServer.getTestIndex()).setStartHit(0).setTopHits(10).addVirtualFields(virtualField).addRetrieveFields("test_field").setQueryText("vendor_name:first vendor").build());
assertEquals(2, searchResponse.getHitsCount());
assertEquals(2.0, searchResponse.getHits(0).getFieldsOrThrow("test_field").getFieldValue(0).getDoubleValue(), Math.ulp(2.0));
assertEquals(2.0, searchResponse.getHits(1).getFieldsOrThrow("test_field").getFieldValue(0).getDoubleValue(), Math.ulp(2.0));
}
use of com.yelp.nrtsearch.server.grpc.GrpcServer in project nrtsearch by Yelp.
the class ScoreScriptTest method testParams.
@Test
public void testParams() throws Exception {
GrpcServer.TestServer testAddDocs = new GrpcServer.TestServer(grpcServer, true, Mode.STANDALONE);
// 2 docs addDocuments
testAddDocs.addDocuments();
// manual refresh
grpcServer.getBlockingStub().refresh(RefreshRequest.newBuilder().setIndexName(grpcServer.getTestIndex()).build());
VirtualField virtualField = VirtualField.newBuilder().setName("test_field").setScript(Script.newBuilder().setLang("test_lang").setSource("test_params").putParams("text_param", Script.ParamValue.newBuilder().setTextValue("text_val").build()).putParams("bool_param", Script.ParamValue.newBuilder().setBooleanValue(false).build()).putParams("int_param", Script.ParamValue.newBuilder().setIntValue(100).build()).putParams("long_param", Script.ParamValue.newBuilder().setLongValue(1001).build()).putParams("float_param", Script.ParamValue.newBuilder().setFloatValue(1.123F).build()).putParams("double_param", Script.ParamValue.newBuilder().setDoubleValue(3.456).build()).build()).build();
SearchResponse searchResponse = grpcServer.getBlockingStub().search(SearchRequest.newBuilder().setIndexName(grpcServer.getTestIndex()).setStartHit(0).setTopHits(10).addVirtualFields(virtualField).addRetrieveFields("test_field").build());
assertEquals(2, searchResponse.getHitsCount());
assertEquals(4.5, searchResponse.getHits(0).getFieldsOrThrow("test_field").getFieldValue(0).getDoubleValue(), Math.ulp(4.5));
assertEquals(4.5, searchResponse.getHits(1).getFieldsOrThrow("test_field").getFieldValue(0).getDoubleValue(), Math.ulp(4.5));
}
use of com.yelp.nrtsearch.server.grpc.GrpcServer in project nrtsearch by Yelp.
the class ScoreScriptTest method setUpGrpcServer.
private GrpcServer setUpGrpcServer(CollectorRegistry collectorRegistry) throws IOException {
String testIndex = "test_index";
LuceneServerConfiguration luceneServerConfiguration = LuceneServerTestConfigurationFactory.getConfig(Mode.STANDALONE, folder.getRoot());
GlobalState globalState = GlobalState.createState(luceneServerConfiguration);
return new GrpcServer(collectorRegistry, grpcCleanup, luceneServerConfiguration, folder, false, globalState, luceneServerConfiguration.getIndexDir(), testIndex, globalState.getPort(), null, Collections.singletonList(new ScoreScriptTestPlugin()));
}
use of com.yelp.nrtsearch.server.grpc.GrpcServer in project nrtsearch by Yelp.
the class ScoreScriptTest method testQueryFieldScript.
private void testQueryFieldScript(String source, String registerFieldsFile, String addDocsFile, double expectedScore) throws Exception {
GrpcServer.TestServer testAddDocs = new GrpcServer.TestServer(grpcServer, false, Mode.STANDALONE);
new GrpcServer.IndexAndRoleManager(grpcServer).createStartIndexAndRegisterFields(Mode.STANDALONE, 0, false, registerFieldsFile);
AddDocumentResponse addDocumentResponse = testAddDocs.addDocuments(addDocsFile);
// manual refresh
grpcServer.getBlockingStub().refresh(RefreshRequest.newBuilder().setIndexName(grpcServer.getTestIndex()).build());
VirtualField virtualField = VirtualField.newBuilder().setName("test_field").setScript(Script.newBuilder().setLang("test_lang").setSource(source).build()).build();
SearchResponse searchResponse = grpcServer.getBlockingStub().search(SearchRequest.newBuilder().setIndexName(grpcServer.getTestIndex()).setStartHit(0).setTopHits(10).addVirtualFields(virtualField).addRetrieveFields("test_field").build());
assertEquals(2, searchResponse.getHitsCount());
assertEquals(expectedScore, searchResponse.getHits(0).getFieldsOrThrow("test_field").getFieldValue(0).getDoubleValue(), Math.ulp(expectedScore));
assertEquals(expectedScore, searchResponse.getHits(1).getFieldsOrThrow("test_field").getFieldValue(0).getDoubleValue(), Math.ulp(expectedScore));
}
Aggregations