add examples to the query suggestions

This commit is contained in:
2019-10-26 19:14:51 +02:00
parent f235890cc1
commit 3190074ce3
2 changed files with 24 additions and 1 deletions

View File

@@ -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,7 +239,21 @@ public class PdbController implements HardcodedValues, PropertyKeys {
return result;
}
@RequestMapping(path = "/fields", //
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, //
produces = MediaType.APPLICATION_JSON_VALUE //

View File

@@ -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";
}