add metric logger for query completion evaluation

This commit is contained in:
2019-02-06 15:51:41 +00:00
parent 668d73c926
commit 99cdf557b3

View File

@@ -15,9 +15,17 @@ import org.lucares.pdb.datastore.lang.Expression.Not;
import org.lucares.pdb.datastore.lang.Expression.Or;
import org.lucares.pdb.datastore.lang.Expression.Property;
import org.lucares.utils.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<String>> {
private static final Logger METRIC_AND_CARET_LOGGER = LoggerFactory
.getLogger("org.lucares.metrics.queryCompletion.expressionEvaluation.andCaret");
private static final Logger METRIC_LOGGER = LoggerFactory
.getLogger("org.lucares.metrics.queryCompletion.expressionEvaluation");
private static final class AndCaretExpressionVisitor extends ExpressionVisitor<SortedSet<String>> {
private final QueryCompletionIndex index;
private final String field;
@@ -29,16 +37,18 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
@Override
public SortedSet<String> visit(final Property property) {
final long start = System.nanoTime();
final String fieldA = property.getProperty();
final String valueA = property.getValue().getValue();
return index.find(fieldA, valueA, field);
SortedSet<String> result = index.find(fieldA, valueA, field);
METRIC_AND_CARET_LOGGER.debug("{}: {}ms", property, (System.nanoTime() - start) / 1_000_000.0);
return result;
}
@Override
public SortedSet<String> visit(final InExpression expression) {
final long start = System.nanoTime();
final SortedSet<String> result = new TreeSet<>();
final String property = expression.getProperty();
final List<String> values = expression.getValues();
@@ -46,13 +56,14 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
final SortedSet<String> candidates = index.find(property, value, field);
result.addAll(candidates);
}
METRIC_AND_CARET_LOGGER.debug("{}: {}ms", expression, (System.nanoTime() - start) / 1_000_000.0);
return result;
}
@Override
public SortedSet<String> visit(final And expression) {
final long start = System.nanoTime();
try {
final Expression left = expression.getLeft();
final Expression right = expression.getRight();
@@ -75,10 +86,15 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
return result;
}
} finally {
METRIC_AND_CARET_LOGGER.debug("{}: {}ms", expression, (System.nanoTime() - start) / 1_000_000.0);
}
}
@Override
public SortedSet<String> visit(final Or expression) {
final long start = System.nanoTime();
final Expression left = expression.getLeft();
final Expression right = expression.getRight();
@@ -87,12 +103,14 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
result.addAll(rightResult);
METRIC_AND_CARET_LOGGER.debug("{}: {}ms", expression, (System.nanoTime() - start) / 1_000_000.0);
return result;
}
@Override
public SortedSet<String> visit(final Not expression) {
final long start = System.nanoTime();
if (!(expression.getExpression() instanceof Property)) {
throw new UnsupportedOperationException("NOT expressions like '" + expression
+ "' are not supported. Only 'NOT property=value' expressions are supported.");
@@ -109,6 +127,7 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
final SortedSet<String> result = CollectionUtils.removeAll(valuesNotForField, valuesOnlyAvailableInField,
TreeSet::new);
METRIC_AND_CARET_LOGGER.debug("{}: {}ms", expression, (System.nanoTime() - start) / 1_000_000.0);
return result;
}
}
@@ -122,6 +141,7 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
@Override
public SortedSet<String> visit(final Property property) {
final long start = System.nanoTime();
final String field = property.getProperty();
final String value = property.getValue().getValue();
@@ -129,12 +149,15 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
final String valuePrefix = value.substring(0, value.indexOf(NewProposerParser.CARET_MARKER));
return GloblikePattern.filterValues(allValuesForField, valuePrefix, TreeSet::new);
final TreeSet<String> result = GloblikePattern.filterValues(allValuesForField, valuePrefix, TreeSet::new);
METRIC_LOGGER.debug("{}: {}ms", property, (System.nanoTime() - start) / 1_000_000.0);
return result;
}
@Override
public SortedSet<String> visit(final AndCaretExpression expression) {
final long start = System.nanoTime();
final Property caretExpression = expression.getCaretExpression();
final String field = caretExpression.getProperty();
final String valueWithCaretMarker = caretExpression.getValue().getValue();
@@ -146,12 +169,16 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
final SortedSet<String> candidateValues = rightHandExpression
.visit(new AndCaretExpressionVisitor(queryCompletionIndex, field));
return GloblikePattern.filterValues(candidateValues, valuePrefix, TreeSet::new);
final TreeSet<String> result = GloblikePattern.filterValues(candidateValues, valuePrefix, TreeSet::new);
METRIC_LOGGER.debug("{}: {}ms", expression, (System.nanoTime() - start) / 1_000_000.0);
return result;
}
@Override
public SortedSet<String> visit(final AndNotCaretExpression expression) {
final long start = System.nanoTime();
final Property caretExpression = expression.getCaretExpression();
final String field = caretExpression.getProperty();
final String valueWithCaretMarker = caretExpression.getValue().getValue();
@@ -174,6 +201,7 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
}
final SortedSet<String> result = CollectionUtils.retainAll(rightHandValues,
valuesForFieldMatchingCaretExpression, TreeSet::new);
METRIC_LOGGER.debug("{}: {}ms", expression, (System.nanoTime() - start) / 1_000_000.0);
return result;
}
@@ -183,6 +211,7 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
final String field;
final Expression innerExpression = expression.getExpression();
if (innerExpression instanceof Property) {
final long start = System.nanoTime();
field = ((Property) innerExpression).getProperty();
final SortedSet<String> allValuesForField = queryCompletionIndex.findAllValuesForField(field);
final String valueWithCaretMarker = ((Property) innerExpression).getValue().getValue();
@@ -190,6 +219,7 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
valueWithCaretMarker.indexOf(NewProposerParser.CARET_MARKER));
final TreeSet<String> result = GloblikePattern.filterValues(allValuesForField, valuePrefix + "*",
TreeSet::new);
METRIC_LOGGER.debug("{}: {}ms", expression, (System.nanoTime() - start) / 1_000_000.0);
return result;
} else {
throw new UnsupportedOperationException();
@@ -198,6 +228,7 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
@Override
public SortedSet<String> visit(final Or expression) {
final long start = System.nanoTime();
final Expression left = expression.getLeft();
final Expression right = expression.getRight();
@@ -205,13 +236,13 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
final SortedSet<String> rightResult = right.visit(this);
result.addAll(rightResult);
METRIC_LOGGER.debug("{}: {}ms", expression, (System.nanoTime() - start) / 1_000_000.0);
return result;
}
@Override
public SortedSet<String> visit(final And expression) {
final long start = System.nanoTime();
final Expression left = expression.getLeft();
final Expression right = expression.getRight();
@@ -219,7 +250,7 @@ public class FindValuesForQueryCompletion extends ExpressionVisitor<SortedSet<St
final SortedSet<String> rightResult = right.visit(this);
result.retainAll(rightResult);
METRIC_LOGGER.debug("{}: {}ms", expression, (System.nanoTime() - start) / 1_000_000.0);
return result;
}
}