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();
}
}
}
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();
}
}
}
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());
}
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());
}
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\""));
}
Aggregations