fetch available values for gallery via autocomplete method
We had a method that returned the values of a field with respect to a query. That method was inefficient, because it executed the query, fetched all Docs and collected the values. The autocomplete method we introduced a while back can answer the same question but much more efficiently.
This commit is contained in:
@@ -11,12 +11,12 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.lucares.pdb.api.DateTimeRange;
|
||||
import org.lucares.pdb.api.Query;
|
||||
import org.lucares.pdb.api.QueryWithCaretMarker;
|
||||
import org.lucares.pdb.datastore.Proposal;
|
||||
import org.lucares.pdb.plot.api.AxisScale;
|
||||
@@ -252,9 +252,14 @@ public class PdbController implements HardcodedValues, PropertyKeys {
|
||||
SortedSet<String> fields(@PathVariable(name = "fieldName") final String fieldName,
|
||||
@RequestParam(name = "query") final String query) {
|
||||
|
||||
final DateTimeRange dateRange = DateTimeRange.max();
|
||||
final Query q = new Query(query, dateRange);
|
||||
final SortedSet<String> fields = db.getFieldsValues(q, fieldName);
|
||||
final String q = String.format("(%s) and %s=", query, fieldName);
|
||||
final int caretIndex = q.length() + 1; // the autocomplete methods needs a 1-based index
|
||||
|
||||
final AutocompleteResponse autocompleteResponse = this.autocomplete(q, caretIndex);
|
||||
final List<AutocompleteProposal> proposals = autocompleteResponse.getProposals();
|
||||
|
||||
final SortedSet<String> fields = CollectionUtils.map(proposals, new TreeSet<>(),
|
||||
AutocompleteProposal::getValue);
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user