Package org.elasticsearch.search

Examples of org.elasticsearch.search.SearchHits.totalHits()


        }
        queryFetchResults = scrollQueryFetchResults;

        sortedShardList = searchPhaseController.sortDocs(queryFetchResults.values());
        hits = searchPhaseController.merge(sortedShardList, queryFetchResults, queryFetchResults).hits();
        assertThat(hits.totalHits(), equalTo(100l));
        assertThat(hits.hits().length, equalTo(40));
        for (int i = 0; i < 40; i++) {
            SearchHit hit = hits.hits()[i];
//            System.out.println(hit.id() + " " + hit.explanation());
            // we don't do perfect sorting when it comes to scroll with Query+Fetch
View Full Code Here


            fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter());
        }

        SearchHits hits = searchPhaseController.merge(sortedShardList, queryResults, fetchResults).hits();

        assertThat(hits.totalHits(), equalTo(100l));
        assertThat(hits.hits().length, equalTo(60));
        for (int i = 0; i < 60; i++) {
            SearchHit hit = hits.hits()[i];
//            System.out.println(hit.explanation());
            assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(100 - i - 1)));
View Full Code Here

            FetchSearchResult fetchResult = nodeToSearchService.get(shardTarget.nodeId()).executeFetchPhase(new FetchSearchRequest(queryResults.get(shardTarget).queryResult().id(), docIds));
            fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter());
        }

        hits = searchPhaseController.merge(sortedShardList, queryResults, fetchResults).hits();
        assertThat(hits.totalHits(), equalTo(100l));
        assertThat(hits.hits().length, equalTo(40));
        for (int i = 0; i < 40; i++) {
            SearchHit hit = hits.hits()[i];
            assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(100 - 60 - 1 - i)));
        }
View Full Code Here

                };
            }

            @Override
            public long totalHits() {
                return hits.totalHits();
            }
        };
    }

    @Override public String scrollId() {
View Full Code Here

    @Test
    public void testLetUpdateFailButMergeToGetCorrectRetweetCount() throws IOException {
        twSearch.testUpdate(createTweet(1L, "text", "peter"));
        SearchHits h = twSearch.query(new TweetQuery()).hits();
        assertEquals(1, h.totalHits());

        Collection<Integer> res = twSearch.bulkUpdate(
                Arrays.asList(createTweet(1L, "text", "peter").setRetweetCount(1).setVersion(10)),
                twSearch.getIndexName());
        assertEquals(1, res.size());
View Full Code Here

    @Test
    public void testVersionCollision() throws IOException {
        twSearch.testUpdate(createTweet(1L, "text", "peter"));
        SearchHits h = twSearch.query(new TweetQuery()).hits();
        assertEquals(1, h.totalHits());

        Collection<Integer> res = twSearch.bulkUpdate(
                Arrays.asList(createTweet(1L, "text", "peter").setRetweetCount(1).setVersion(h.hits()[0].getVersion())),
                twSearch.getIndexName());
        assertEquals(0, res.size());
View Full Code Here

  @Test
  public void shouldMapSearchRequestToPage() {
    //Given
    SearchHit[] hits = {createCarHit("Ford", "Grat"), createCarHit("BMW", "Arrow")};
    SearchHits searchHits = mock(SearchHits.class);
    when(searchHits.totalHits()).thenReturn(2L);
    when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
    when(response.getHits()).thenReturn(searchHits);

    //When
    FacetedPage<Car> page = resultMapper.mapResults(response, Car.class, null);
View Full Code Here

  @Test
  public void shouldMapPartialSearchRequestToObject() {
    //Given
    SearchHit[] hits = {createCarPartialHit("Ford", "Grat"), createCarPartialHit("BMW", "Arrow")};
    SearchHits searchHits = mock(SearchHits.class);
    when(searchHits.totalHits()).thenReturn(2L);
    when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
    when(response.getHits()).thenReturn(searchHits);

    //When
    FacetedPage<Car> page = resultMapper.mapResults(response, Car.class, null);
View Full Code Here

                log.trace("elasticsearch query : " + searchRequest);
            }
            SearchResponse searchResponse = searchRequest.execute().actionGet();

            SearchHits searchHits = searchResponse.hits();
            Long hitsNumber = searchHits.totalHits();
            if (hitsNumber == 0) {
                return Collections.emptyList();
            }

            SearchHit[] hits = searchHits.hits();
View Full Code Here

            SearchResponse searchResponse = searchRequest
                    .execute()
                    .actionGet();

            SearchHits searchHits = searchResponse.hits();
            if (searchHits.totalHits() == 0)
                return Collections.emptyList();

            SearchHit[] hits = searchHits.hits();
            final List<String> ids = new ArrayList<String>(hits.length);
            for (SearchHit hit : hits) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.