Search in sources :

Example 1 with Hit

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()));
    }
}
Also used : Hit(com.yelp.nrtsearch.server.grpc.SearchResponse.Hit) TermQuery(com.yelp.nrtsearch.server.grpc.TermQuery) Query(com.yelp.nrtsearch.server.grpc.Query) TermInSetQuery(com.yelp.nrtsearch.server.grpc.TermInSetQuery) SearchResponse(com.yelp.nrtsearch.server.grpc.SearchResponse)

Example 2 with Hit

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

Example 3 with Hit

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

Example 4 with Hit

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);
}
Also used : Hit(com.yelp.nrtsearch.server.grpc.SearchResponse.Hit) HashSet(java.util.HashSet)

Example 5 with Hit

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()));
    }
}
Also used : Hit(com.yelp.nrtsearch.server.grpc.SearchResponse.Hit) Query(com.yelp.nrtsearch.server.grpc.Query) TermQuery(com.yelp.nrtsearch.server.grpc.TermQuery) TermInSetQuery(com.yelp.nrtsearch.server.grpc.TermInSetQuery) SearchResponse(com.yelp.nrtsearch.server.grpc.SearchResponse)

Aggregations

Hit (com.yelp.nrtsearch.server.grpc.SearchResponse.Hit)8 SearchResponse (com.yelp.nrtsearch.server.grpc.SearchResponse)5 Query (com.yelp.nrtsearch.server.grpc.Query)3 TermInSetQuery (com.yelp.nrtsearch.server.grpc.TermInSetQuery)3 TermQuery (com.yelp.nrtsearch.server.grpc.TermQuery)3 HashSet (java.util.HashSet)2 SearchRequest (com.yelp.nrtsearch.server.grpc.SearchRequest)1 CompositeFieldValue (com.yelp.nrtsearch.server.grpc.SearchResponse.Hit.CompositeFieldValue)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Future (java.util.concurrent.Future)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 Test (org.junit.Test)1