Skip to content

Commit

Permalink
Merge pull request #1669 from MMcM/lucene-planner-unsupported-comparison
Browse files Browse the repository at this point in the history
Fixes #1668: Unsupported comparisons cause exception for Lucene index
  • Loading branch information
tian-yizuo committed May 17, 2022
2 parents bd7a5a2 + e986520 commit 2da36fe
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -63,12 +65,14 @@
* plan created and from there into the record cursor which creates a Lucene sort object.
*/
public class LucenePlanner extends RecordQueryPlanner {
private static final Logger logger = LoggerFactory.getLogger(LucenePlanner.class);

public LucenePlanner(@Nonnull final RecordMetaData metaData, @Nonnull final RecordStoreState recordStoreState, final PlannableIndexTypes indexTypes, final FDBStoreTimer timer) {
super(metaData, recordStoreState, indexTypes, timer);
}

@Override
@Nullable
protected ScoredPlan planOther(@Nonnull CandidateScan candidateScan,
@Nonnull Index index, @Nonnull QueryComponent filter,
@Nullable KeyExpression sort, boolean sortReverse) {
Expand All @@ -79,6 +83,7 @@ protected ScoredPlan planOther(@Nonnull CandidateScan candidateScan,
}
}

@Nullable
private ScoredPlan planLucene(@Nonnull CandidateScan candidateScan,
@Nonnull Index index, @Nonnull QueryComponent filter,
@Nullable KeyExpression sort, boolean sortReverse) {
Expand Down Expand Up @@ -154,6 +159,7 @@ static class LucenePlanState {
}
}

@Nullable
private LuceneScanParameters getSpecialScan(@Nonnull LucenePlanState state, @Nonnull FilterSatisfiedMask filterMask) {
QueryComponent queryComponent = state.groupingComparisons.isEmpty() ? state.filter : filterMask.getUnsatisfiedFilter();
if (queryComponent instanceof LuceneQueryComponent) {
Expand Down Expand Up @@ -188,6 +194,7 @@ private LuceneScanParameters getSpecialScan(@Nonnull LucenePlanState state, @Non
return null;
}

@Nullable
private LuceneQueryClause getQueryForFilter(@Nonnull LucenePlanState state, @Nonnull QueryComponent filter,
@Nullable String parentFieldName, @Nullable FilterSatisfiedMask filterMask) {
if (filter instanceof LuceneQueryComponent) {
Expand All @@ -204,6 +211,7 @@ private LuceneQueryClause getQueryForFilter(@Nonnull LucenePlanState state, @Non
return null;
}

@Nullable
private LuceneQueryClause getQueryForLuceneComponent(@Nonnull LucenePlanState state, @Nonnull LuceneQueryComponent filter,
@Nullable FilterSatisfiedMask filterMask) {
//TODO figure out how to take into account the parentField name here. Or maybe disallow this if its contained within a
Expand All @@ -224,6 +232,7 @@ private LuceneQueryClause getQueryForLuceneComponent(@Nonnull LucenePlanState st
}
}

@Nullable
@SuppressWarnings("java:S3776")
private LuceneQueryClause getQueryForAndOr(@Nonnull LucenePlanState state, @Nonnull AndOrComponent filter,
@Nullable String parentFieldName, @Nullable FilterSatisfiedMask filterMask) {
Expand Down Expand Up @@ -254,6 +263,7 @@ private LuceneQueryClause getQueryForAndOr(@Nonnull LucenePlanState state, @Nonn
return new LuceneBooleanQuery(childClauses, occur);
}

@Nullable
private LuceneQueryClause getQueryForFieldWithComparison(@Nonnull LucenePlanState state, @Nonnull FieldWithComparison filter,
@Nullable String parentFieldName, @Nullable FilterSatisfiedMask filterSatisfiedMask) {
if (filterSatisfiedMask != null && filterSatisfiedMask.isSatisfied()) {
Expand All @@ -270,9 +280,17 @@ private LuceneQueryClause getQueryForFieldWithComparison(@Nonnull LucenePlanStat
if (filterSatisfiedMask != null) {
filterSatisfiedMask.setSatisfied(true);
}
return LuceneQueryFieldComparisonClause.create(completeFieldName, fieldType, filter.getComparison());
try {
return LuceneQueryFieldComparisonClause.create(completeFieldName, fieldType, filter.getComparison());
} catch (RecordCoreException ex) {
if (logger.isDebugEnabled()) {
logger.debug("no query for comparison " + filter, ex);
}
return null;
}
}

@Nullable
// TODO Better implementation of nesting that actually takes into account
// positioning of the fields in relation to each other
// This should use the multiField query parser. Very much a TODO
Expand Down

0 comments on commit 2da36fe

Please sign in to comment.