DATAES-14 - added option to choose different search types per query

This commit is contained in:
Artur Konczak 2014-03-12 16:02:50 +00:00
parent b6628385d9
commit 08cdcc5c4c
3 changed files with 19 additions and 1 deletions

View File

@ -555,7 +555,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
int startRecord = 0;
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) {
startRecord = query.getPageable().getPageNumber() * query.getPageable().getPageSize();

View File

@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.elasticsearch.action.search.SearchType;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.util.Assert;
@ -41,6 +42,7 @@ abstract class AbstractQuery implements Query {
protected float minScore;
protected Collection<String> ids;
protected String route;
protected SearchType searchType = SearchType.DFS_QUERY_THEN_FETCH;
@Override
public Sort getSort() {
@ -127,4 +129,12 @@ abstract class AbstractQuery implements Query {
public void setRoute(String route) {
this.route = route;
}
public void setSearchType(SearchType searchType) {
this.searchType = searchType;
}
public SearchType getSearchType() {
return searchType;
}
}

View File

@ -18,6 +18,7 @@ package org.springframework.data.elasticsearch.core.query;
import java.util.Collection;
import java.util.List;
import org.elasticsearch.action.search.SearchType;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@ -130,4 +131,11 @@ public interface Query {
* @return
*/
String getRoute();
/**
* Type of search
* @return
*/
SearchType getSearchType();
}