add examples to the query suggestions
This commit is contained in:
@@ -15,6 +15,7 @@ import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.lucares.pdb.api.DateTimeRange;
|
||||
@@ -75,6 +76,9 @@ public class PdbController implements HardcodedValues, PropertyKeys {
|
||||
@Value("${" + PRODUCTION_MODE + ":true}")
|
||||
private boolean modeProduction;
|
||||
|
||||
@Value("${"+QUERY_EXAMPLES+":}")
|
||||
private String queryExamples;
|
||||
|
||||
public PdbController(final PerformanceDb db, final Plotter plotter) {
|
||||
this.db = db;
|
||||
this.plotter = plotter;
|
||||
@@ -224,6 +228,9 @@ public class PdbController implements HardcodedValues, PropertyKeys {
|
||||
final AutocompleteResponse result = new AutocompleteResponse();
|
||||
|
||||
final List<Proposal> proposals = db.autocomplete(q);
|
||||
if (query.trim().length() == 0) {
|
||||
proposals.addAll(exampleProposals());
|
||||
}
|
||||
|
||||
final List<AutocompleteProposal> autocompleteProposals = toAutocompleteProposals(proposals);
|
||||
Collections.sort(autocompleteProposals, new AutocompleteProposalByValue());
|
||||
@@ -232,6 +239,20 @@ public class PdbController implements HardcodedValues, PropertyKeys {
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Proposal> exampleProposals() {
|
||||
List<Proposal> result = new ArrayList<Proposal>();
|
||||
|
||||
if (queryExamples.length() > 0) {
|
||||
final String[] exampleQueries = queryExamples.split(Pattern.quote(";"));
|
||||
for (String example : exampleQueries) {
|
||||
Proposal p = new Proposal(" Example: "+example, example, true, example+" ", example.length()+1);
|
||||
result.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/fields", //
|
||||
method = RequestMethod.GET, //
|
||||
//consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, //
|
||||
|
||||
@@ -17,4 +17,6 @@ public interface PropertyKeys {
|
||||
* property is used to switch Vue.js into production or development mode.
|
||||
*/
|
||||
String PRODUCTION_MODE = "mode.production";
|
||||
|
||||
String QUERY_EXAMPLES = "query.examples";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user