use of com.yelp.nrtsearch.server.grpc.SearchResponse.Hit in project nrtsearch by Yelp.
the class BooleanFieldTest method queryAndVerifyIds.
private void queryAndVerifyIds(TermQuery termQuery, String... expectedIds) {
Query query = Query.newBuilder().setTermQuery(termQuery).build();
SearchResponse response = getGrpcServer().getBlockingStub().search(SearchRequest.newBuilder().setIndexName(DEFAULT_TEST_INDEX).setStartHit(0).setTopHits(10).setQuery(query).addRetrieveFields("doc_id").build());
List<String> idList = Arrays.asList(expectedIds);
assertEquals(idList.size(), response.getHitsCount());
for (Hit hit : response.getHitsList()) {
assertTrue(idList.contains(hit.getFieldsOrThrow("doc_id").getFieldValue(0).getTextValue()));
}
}
use of com.yelp.nrtsearch.server.grpc.SearchResponse.Hit 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.SearchResponse.Hit in project nrtsearch by Yelp.
the class LatLonFieldDefTest method queryAndVerifyIds.
private void queryAndVerifyIds(Query query, String... expectedIds) {
SearchResponse response = getGrpcServer().getBlockingStub().search(SearchRequest.newBuilder().setIndexName(DEFAULT_TEST_INDEX).setStartHit(0).setTopHits(10).setQuery(query).addRetrieveFields("doc_id").build());
List<String> idList = Arrays.asList(expectedIds);
assertEquals(idList.size(), response.getHitsCount());
for (Hit hit : response.getHitsList()) {
assertTrue(idList.contains(hit.getFieldsOrThrow("doc_id").getFieldValue(0).getTextValue()));
}
}
use of com.yelp.nrtsearch.server.grpc.SearchResponse.Hit in project nrtsearch by Yelp.
the class MultiFieldTest method assertFields.
private void assertFields(SearchResponse response, String... expectedIds) {
Set<String> seenSet = new HashSet<>();
for (Hit hit : response.getHitsList()) {
String id = hit.getFieldsOrThrow("doc_id").getFieldValue(0).getTextValue();
seenSet.add(id);
if (id.equals("1")) {
assertEquals("First Field", hit.getFieldsOrThrow("field_1").getFieldValue(0).getTextValue());
assertEquals("First Field", hit.getFieldsOrThrow("field_1.keyword").getFieldValue(0).getTextValue());
assertEquals("10", hit.getFieldsOrThrow("field_2").getFieldValue(0).getTextValue());
assertEquals(10, hit.getFieldsOrThrow("field_2.number").getFieldValue(0).getIntValue());
assertEquals("10", hit.getFieldsOrThrow("field_2.number.keyword").getFieldValue(0).getTextValue());
assertEquals(50, hit.getFieldsOrThrow("field_3").getFieldValue(0).getIntValue());
assertEquals("50", hit.getFieldsOrThrow("field_3.keyword").getFieldValue(0).getTextValue());
assertEquals("50", hit.getFieldsOrThrow("field_3.text").getFieldValue(0).getTextValue());
} else if (id.equals("2")) {
assertEquals("Second Field", hit.getFieldsOrThrow("field_1").getFieldValue(0).getTextValue());
assertEquals("Second Field", hit.getFieldsOrThrow("field_1.keyword").getFieldValue(0).getTextValue());
assertEquals("20", hit.getFieldsOrThrow("field_2").getFieldValue(0).getTextValue());
assertEquals(20, hit.getFieldsOrThrow("field_2.number").getFieldValue(0).getIntValue());
assertEquals("20", hit.getFieldsOrThrow("field_2.number.keyword").getFieldValue(0).getTextValue());
assertEquals(100, hit.getFieldsOrThrow("field_3").getFieldValue(0).getIntValue());
assertEquals("100", hit.getFieldsOrThrow("field_3.keyword").getFieldValue(0).getTextValue());
assertEquals("100", hit.getFieldsOrThrow("field_3.text").getFieldValue(0).getTextValue());
} else {
fail("Unknown id: " + id);
}
}
Set<String> expectedSet = new HashSet<>(Arrays.asList(expectedIds));
assertEquals(expectedSet, seenSet);
}
use of com.yelp.nrtsearch.server.grpc.SearchResponse.Hit in project nrtsearch by Yelp.
the class AtomFieldTest method queryInSetAndVerifyIds.
private void queryInSetAndVerifyIds(TermInSetQuery termInSetQuery, String... expectedIds) {
Query query = Query.newBuilder().setTermInSetQuery(termInSetQuery).build();
SearchResponse response = getGrpcServer().getBlockingStub().search(SearchRequest.newBuilder().setIndexName(DEFAULT_TEST_INDEX).setStartHit(0).setTopHits(10).setQuery(query).addRetrieveFields("doc_id").build());
List<String> idList = Arrays.asList(expectedIds);
assertEquals(idList.size(), response.getHitsCount());
for (Hit hit : response.getHitsList()) {
assertTrue(idList.contains(hit.getFieldsOrThrow("doc_id").getFieldValue(0).getTextValue()));
}
}
Aggregations