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.TreeSet;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.lucares.pdb.api.DateTimeRange;
|
import org.lucares.pdb.api.DateTimeRange;
|
||||||
@@ -74,6 +75,9 @@ public class PdbController implements HardcodedValues, PropertyKeys {
|
|||||||
|
|
||||||
@Value("${" + PRODUCTION_MODE + ":true}")
|
@Value("${" + PRODUCTION_MODE + ":true}")
|
||||||
private boolean modeProduction;
|
private boolean modeProduction;
|
||||||
|
|
||||||
|
@Value("${"+QUERY_EXAMPLES+":}")
|
||||||
|
private String queryExamples;
|
||||||
|
|
||||||
public PdbController(final PerformanceDb db, final Plotter plotter) {
|
public PdbController(final PerformanceDb db, final Plotter plotter) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
@@ -224,6 +228,9 @@ public class PdbController implements HardcodedValues, PropertyKeys {
|
|||||||
final AutocompleteResponse result = new AutocompleteResponse();
|
final AutocompleteResponse result = new AutocompleteResponse();
|
||||||
|
|
||||||
final List<Proposal> proposals = db.autocomplete(q);
|
final List<Proposal> proposals = db.autocomplete(q);
|
||||||
|
if (query.trim().length() == 0) {
|
||||||
|
proposals.addAll(exampleProposals());
|
||||||
|
}
|
||||||
|
|
||||||
final List<AutocompleteProposal> autocompleteProposals = toAutocompleteProposals(proposals);
|
final List<AutocompleteProposal> autocompleteProposals = toAutocompleteProposals(proposals);
|
||||||
Collections.sort(autocompleteProposals, new AutocompleteProposalByValue());
|
Collections.sort(autocompleteProposals, new AutocompleteProposalByValue());
|
||||||
@@ -232,7 +239,21 @@ public class PdbController implements HardcodedValues, PropertyKeys {
|
|||||||
return result;
|
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, //
|
method = RequestMethod.GET, //
|
||||||
//consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, //
|
//consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, //
|
||||||
produces = MediaType.APPLICATION_JSON_VALUE //
|
produces = MediaType.APPLICATION_JSON_VALUE //
|
||||||
|
|||||||
@@ -17,4 +17,6 @@ public interface PropertyKeys {
|
|||||||
* property is used to switch Vue.js into production or development mode.
|
* property is used to switch Vue.js into production or development mode.
|
||||||
*/
|
*/
|
||||||
String PRODUCTION_MODE = "mode.production";
|
String PRODUCTION_MODE = "mode.production";
|
||||||
|
|
||||||
|
String QUERY_EXAMPLES = "query.examples";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user