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:
@@ -10,8 +10,6 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -229,28 +227,6 @@ public class DataStore implements AutoCloseable {
|
||||
|
||||
}
|
||||
|
||||
public SortedSet<String> getAvailableValuesForKey(final Query query, final String key) {
|
||||
|
||||
final SortedSet<String> result = new TreeSet<>();
|
||||
if (query.getQuery().isEmpty()) {
|
||||
final PartitionIdSource partitionIdSource = new DatePartitioner(query.getDateRange());
|
||||
tagToDocsId.visitValues(partitionIdSource, new Tag(key, ""),
|
||||
(tag, __) -> result.add(tag.getValueAsString()));
|
||||
} else {
|
||||
final List<Doc> docs = search(query);
|
||||
for (final Doc doc : docs) {
|
||||
final String valueForKey = doc.getTags().getValue(key);
|
||||
|
||||
if (valueForKey != null) {
|
||||
result.add(valueForKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private PartitionLongList executeQuery(final Query query) {
|
||||
final long start = System.nanoTime();
|
||||
synchronized (docIdToDoc) {
|
||||
|
||||
Reference in New Issue
Block a user