use of com.yelp.nrtsearch.server.grpc.SearchRequest in project nrtsearch by Yelp.
the class Warmer method backupWarmingQueriesToS3.
public synchronized void backupWarmingQueriesToS3(String service) throws IOException {
if (Strings.isNullOrEmpty(service)) {
service = this.service;
}
// TODO: tmpDirectory used for simplicity but we might want to provide directory via config
Path tmpDirectory = Paths.get(System.getProperty("java.io.tmpdir"));
Path warmingQueriesDir = null;
Path warmingQueriesFile = null;
BufferedWriter writer = null;
try {
// Creating a directory since the Archiver requires a directory
warmingQueriesDir = Files.createDirectory(tmpDirectory.resolve(WARMING_QUERIES_DIR));
warmingQueriesFile = warmingQueriesDir.resolve(WARMING_QUERIES_FILE);
writer = Files.newBufferedWriter(warmingQueriesFile);
int count = 0;
for (SearchRequest searchRequest : warmingRequests) {
writer.write(JsonFormat.printer().omittingInsignificantWhitespace().print(searchRequest));
writer.newLine();
count++;
}
writer.close();
writer = null;
String versionHash = archiver.upload(service, resource, warmingQueriesDir, List.of(), List.of(), true);
archiver.blessVersion(service, resource, versionHash);
logger.info("Backed up {} warming queries for index: {} to service: {}, resource: {}", count, index, service, resource);
} finally {
if (writer != null) {
writer.close();
}
if (warmingQueriesFile != null && Files.exists(warmingQueriesFile)) {
Files.delete(warmingQueriesFile);
}
if (warmingQueriesDir != null && Files.exists(warmingQueriesDir)) {
Files.delete(warmingQueriesDir);
}
}
}
use of com.yelp.nrtsearch.server.grpc.SearchRequest in project nrtsearch by Yelp.
the class WarmerTest method getTestSearchRequests.
private List<SearchRequest> getTestSearchRequests() {
List<SearchRequest> testRequests = new ArrayList<>();
for (int i = 0; i < 2; i++) {
SearchRequest searchRequest = SearchRequest.newBuilder().setIndexName(index).setQuery(Query.newBuilder().setTermQuery(TermQuery.newBuilder().setField("field" + i).build()).build()).build();
testRequests.add(searchRequest);
}
return testRequests;
}
use of com.yelp.nrtsearch.server.grpc.SearchRequest in project nrtsearch by Yelp.
the class SharedDocContextTest method testSharedDocContext.
@Test
public void testSharedDocContext() {
SearchRequest request = SearchRequest.newBuilder().setTopHits(10).setStartHit(0).setIndexName(DEFAULT_TEST_INDEX).addRetrieveFields("int_score").setQuery(Query.newBuilder().setRangeQuery(RangeQuery.newBuilder().setField("int_field").setLower("20").setUpper("29").build()).build()).addFetchTasks(com.yelp.nrtsearch.server.grpc.FetchTask.newBuilder().setName("phase_1").build()).addFetchTasks(com.yelp.nrtsearch.server.grpc.FetchTask.newBuilder().setName("phase_2").build()).build();
SearchResponse response = getGrpcServer().getBlockingStub().search(request);
assertEquals(10, response.getHitsCount());
for (Hit hit : response.getHitsList()) {
assertEquals(hit.getFieldsOrThrow("_context_value").getFieldValue(0).getIntValue(), hit.getFieldsOrThrow("int_score").getFieldValue(0).getIntValue() * 2);
}
}
use of com.yelp.nrtsearch.server.grpc.SearchRequest in project nrtsearch by Yelp.
the class DocCollectorTest method testNoTimeoutWrapper.
@Test
public void testNoTimeoutWrapper() {
SearchRequest request = SearchRequest.newBuilder().setTopHits(10).build();
TestDocCollector docCollector = new TestDocCollector(request);
assertTrue(docCollector.getManager() instanceof TestDocCollector.TestCollectorManager);
assertTrue(docCollector.getWrappedManager() instanceof SearchCollectorManager);
assertSame(docCollector.getManager(), ((SearchCollectorManager) docCollector.getWrappedManager()).getDocCollectorManger());
}
use of com.yelp.nrtsearch.server.grpc.SearchRequest in project nrtsearch by Yelp.
the class DocCollectorTest method testHasStatsWrapper.
@Test
public void testHasStatsWrapper() {
SearchRequest request = SearchRequest.newBuilder().setTopHits(10).setProfile(true).build();
TestDocCollector docCollector = new TestDocCollector(request);
assertTrue(docCollector.getManager() instanceof TestDocCollector.TestCollectorManager);
assertTrue(docCollector.getWrappedManager() instanceof SearchStatsWrapper);
SearchStatsWrapper<?> searchStatsWrapper = (SearchStatsWrapper<?>) docCollector.getWrappedManager();
assertTrue(searchStatsWrapper.getWrapped() instanceof SearchCollectorManager);
SearchCollectorManager searchCollectorManager = (SearchCollectorManager) searchStatsWrapper.getWrapped();
assertSame(docCollector.getManager(), searchCollectorManager.getDocCollectorManger());
}
Aggregations