Search in sources :

Example 26 with AddDocumentRequest

use of com.yelp.nrtsearch.server.grpc.AddDocumentRequest in project nrtsearch by Yelp.

the class TerminateAfterWrapperTest method initIndex.

@Override
public void initIndex(String name) throws Exception {
    IndexWriter writer = getGlobalState().getIndex(name).getShard(0).writer;
    // don't want any merges for these tests
    writer.getConfig().setMergePolicy(NoMergePolicy.INSTANCE);
    // create a shuffled list of ids
    List<Integer> idList = new ArrayList<>();
    for (int i = 0; i < NUM_DOCS; ++i) {
        idList.add(i);
    }
    Collections.shuffle(idList);
    // add documents one chunk at a time to ensure multiple index segments
    List<AddDocumentRequest> requestChunk = new ArrayList<>();
    for (Integer id : idList) {
        requestChunk.add(AddDocumentRequest.newBuilder().setIndexName(name).putFields("doc_id", AddDocumentRequest.MultiValuedField.newBuilder().addValue(String.valueOf(id)).build()).putFields("int_score", AddDocumentRequest.MultiValuedField.newBuilder().addValue(String.valueOf(NUM_DOCS - id)).build()).putFields("int_field", AddDocumentRequest.MultiValuedField.newBuilder().addValue(String.valueOf(id)).build()).build());
        if (requestChunk.size() == SEGMENT_CHUNK) {
            addDocuments(requestChunk.stream());
            requestChunk.clear();
            writer.commit();
        }
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) ArrayList(java.util.ArrayList) AddDocumentRequest(com.yelp.nrtsearch.server.grpc.AddDocumentRequest)

Example 27 with AddDocumentRequest

use of com.yelp.nrtsearch.server.grpc.AddDocumentRequest in project nrtsearch by Yelp.

the class RescorerTest method initIndex.

@Override
public void initIndex(String name) throws Exception {
    IndexWriter writer = getGlobalState().getIndex(name).getShard(0).writer;
    // don't want any merges for these tests
    writer.getConfig().setMergePolicy(NoMergePolicy.INSTANCE);
    // create a shuffled list of ids
    List<Integer> idList = new ArrayList<>();
    for (int i = 0; i < NUM_DOCS; ++i) {
        idList.add(i);
    }
    Collections.shuffle(idList);
    // add documents one chunk at a time to ensure multiple index segments
    List<AddDocumentRequest> requestChunk = new ArrayList<>();
    for (Integer id : idList) {
        requestChunk.add(AddDocumentRequest.newBuilder().setIndexName(name).putFields("doc_id", AddDocumentRequest.MultiValuedField.newBuilder().addValue(String.valueOf(id)).build()).putFields("int_score", AddDocumentRequest.MultiValuedField.newBuilder().addValue(String.valueOf(NUM_DOCS - id)).build()).putFields("int_field", AddDocumentRequest.MultiValuedField.newBuilder().addValue(String.valueOf(id)).build()).build());
        if (requestChunk.size() == SEGMENT_CHUNK) {
            addDocuments(requestChunk.stream());
            requestChunk.clear();
            writer.commit();
        }
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) ArrayList(java.util.ArrayList) AddDocumentRequest(com.yelp.nrtsearch.server.grpc.AddDocumentRequest)

Example 28 with AddDocumentRequest

use of com.yelp.nrtsearch.server.grpc.AddDocumentRequest in project nrtsearch by Yelp.

the class AtomFieldTest method initIndex.

protected void initIndex(String name) throws Exception {
    List<AddDocumentRequest> docs = new ArrayList<>();
    MultiValuedField t1Value = MultiValuedField.newBuilder().addValue("term 1").build();
    MultiValuedField t2Value = MultiValuedField.newBuilder().addValue("term 2").build();
    MultiValuedField t3Value = MultiValuedField.newBuilder().addValue("term 3").build();
    MultiValuedField t12Values = MultiValuedField.newBuilder().addValue("term 1").addValue("term 2").build();
    MultiValuedField t23Values = MultiValuedField.newBuilder().addValue("term 2").addValue("term 3").build();
    MultiValuedField t31Values = MultiValuedField.newBuilder().addValue("term 3").addValue("term 1").build();
    AddDocumentRequest request = AddDocumentRequest.newBuilder().setIndexName(name).putFields("doc_id", MultiValuedField.newBuilder().addValue("1").build()).putFields("single", t1Value).putFields("multi_one", t2Value).putFields("multi_two", t31Values).build();
    docs.add(request);
    request = AddDocumentRequest.newBuilder().setIndexName(name).putFields("doc_id", MultiValuedField.newBuilder().addValue("2").build()).putFields("single", t2Value).putFields("multi_one", t3Value).putFields("multi_two", t12Values).build();
    docs.add(request);
    request = AddDocumentRequest.newBuilder().setIndexName(name).putFields("doc_id", MultiValuedField.newBuilder().addValue("3").build()).putFields("single", t3Value).putFields("multi_one", t1Value).putFields("multi_two", t23Values).build();
    docs.add(request);
    addDocuments(docs.stream());
}
Also used : MultiValuedField(com.yelp.nrtsearch.server.grpc.AddDocumentRequest.MultiValuedField) ArrayList(java.util.ArrayList) AddDocumentRequest(com.yelp.nrtsearch.server.grpc.AddDocumentRequest)

Example 29 with AddDocumentRequest

use of com.yelp.nrtsearch.server.grpc.AddDocumentRequest in project nrtsearch by Yelp.

the class BooleanFieldTest method initIndex.

protected void initIndex(String name) throws Exception {
    List<AddDocumentRequest> docs = new ArrayList<>();
    MultiValuedField trueValue = MultiValuedField.newBuilder().addValue("true").build();
    MultiValuedField falseValue = MultiValuedField.newBuilder().addValue("false").build();
    MultiValuedField bothValues = MultiValuedField.newBuilder().addValue("true").addValue("false").build();
    AddDocumentRequest request = AddDocumentRequest.newBuilder().setIndexName(name).putFields("doc_id", MultiValuedField.newBuilder().addValue("1").build()).putFields("single", trueValue).putFields("single_not_search", trueValue).putFields("multi_one", falseValue).putFields("multi_both", bothValues).putFields("multi_not_search", falseValue).build();
    docs.add(request);
    request = AddDocumentRequest.newBuilder().setIndexName(name).putFields("doc_id", MultiValuedField.newBuilder().addValue("2").build()).putFields("single", falseValue).putFields("single_not_search", falseValue).putFields("multi_one", trueValue).putFields("multi_both", bothValues).putFields("multi_not_search", trueValue).build();
    docs.add(request);
    addDocuments(docs.stream());
}
Also used : MultiValuedField(com.yelp.nrtsearch.server.grpc.AddDocumentRequest.MultiValuedField) ArrayList(java.util.ArrayList) AddDocumentRequest(com.yelp.nrtsearch.server.grpc.AddDocumentRequest)

Example 30 with AddDocumentRequest

use of com.yelp.nrtsearch.server.grpc.AddDocumentRequest in project nrtsearch by Yelp.

the class VectorFieldDefTest method parseVectorFieldToFloatArrFailTest.

@Test
public void parseVectorFieldToFloatArrFailTest() {
    List<String> invalidJsonList = Arrays.asList("[a, b, c]");
    List<AddDocumentRequest> documents = buildDocuments(DEFAULT_TEST_INDEX, invalidJsonList);
    Exception exception = Assert.assertThrows(RuntimeException.class, () -> addDocuments(documents.stream()));
    assertTrue(exception.getMessage().contains("For input string: \"a\""));
}
Also used : AddDocumentRequest(com.yelp.nrtsearch.server.grpc.AddDocumentRequest) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

AddDocumentRequest (com.yelp.nrtsearch.server.grpc.AddDocumentRequest)33 ArrayList (java.util.ArrayList)21 IndexWriter (org.apache.lucene.index.IndexWriter)14 IOException (java.io.IOException)6 Test (org.junit.Test)6 MultiValuedField (com.yelp.nrtsearch.server.grpc.AddDocumentRequest.MultiValuedField)3 Path (java.nio.file.Path)3 AddDocumentResponse (com.yelp.nrtsearch.server.grpc.AddDocumentResponse)2 LuceneServerClientBuilder (com.yelp.nrtsearch.server.grpc.LuceneServerClientBuilder)2 StreamObserver (io.grpc.stub.StreamObserver)2 Reader (java.io.Reader)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 CSVParser (org.apache.commons.csv.CSVParser)2 Gson (com.google.gson.Gson)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ProtocolStringList (com.google.protobuf.ProtocolStringList)1 FieldDefRequest (com.yelp.nrtsearch.server.grpc.FieldDefRequest)1 GrpcServer (com.yelp.nrtsearch.server.grpc.GrpcServer)1 LuceneServerClient (com.yelp.nrtsearch.server.grpc.LuceneServerClient)1 LuceneServerGrpc (com.yelp.nrtsearch.server.grpc.LuceneServerGrpc)1