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