Commit 27c9975f authored by Jean-Baptiste Nizet's avatar Jean-Baptiste Nizet
Browse files

feat: avoid loading the suggestions field when searching

It's large, and it will be ignored anyway when mapping the JSON to a GeneticResource object
parent 5e87004e
......@@ -23,6 +23,7 @@ import org.elasticsearch.search.suggest.SuggestBuilders;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.data.elasticsearch.core.query.FetchSourceFilterBuilder;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
......@@ -32,8 +33,16 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde
*/
public class GeneticResourceDaoImpl implements GeneticResourceDaoCustom {
/**
* The name of the completion suggestion
*/
private static final String COMPLETION = "completion";
/**
* The name of the field on which the completion suggester is applied
*/
private static final String SUGGESTIONS_FIELD = "suggestions";
/**
* Contains the fields searchable on a {@link GeneticResource}.
* This is basically all fields at the exception of a few ones like `identifier`,
......@@ -75,6 +84,7 @@ public class GeneticResourceDaoImpl implements GeneticResourceDaoCustom {
NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder()
.withQuery(boolQueryBuilder)
.withSourceFilter(new FetchSourceFilterBuilder().withExcludes(SUGGESTIONS_FIELD).build())
.withPageable(page);
if (aggregate) {
......@@ -91,7 +101,7 @@ public class GeneticResourceDaoImpl implements GeneticResourceDaoCustom {
public List<String> suggest(String term) {
SuggestBuilder suggestion =
new SuggestBuilder().addSuggestion(COMPLETION,
SuggestBuilders.completionSuggestion("suggestions")
SuggestBuilders.completionSuggestion(SUGGESTIONS_FIELD)
.text(term)
.size(8)
.skipDuplicates(true));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment