mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-07-05 18:22:23 +00:00
DATAES-14 - added option to choose different search types per query
This commit is contained in:
parent
b6628385d9
commit
08cdcc5c4c
@ -555,7 +555,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
|||||||
|
|
||||||
int startRecord = 0;
|
int startRecord = 0;
|
||||||
SearchRequestBuilder searchRequestBuilder = client.prepareSearch(toArray(query.getIndices()))
|
SearchRequestBuilder searchRequestBuilder = client.prepareSearch(toArray(query.getIndices()))
|
||||||
.setSearchType(DFS_QUERY_THEN_FETCH).setTypes(toArray(query.getTypes()));
|
.setSearchType(query.getSearchType()).setTypes(toArray(query.getTypes()));
|
||||||
|
|
||||||
if (query.getPageable() != null) {
|
if (query.getPageable() != null) {
|
||||||
startRecord = query.getPageable().getPageNumber() * query.getPageable().getPageSize();
|
startRecord = query.getPageable().getPageNumber() * query.getPageable().getPageSize();
|
||||||
|
@ -21,6 +21,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.elasticsearch.action.search.SearchType;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
@ -41,6 +42,7 @@ abstract class AbstractQuery implements Query {
|
|||||||
protected float minScore;
|
protected float minScore;
|
||||||
protected Collection<String> ids;
|
protected Collection<String> ids;
|
||||||
protected String route;
|
protected String route;
|
||||||
|
protected SearchType searchType = SearchType.DFS_QUERY_THEN_FETCH;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Sort getSort() {
|
public Sort getSort() {
|
||||||
@ -127,4 +129,12 @@ abstract class AbstractQuery implements Query {
|
|||||||
public void setRoute(String route) {
|
public void setRoute(String route) {
|
||||||
this.route = route;
|
this.route = route;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSearchType(SearchType searchType) {
|
||||||
|
this.searchType = searchType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SearchType getSearchType() {
|
||||||
|
return searchType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package org.springframework.data.elasticsearch.core.query;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.elasticsearch.action.search.SearchType;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
@ -130,4 +131,11 @@ public interface Query {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getRoute();
|
String getRoute();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of search
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SearchType getSearchType();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user