Fix InternalSearchHit#hasSource to return the proper boolean value (#21441)

The method used to be called `isSourceEmpty`, and was renamed to `hasSource`, but the return value never changed. Updated tests and users accordingly.

Closes #21419
This commit is contained in:
Luca Cavanna 2016-11-10 13:13:38 +01:00 committed by GitHub
parent 860efb2ad2
commit bd23921a3a
4 changed files with 12 additions and 5 deletions

View File

@ -249,7 +249,7 @@ public class InternalSearchHit implements SearchHit {
@Override
public boolean hasSource() {
return source == null;
return source != null;
}
@Override

View File

@ -293,7 +293,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
assertNoFailures(response);
assertThat(response.getHits().totalHits(), equalTo(3L));
assertThat(response.getHits().getAt(0).hasSource(), equalTo(true));
assertFalse(response.getHits().getAt(0).hasSource());
assertThat(response.getHits().getAt(0).id(), equalTo("1"));
Set<String> fields = new HashSet<>(response.getHits().getAt(0).fields().keySet());
fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates

View File

@ -19,6 +19,7 @@
package org.elasticsearch.search.internal;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
import org.elasticsearch.common.text.Text;
@ -26,7 +27,6 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.search.SearchShardTarget;
import org.elasticsearch.test.ESTestCase;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
@ -87,4 +87,11 @@ public class InternalSearchHitTests extends ESTestCase {
assertThat(searchHit.getSourceRef(), nullValue());
assertThat(searchHit.getSourceAsString(), nullValue());
}
public void testHasSource() {
InternalSearchHit searchHit = new InternalSearchHit(randomInt());
assertFalse(searchHit.hasSource());
searchHit.sourceRef(new BytesArray("{}"));
assertTrue(searchHit.hasSource());
}
}

View File

@ -197,9 +197,9 @@ public class ClientScrollableHitSource extends ScrollableHitSource {
private final SearchHit delegate;
private final BytesReference source;
public ClientHit(SearchHit delegate) {
ClientHit(SearchHit delegate) {
this.delegate = delegate;
source = delegate.hasSource() ? null : delegate.getSourceRef();
source = delegate.hasSource() ? delegate.getSourceRef() : null;
}
@Override