Skip to content

Commit

Permalink
HSEARCH-3517 Rename totalHitCountMinimum into totalHitsThreshold
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever committed Sep 1, 2020
1 parent 2030523 commit 2ebf26a
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class ElasticsearchSearchQueryBuilder<H>
private Long timeoutValue;
private TimeUnit timeoutUnit;
private boolean exceptionOnTimeout;
private Integer totalHitCountMinimum;
private Integer totalHitsThreshold;
private ElasticsearchSearchRequestTransformer requestTransformer;

public ElasticsearchSearchQueryBuilder(
Expand Down Expand Up @@ -125,8 +125,8 @@ public void failAfter(long timeout, TimeUnit timeUnit) {
}

@Override
public void totalHitCountMinimum(int totalHitCountMinimum) {
this.totalHitCountMinimum = totalHitCountMinimum;
public void totalHitsThreshold(int totalHitsThreshold) {
this.totalHitsThreshold = totalHitsThreshold;
}

@Override
Expand Down Expand Up @@ -235,7 +235,7 @@ public ElasticsearchSearchQuery<H> build() {
payload, requestTransformer,
searchResultExtractor,
timeoutManager,
scrollTimeout, totalHitCountMinimum
scrollTimeout, totalHitsThreshold
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class ElasticsearchSearchQueryImpl<H> extends AbstractSearchQuery<H, Elas
private final ElasticsearchSearchRequestTransformer requestTransformer;
private final ElasticsearchSearchResultExtractor<ElasticsearchLoadableSearchResult<H>> searchResultExtractor;
private final Integer scrollTimeout;
private final Integer totalHitCountMinimum;
private final Integer totalHitsThreshold;

private ElasticsearchTimeoutManager timeoutManager;

Expand All @@ -78,7 +78,7 @@ public class ElasticsearchSearchQueryImpl<H> extends AbstractSearchQuery<H, Elas
JsonObject payload,
ElasticsearchSearchRequestTransformer requestTransformer,
ElasticsearchSearchResultExtractor<ElasticsearchLoadableSearchResult<H>> searchResultExtractor,
ElasticsearchTimeoutManager timeoutManager, Integer scrollTimeout, Integer totalHitCountMinimum) {
ElasticsearchTimeoutManager timeoutManager, Integer scrollTimeout, Integer totalHitsThreshold) {
this.workFactory = workFactory;
this.queryOrchestrator = queryOrchestrator;
this.searchContext = searchContext;
Expand All @@ -90,7 +90,7 @@ public class ElasticsearchSearchQueryImpl<H> extends AbstractSearchQuery<H, Elas
this.searchResultExtractor = searchResultExtractor;
this.timeoutManager = timeoutManager;
this.scrollTimeout = scrollTimeout;
this.totalHitCountMinimum = totalHitCountMinimum;
this.totalHitsThreshold = totalHitsThreshold;
}

@Override
Expand All @@ -115,7 +115,7 @@ public ElasticsearchSearchResult<H> fetch(Integer offset, Integer limit) {
timeoutManager.start();
NonBulkableWork<ElasticsearchLoadableSearchResult<H>> work = searchWorkBuilder()
.paging( defaultedLimit( limit, offset ), offset )
.totalHitCountMinimum( totalHitCountMinimum )
.totalHitsThreshold( totalHitsThreshold )
.build();

ElasticsearchSearchResultImpl<H> result = Futures.unwrappedExceptionJoin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ public interface SearchWorkBuilder<R> extends ElasticsearchWorkBuilder<NonBulkab

SearchWorkBuilder<R> disableTrackTotalHits();

SearchWorkBuilder<R> totalHitCountMinimum(Integer totalHitCountMinimum);
SearchWorkBuilder<R> totalHitsThreshold(Integer totalHitsThreshold);
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static <T> Builder<T> forElasticsearch7AndAbove(JsonObject payload, Elast
private final Set<URLEncodedString> indexes = new HashSet<>();

private Boolean trackTotalHits;
private Integer totalHitCountMinimum;
private Integer totalHitsThreshold;
private Integer from;
private Integer size;
private Integer scrollSize;
Expand Down Expand Up @@ -138,11 +138,11 @@ public SearchWorkBuilder<R> disableTrackTotalHits() {
}

@Override
public SearchWorkBuilder<R> totalHitCountMinimum(Integer totalHitCountMinimum) {
public SearchWorkBuilder<R> totalHitsThreshold(Integer totalHitsThreshold) {
// setting trackTotalHits to false only if this parameter was already set,
// the parameter is not supported by the older Elasticsearch server
if ( trackTotalHits != null && trackTotalHits ) {
this.totalHitCountMinimum = totalHitCountMinimum;
this.totalHitsThreshold = totalHitsThreshold;
}
return this;
}
Expand Down Expand Up @@ -173,9 +173,9 @@ protected ElasticsearchRequest buildRequest() {
}

if ( trackTotalHits != null ) {
if ( trackTotalHits && totalHitCountMinimum != null ) {
if ( trackTotalHits && totalHitsThreshold != null ) {
// total hits is tracked but a with a limited precision
builder.param( "track_total_hits", totalHitCountMinimum );
builder.param( "track_total_hits", totalHitsThreshold );
}
else {
builder.param( "track_total_hits", trackTotalHits );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private ExtractionRequirements(Builder builder) {

public LuceneCollectors createCollectors(IndexSearcher indexSearcher, Query luceneQuery, Sort sort,
IndexReaderMetadataResolver metadataResolver, int maxDocs, LuceneTimeoutManager timeoutManager,
boolean skipTotalHitCount, Integer totalHitCountMinimum)
boolean skipTotalHitCount, Integer totalHitsThreshold)
throws IOException {
TopDocsCollector<?> topDocsCollector;
Integer scoreSortFieldIndexForRescoring = null;
Expand All @@ -57,13 +57,13 @@ public LuceneCollectors createCollectors(IndexSearcher indexSearcher, Query luce
CollectorSet.Builder collectorsForAllMatchingDocsBuilder =
new CollectorSet.Builder( executionContext, timeoutManager );

int totalHitsThreshold = ( skipTotalHitCount ) ? 0 :
( totalHitCountMinimum == null ) ? Integer.MAX_VALUE : totalHitCountMinimum;
int luceneTotalHitsThreshold = ( skipTotalHitCount ) ? 0 :
( totalHitsThreshold == null ) ? Integer.MAX_VALUE : totalHitsThreshold;

if ( maxDocs > 0 ) {
if ( sort == null ) {
topDocsCollector = TopScoreDocCollector.create(
maxDocs, totalHitsThreshold
maxDocs, luceneTotalHitsThreshold
);
}
else {
Expand All @@ -76,13 +76,13 @@ public LuceneCollectors createCollectors(IndexSearcher indexSearcher, Query luce
scoreSortFieldIndexForRescoring = getScoreSortFieldIndexOrNull( sort );
}
topDocsCollector = TopFieldCollector.create(
sort, maxDocs, totalHitsThreshold
sort, maxDocs, luceneTotalHitsThreshold
);
}
collectorsForAllMatchingDocsBuilder.add( LuceneCollectors.TOP_DOCS_KEY, topDocsCollector );
}

if ( !skipTotalHitCount && totalHitCountMinimum == null ) {
if ( !skipTotalHitCount && totalHitsThreshold == null ) {
TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
collectorsForAllMatchingDocsBuilder.add( LuceneCollectors.TOTAL_HIT_COUNT_KEY, totalHitCountCollector );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class LuceneSearchQueryBuilder<H>
private Long timeout;
private TimeUnit timeUnit;
private boolean exceptionOnTimeout;
private Integer totalHitCountMinimum;
private Integer totalHitsThreshold;

public LuceneSearchQueryBuilder(
LuceneWorkFactory workFactory,
Expand Down Expand Up @@ -115,8 +115,8 @@ public void failAfter(long timeout, TimeUnit timeUnit) {
}

@Override
public void totalHitCountMinimum(int totalHitCountMinimum) {
this.totalHitCountMinimum = totalHitCountMinimum;
public void totalHitsThreshold(int totalHitsThreshold) {
this.totalHitsThreshold = totalHitsThreshold;
}

@Override
Expand Down Expand Up @@ -234,7 +234,7 @@ public LuceneSearchQuery<H> build() {
timeoutManager,
definitiveLuceneQuery,
luceneSort,
searcher, totalHitCountMinimum
searcher, totalHitsThreshold
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class LuceneSearchQueryImpl<H> extends AbstractSearchQuery<H, LuceneSearc
private final Query luceneQuery;
private final Sort luceneSort;
private final LuceneSearcher<LuceneLoadableSearchResult<H>, LuceneExtractableSearchResult<H>> searcher;
private final Integer totalHitCountMinimum;
private final Integer totalHitsThreshold;

private LuceneTimeoutManager timeoutManager;

Expand All @@ -65,7 +65,7 @@ public class LuceneSearchQueryImpl<H> extends AbstractSearchQuery<H, LuceneSearc
LuceneTimeoutManager timeoutManager,
Query luceneQuery, Sort luceneSort,
LuceneSearcher<LuceneLoadableSearchResult<H>, LuceneExtractableSearchResult<H>> searcher,
Integer totalHitCountMinimum) {
Integer totalHitsThreshold) {
this.queryOrchestrator = queryOrchestrator;
this.workFactory = workFactory;
this.searchContext = searchContext;
Expand All @@ -76,7 +76,7 @@ public class LuceneSearchQueryImpl<H> extends AbstractSearchQuery<H, LuceneSearc
this.luceneQuery = luceneQuery;
this.luceneSort = luceneSort;
this.searcher = searcher;
this.totalHitCountMinimum = totalHitCountMinimum;
this.totalHitsThreshold = totalHitsThreshold;
}

@Override
Expand Down Expand Up @@ -174,7 +174,8 @@ public Sort luceneSort() {
private LuceneSearchResult<H> doFetch(Integer offset, Integer limit, boolean skipTotalHitCount) {
timeoutManager.start();
ReadWork<LuceneLoadableSearchResult<H>> work = workFactory.search( searcher, offset, limit, skipTotalHitCount,
totalHitCountMinimum );
totalHitsThreshold
);
LuceneSearchResult<H> result = doSubmit( work )
/*
* WARNING: the following call must run in the user thread.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public String toString() {
@Override
public LuceneLoadableSearchResult<H> search(IndexSearcher indexSearcher,
IndexReaderMetadataResolver metadataResolver,
int offset, Integer limit, boolean skipTotalHitCount, Integer totalHitCountMinimum) throws IOException {
int offset, Integer limit, boolean skipTotalHitCount, Integer totalHitsThreshold) throws IOException {
queryLog.executingLuceneQuery( requestContext.getLuceneQuery() );

// TODO HSEARCH-3947 Check (and in case avoid) huge arrays are created for collectors when a query does not have an upper bound limit
int maxDocs = getMaxDocs( indexSearcher.getIndexReader(), offset, limit );

LuceneCollectors luceneCollectors = buildCollectors( indexSearcher, metadataResolver, maxDocs,
skipTotalHitCount, totalHitCountMinimum
skipTotalHitCount, totalHitsThreshold
);

luceneCollectors.collectMatchingDocs( offset, limit );
Expand Down Expand Up @@ -135,10 +135,10 @@ public void setTimeoutManager(LuceneTimeoutManager timeoutManager) {
}

private LuceneCollectors buildCollectors(IndexSearcher indexSearcher, IndexReaderMetadataResolver metadataResolver,
int maxDocs, boolean skipTotalHitCount, Integer totalHitCountMinimum) throws IOException {
int maxDocs, boolean skipTotalHitCount, Integer totalHitsThreshold) throws IOException {
return extractionRequirements.createCollectors(
indexSearcher, requestContext.getLuceneQuery(), requestContext.getLuceneSort(),
metadataResolver, maxDocs, timeoutManager, skipTotalHitCount, totalHitCountMinimum
metadataResolver, maxDocs, timeoutManager, skipTotalHitCount, totalHitsThreshold
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public interface LuceneSearcher<R, ER> {

R search(IndexSearcher indexSearcher, IndexReaderMetadataResolver metadataResolver,
int offset, Integer limit, boolean skipTotalHitCount, Integer totalHitCountMinimum) throws IOException;
int offset, Integer limit, boolean skipTotalHitCount, Integer totalHitsThreshold) throws IOException;

ER scroll(IndexSearcher indexSearcher, IndexReaderMetadataResolver metadataResolver, int limit) throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ SingleDocumentIndexingWork update(String tenantId, String entityTypeName, Object
IndexManagementWork<?> deleteAll(String tenantId, Set<String> routingKeys);

<R> ReadWork<R> search(LuceneSearcher<R, ?> searcher, Integer offset, Integer limit, boolean skipTotalHitCount,
Integer totalHitCountMinimum);
Integer totalHitsThreshold);

<ER> ReadWork<ER> scroll(LuceneSearcher<?, ER> searcher, int limit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public IndexManagementWork<?> deleteAll(String tenantId, Set<String> routingKeys

@Override
public <R> ReadWork<R> search(LuceneSearcher<R, ?> searcher, Integer offset, Integer limit,
boolean skipTotalHitCount, Integer totalHitCountMinimum) {
return new SearchWork<>( searcher, offset, limit, skipTotalHitCount, totalHitCountMinimum );
boolean skipTotalHitCount, Integer totalHitsThreshold) {
return new SearchWork<>( searcher, offset, limit, skipTotalHitCount, totalHitsThreshold );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ public class SearchWork<R> implements ReadWork<R> {
private final int offset;
private final Integer limit;
private final boolean skipTotalHitCount;
private final Integer totalHitCountMinimum;
private final Integer totalHitsThreshold;

SearchWork(LuceneSearcher<R, ?> searcher,
Integer offset, Integer limit,
boolean skipTotalHitCount, Integer totalHitCountMinimum) {
boolean skipTotalHitCount, Integer totalHitsThreshold) {
this.offset = offset == null ? 0 : offset;
this.limit = limit;
this.searcher = searcher;
this.skipTotalHitCount = skipTotalHitCount;
this.totalHitCountMinimum = totalHitCountMinimum;
this.totalHitsThreshold = totalHitsThreshold;
}

@Override
Expand All @@ -43,7 +43,7 @@ public R execute(ReadWorkExecutionContext context) {

return searcher.search(
indexSearcher, context.getIndexReaderMetadataResolver(), offset, limit, skipTotalHitCount,
totalHitCountMinimum
totalHitsThreshold
);
}
catch (IOException e) {
Expand All @@ -59,7 +59,7 @@ public String toString() {
.append( ", offset=" ).append( offset )
.append( ", limit=" ).append( limit )
.append( ", skipTotalHitCount=" ).append( skipTotalHitCount )
.append( ", totalHitCountMinimum=" ).append( totalHitCountMinimum )
.append( ", totalHitsThreshold=" ).append( totalHitsThreshold )
.append( "]" );
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface SearchResultTotal {
boolean isHitCountExact();

/**
* It could be a lower bound only when a {@link SearchQueryOptionsStep#totalHitCountMinimum(int)} or
* It could be a lower bound only when a {@link SearchQueryOptionsStep#totalHitsThreshold(int)} or
* a {@link SearchQueryOptionsStep#truncateAfter(long, TimeUnit)} has been defined
* for the current query.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ public interface SearchQueryOptionsStep<
/**
* Sometime we don't need the exact total hit count number but a reasonable lower bound of it could be enough.
* <p>
* So that we can skip to collect the hits for the count when a given {@code totalHitCountMinimum} is reached,
* So that we can skip to collect the hits for the count when a given {@code totalHitsThreshold} is reached,
* potentially improving the performance.
*
* @param totalHitCountMinimum the value below which the hit count is always exact
* @param totalHitsThreshold the value below which the hit count is always exact
* @return {@code this}, for method chaining.
* @see SearchResultTotal
*/
S totalHitCountMinimum(int totalHitCountMinimum);
S totalHitsThreshold(int totalHitsThreshold);

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public S failAfter(long timeout, TimeUnit timeUnit) {
}

@Override
public S totalHitCountMinimum(int totalHitCountMinimum) {
searchQueryBuilder.totalHitCountMinimum( totalHitCountMinimum );
public S totalHitsThreshold(int totalHitsThreshold) {
searchQueryBuilder.totalHitsThreshold( totalHitsThreshold );
return thisAsS();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface SearchQueryBuilder<H, C> {

void failAfter(long timeout, TimeUnit timeUnit);

void totalHitCountMinimum(int totalHitCountMinimum);
void totalHitsThreshold(int totalHitsThreshold);

SearchQuery<H> build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void failAfter(long timeout, TimeUnit timeUnit) {
}

@Override
public void totalHitCountMinimum(int totalHitCountMinimum) {
public void totalHitsThreshold(int totalHitsThreshold) {
// TODO HSEARCH-3517 implement it to test mappers
}

Expand Down

0 comments on commit 2ebf26a

Please sign in to comment.