mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-21 19:42:10 +00:00
DATAES-462 - Add query builder option to track scores.
Original pull request: #207.
This commit is contained in:
parent
62a03a8fb7
commit
112600261d
@ -991,7 +991,8 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
SearchRequestBuilder searchRequestBuilder = client.prepareSearch(toArray(query.getIndices()))
|
||||
.setSearchType(query.getSearchType())
|
||||
.setTypes(toArray(query.getTypes()))
|
||||
.setVersion(true);
|
||||
.setVersion(true)
|
||||
.setTrackScores(query.getTrackScores());
|
||||
|
||||
if (query.getSourceFilter() != null) {
|
||||
SourceFilter sourceFilter = query.getSourceFilter();
|
||||
|
@ -15,10 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.query;
|
||||
|
||||
import static java.util.Collections.addAll;
|
||||
import static java.util.Collections.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@ -32,6 +34,7 @@ import org.springframework.util.Assert;
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Alen Turkovic
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
abstract class AbstractQuery implements Query {
|
||||
|
||||
@ -46,6 +49,7 @@ abstract class AbstractQuery implements Query {
|
||||
protected String route;
|
||||
protected SearchType searchType = SearchType.DFS_QUERY_THEN_FETCH;
|
||||
protected IndicesOptions indicesOptions;
|
||||
protected boolean trackScores;
|
||||
|
||||
@Override
|
||||
public Sort getSort() {
|
||||
@ -160,4 +164,13 @@ abstract class AbstractQuery implements Query {
|
||||
public void setIndicesOptions(IndicesOptions indicesOptions) {
|
||||
this.indicesOptions = indicesOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getTrackScores() {
|
||||
return trackScores;
|
||||
}
|
||||
|
||||
public void setTrackScores(boolean trackScores) {
|
||||
this.trackScores = trackScores;
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||
* @author Artur Konczak
|
||||
* @author Mark Paluch
|
||||
* @author Alen Turkovic
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
public class NativeSearchQueryBuilder {
|
||||
|
||||
@ -53,6 +54,7 @@ public class NativeSearchQueryBuilder {
|
||||
private SourceFilter sourceFilter;
|
||||
private List<IndexBoost> indicesBoost;
|
||||
private float minScore;
|
||||
private boolean trackScores;
|
||||
private Collection<String> ids;
|
||||
private String route;
|
||||
private SearchType searchType;
|
||||
@ -128,6 +130,11 @@ public class NativeSearchQueryBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeSearchQueryBuilder withTrackScores(boolean trackScores) {
|
||||
this.trackScores = trackScores;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeSearchQueryBuilder withIds(Collection<String> ids) {
|
||||
this.ids = ids;
|
||||
return this;
|
||||
@ -149,8 +156,11 @@ public class NativeSearchQueryBuilder {
|
||||
}
|
||||
|
||||
public NativeSearchQuery build() {
|
||||
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(queryBuilder, filterBuilder, sortBuilders, highlightFields);
|
||||
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(queryBuilder, filterBuilder, sortBuilders,
|
||||
highlightFields);
|
||||
|
||||
nativeSearchQuery.setPageable(pageable);
|
||||
nativeSearchQuery.setTrackScores(trackScores);
|
||||
|
||||
if (indices != null) {
|
||||
nativeSearchQuery.addIndices(indices);
|
||||
|
@ -30,6 +30,7 @@ import org.springframework.data.domain.Sort;
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Alen Turkovic
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
public interface Query {
|
||||
|
||||
@ -114,8 +115,7 @@ public interface Query {
|
||||
void addSourceFilter(SourceFilter sourceFilter);
|
||||
|
||||
/**
|
||||
* Get SourceFilter to be returned to get include and exclude source
|
||||
* fields as part of search request.
|
||||
* Get SourceFilter to be returned to get include and exclude source fields as part of search request.
|
||||
*
|
||||
* @return SourceFilter
|
||||
*/
|
||||
@ -128,6 +128,13 @@ public interface Query {
|
||||
*/
|
||||
float getMinScore();
|
||||
|
||||
/**
|
||||
* Get if scores will be computed and tracked, regardless of whether sorting on a field. Defaults to <tt>false</tt>.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean getTrackScores();
|
||||
|
||||
/**
|
||||
* Get Ids
|
||||
*
|
||||
@ -142,7 +149,6 @@ public interface Query {
|
||||
*/
|
||||
String getRoute();
|
||||
|
||||
|
||||
/**
|
||||
* Type of search
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user