Search in sources :

Example 6 with GrpcServer

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));
}
Also used : GrpcServer(com.yelp.nrtsearch.server.grpc.GrpcServer) AddDocumentResponse(com.yelp.nrtsearch.server.grpc.AddDocumentResponse) SearchResponse(com.yelp.nrtsearch.server.grpc.SearchResponse) Test(org.junit.Test)

Example 7 with GrpcServer

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));
}
Also used : VirtualField(com.yelp.nrtsearch.server.grpc.VirtualField) GrpcServer(com.yelp.nrtsearch.server.grpc.GrpcServer) SearchResponse(com.yelp.nrtsearch.server.grpc.SearchResponse) Test(org.junit.Test)

Example 8 with GrpcServer

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));
}
Also used : VirtualField(com.yelp.nrtsearch.server.grpc.VirtualField) GrpcServer(com.yelp.nrtsearch.server.grpc.GrpcServer) SearchResponse(com.yelp.nrtsearch.server.grpc.SearchResponse) Test(org.junit.Test)

Example 9 with GrpcServer

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()));
}
Also used : LuceneServerConfiguration(com.yelp.nrtsearch.server.config.LuceneServerConfiguration) GlobalState(com.yelp.nrtsearch.server.luceneserver.GlobalState) GrpcServer(com.yelp.nrtsearch.server.grpc.GrpcServer)

Example 10 with GrpcServer

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));
}
Also used : VirtualField(com.yelp.nrtsearch.server.grpc.VirtualField) GrpcServer(com.yelp.nrtsearch.server.grpc.GrpcServer) AddDocumentResponse(com.yelp.nrtsearch.server.grpc.AddDocumentResponse) SearchResponse(com.yelp.nrtsearch.server.grpc.SearchResponse)

Aggregations

GrpcServer (com.yelp.nrtsearch.server.grpc.GrpcServer)11 SearchResponse (com.yelp.nrtsearch.server.grpc.SearchResponse)7 Test (org.junit.Test)6 LuceneServerConfiguration (com.yelp.nrtsearch.server.config.LuceneServerConfiguration)3 AddDocumentResponse (com.yelp.nrtsearch.server.grpc.AddDocumentResponse)3 VirtualField (com.yelp.nrtsearch.server.grpc.VirtualField)3 GlobalState (com.yelp.nrtsearch.server.luceneserver.GlobalState)2 AddDocumentRequest (com.yelp.nrtsearch.server.grpc.AddDocumentRequest)1 FieldDefRequest (com.yelp.nrtsearch.server.grpc.FieldDefRequest)1 LuceneServerGrpc (com.yelp.nrtsearch.server.grpc.LuceneServerGrpc)1