use of org.graylog.shaded.elasticsearch7.org.apache.lucene.search.TotalHits in project sonarqube by SonarSource.
the class EsUtilsTest method convertToDocs_empty.
@Test
public void convertToDocs_empty() {
SearchHits hits = new SearchHits(new SearchHit[] {}, new TotalHits(0, TotalHits.Relation.EQUAL_TO), 0);
List<BaseDoc> docs = EsUtils.convertToDocs(hits, IssueDoc::new);
assertThat(docs).isEmpty();
}
use of org.graylog.shaded.elasticsearch7.org.apache.lucene.search.TotalHits in project sonarqube by SonarSource.
the class IssueIndexTest method paging.
@Test
public void paging() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
for (int i = 0; i < 12; i++) {
indexIssues(newDoc("I" + i, file));
}
IssueQuery.Builder query = IssueQuery.builder();
// There are 12 issues in total, with 10 issues per page, the page 2 should only contain 2 elements
SearchResponse result = underTest.search(query.build(), new SearchOptions().setPage(2, 10));
assertThat(result.getHits().getHits()).hasSize(2);
assertThat(result.getHits().getTotalHits()).isEqualTo(new TotalHits(12, TotalHits.Relation.EQUAL_TO));
result = underTest.search(IssueQuery.builder().build(), new SearchOptions().setOffset(0).setLimit(5));
assertThat(result.getHits().getHits()).hasSize(5);
assertThat(result.getHits().getTotalHits()).isEqualTo(new TotalHits(12, TotalHits.Relation.EQUAL_TO));
result = underTest.search(IssueQuery.builder().build(), new SearchOptions().setOffset(2).setLimit(10));
assertThat(result.getHits().getHits()).hasSize(10);
assertThat(result.getHits().getTotalHits()).isEqualTo(new TotalHits(12, TotalHits.Relation.EQUAL_TO));
}
use of org.graylog.shaded.elasticsearch7.org.apache.lucene.search.TotalHits in project snow-owl by b2ihealthcare.
the class EsDocumentSearcher method toHits.
private <T> Hits<T> toHits(Class<T> select, List<Class<?>> from, final List<String> fields, final boolean fetchSource, final int limit, final int totalHits, final SortBy sortBy, final Iterable<SearchHit> hits) throws IOException {
final HitConverter<T> hitConverter = HitConverter.getConverter(mapper, select, from, fetchSource, fields);
Object[] searchAfterSortValues = null;
final ImmutableList.Builder<T> result = ImmutableList.builder();
for (Iterator<SearchHit> iterator = hits.iterator(); iterator.hasNext(); ) {
SearchHit hit = iterator.next();
// if this was the last value then collect the sort values for searchAfter
final T value = hitConverter.convert(hit);
if (value instanceof WithScore) {
((WithScore) value).setScore(Float.isNaN(hit.getScore()) ? 0.0f : hit.getScore());
}
result.add(value);
if (!iterator.hasNext()) {
searchAfterSortValues = hit.getSortValues();
}
}
return new Hits<T>(result.build(), toSearchAfterToken(searchAfterSortValues), limit, totalHits);
}
use of org.graylog.shaded.elasticsearch7.org.apache.lucene.search.TotalHits in project graylog2-server by Graylog2.
the class ESPivotTest method returnDocumentCount.
private void returnDocumentCount(SearchResponse queryResult, long totalCount) {
final TotalHits totalHits = new TotalHits(totalCount, TotalHits.Relation.EQUAL_TO);
final SearchHits searchHits = new SearchHits(new SearchHit[0], totalHits, 0.0f);
when(queryResult.getHits()).thenReturn(searchHits);
}
Aggregations