Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete PR #3948

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -5,15 +5,9 @@
import org.apache.http.util.EntityUtils;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.suggest.SuggestBuilder;
import org.elasticsearch.search.suggest.SuggestBuilders;
import org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -37,7 +31,7 @@ public ESBasedSuggestionService(RestClient lowLevelClient) {
public SuggestionResponse searchSuggestions(String queryStr) throws IOException {
// Build the suggestor query for ES
String suggestorName = "suggest_keyword";
Request queryRequest = new Request("POST", "/autocomplete/_search");
Request queryRequest = new Request("POST", "/autocomplete/_search?_source=false");
queryRequest.setJsonEntity(queryStr);
Response response = esRestClient.performRequest(queryRequest);

@@ -51,7 +45,7 @@ public SuggestionResponse searchSuggestions(String queryStr) throws IOException
LinkedHashMap suggestions = suggestionMap.get(0);
List<LinkedHashMap> options = (List<LinkedHashMap>) suggestions.get("options");
for (LinkedHashMap option : options) {
suggestionResponse.addSuggestion((LinkedHashMap) option.get("_source"));
suggestionResponse.addSuggestion((String) option.get("text"));
}

return suggestionResponse;
@@ -63,22 +57,22 @@ public SuggestionResponse searchSuggestions(String queryStr) throws IOException
public class SuggestionResponse {

public SuggestionResponse() { }
private List<LinkedHashMap> suggestions = new ArrayList<>();
private List<String> suggestions = new ArrayList<>();
private final List<LinkedHashMap> sources = new ArrayList<>();

public List<LinkedHashMap> getSuggestions() {
public List<String> getSuggestions() {
return suggestions;
}

public void addSuggestion(LinkedHashMap suggestion) {
public void addSuggestion(String suggestion) {
this.suggestions.add(suggestion);
}

public void addSource(LinkedHashMap source) {
this.sources.add(source);
}

public void setSuggestions(List<LinkedHashMap> suggestions) {
public void setSuggestions(List<String> suggestions) {
this.suggestions = suggestions;
}