mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ACS-2699 Update logic around + and - for lucene queries. (#2144)
Remove unused list of constraints. Only add match all clause once if necessary. Also fix a few PMD violations.
This commit is contained in:
@@ -58,10 +58,9 @@ public class LuceneConjunction<Q, S, E extends Throwable> extends BaseConjunctio
|
|||||||
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, QueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
|
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, QueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
|
||||||
throws E
|
throws E
|
||||||
{
|
{
|
||||||
|
|
||||||
QueryParserExpressionAdaptor<Q, E> expressionAdaptor = luceneContext.getLuceneQueryParserAdaptor().getExpressionAdaptor();
|
QueryParserExpressionAdaptor<Q, E> expressionAdaptor = luceneContext.getLuceneQueryParserAdaptor().getExpressionAdaptor();
|
||||||
boolean must = false;
|
boolean must = false;
|
||||||
boolean must_not = false;
|
boolean mustNot = false;
|
||||||
for (Constraint constraint : getConstraints())
|
for (Constraint constraint : getConstraints())
|
||||||
{
|
{
|
||||||
if (constraint instanceof LuceneQueryBuilderComponent)
|
if (constraint instanceof LuceneQueryBuilderComponent)
|
||||||
@@ -84,23 +83,20 @@ public class LuceneConjunction<Q, S, E extends Throwable> extends BaseConjunctio
|
|||||||
break;
|
break;
|
||||||
case EXCLUDE:
|
case EXCLUDE:
|
||||||
expressionAdaptor.addExcluded(constraintQuery, constraint.getBoost());
|
expressionAdaptor.addExcluded(constraintQuery, constraint.getBoost());
|
||||||
must_not = true;
|
mustNot = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
if(!must && must_not)
|
}
|
||||||
|
if(!must && mustNot)
|
||||||
{
|
{
|
||||||
expressionAdaptor.addRequired(luceneContext.getLuceneQueryParserAdaptor().getMatchAllNodesQuery());
|
expressionAdaptor.addRequired(luceneContext.getLuceneQueryParserAdaptor().getMatchAllNodesQuery());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return expressionAdaptor.getQuery();
|
return expressionAdaptor.getQuery();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -40,12 +40,10 @@ import org.alfresco.repo.search.impl.querymodel.PropertyArgument;
|
|||||||
import org.alfresco.repo.search.impl.querymodel.Selector;
|
import org.alfresco.repo.search.impl.querymodel.Selector;
|
||||||
import org.alfresco.repo.search.impl.querymodel.Source;
|
import org.alfresco.repo.search.impl.querymodel.Source;
|
||||||
import org.alfresco.repo.search.impl.querymodel.impl.BaseQuery;
|
import org.alfresco.repo.search.impl.querymodel.impl.BaseQuery;
|
||||||
import org.alfresco.repo.search.impl.querymodel.impl.SimpleConstraint;
|
|
||||||
import org.alfresco.repo.search.impl.querymodel.impl.functions.PropertyAccessor;
|
import org.alfresco.repo.search.impl.querymodel.impl.functions.PropertyAccessor;
|
||||||
import org.alfresco.repo.search.impl.querymodel.impl.functions.Score;
|
import org.alfresco.repo.search.impl.querymodel.impl.functions.Score;
|
||||||
import org.alfresco.service.cmr.search.SearchParameters.SortDefinition;
|
import org.alfresco.service.cmr.search.SearchParameters.SortDefinition;
|
||||||
import org.alfresco.service.cmr.search.SearchParameters.SortDefinition.SortType;
|
import org.alfresco.service.cmr.search.SearchParameters.SortDefinition.SortType;
|
||||||
import org.alfresco.util.Pair;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author andyh
|
* @author andyh
|
||||||
@@ -72,9 +70,7 @@ public class LuceneQuery<Q, S, E extends Throwable> extends BaseQuery implements
|
|||||||
QueryParserExpressionAdaptor<Q, E> expressionBuilder = luceneContext.getLuceneQueryParserAdaptor().getExpressionAdaptor();
|
QueryParserExpressionAdaptor<Q, E> expressionBuilder = luceneContext.getLuceneQueryParserAdaptor().getExpressionAdaptor();
|
||||||
|
|
||||||
boolean must = false;
|
boolean must = false;
|
||||||
boolean must_not = false;
|
boolean mustNot = false;
|
||||||
|
|
||||||
ArrayList<Pair<Constraint, Q>> queriestoConjoin = new ArrayList<>();
|
|
||||||
|
|
||||||
if (selectors != null)
|
if (selectors != null)
|
||||||
{
|
{
|
||||||
@@ -86,7 +82,6 @@ public class LuceneQuery<Q, S, E extends Throwable> extends BaseQuery implements
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
LuceneQueryBuilderComponent<Q, S, E> luceneQueryBuilderComponent = (LuceneQueryBuilderComponent<Q, S, E>) current;
|
LuceneQueryBuilderComponent<Q, S, E> luceneQueryBuilderComponent = (LuceneQueryBuilderComponent<Q, S, E>) current;
|
||||||
Q selectorQuery = luceneQueryBuilderComponent.addComponent(selectors, null, luceneContext, functionContext);
|
Q selectorQuery = luceneQueryBuilderComponent.addComponent(selectors, null, luceneContext, functionContext);
|
||||||
queriestoConjoin.add(new Pair<Constraint, Q>(new SimpleConstraint(org.alfresco.repo.search.impl.querymodel.Constraint.Occur.MANDATORY), selectorQuery));
|
|
||||||
if (selectorQuery != null)
|
if (selectorQuery != null)
|
||||||
{
|
{
|
||||||
expressionBuilder.addRequired(selectorQuery);
|
expressionBuilder.addRequired(selectorQuery);
|
||||||
@@ -108,7 +103,6 @@ public class LuceneQuery<Q, S, E extends Throwable> extends BaseQuery implements
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
LuceneQueryBuilderComponent<Q, S, E> luceneQueryBuilderComponent = (LuceneQueryBuilderComponent<Q, S, E>) constraint;
|
LuceneQueryBuilderComponent<Q, S, E> luceneQueryBuilderComponent = (LuceneQueryBuilderComponent<Q, S, E>) constraint;
|
||||||
Q constraintQuery = luceneQueryBuilderComponent.addComponent(selectors, null, luceneContext, functionContext);
|
Q constraintQuery = luceneQueryBuilderComponent.addComponent(selectors, null, luceneContext, functionContext);
|
||||||
queriestoConjoin.add(new Pair<Constraint, Q>(constraint, constraintQuery));
|
|
||||||
|
|
||||||
if (constraintQuery != null)
|
if (constraintQuery != null)
|
||||||
{
|
{
|
||||||
@@ -124,7 +118,7 @@ public class LuceneQuery<Q, S, E extends Throwable> extends BaseQuery implements
|
|||||||
break;
|
break;
|
||||||
case EXCLUDE:
|
case EXCLUDE:
|
||||||
expressionBuilder.addExcluded(constraintQuery, constraint.getBoost());
|
expressionBuilder.addExcluded(constraintQuery, constraint.getBoost());
|
||||||
must_not = true;
|
mustNot = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,13 +129,12 @@ public class LuceneQuery<Q, S, E extends Throwable> extends BaseQuery implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!must && must_not)
|
if (!must && mustNot)
|
||||||
{
|
{
|
||||||
expressionBuilder.addRequired(luceneContext.getLuceneQueryParserAdaptor().getMatchAllNodesQuery());
|
expressionBuilder.addRequired(luceneContext.getLuceneQueryParserAdaptor().getMatchAllNodesQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
return expressionBuilder.getQuery();
|
return expressionBuilder.getQuery();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -165,10 +158,10 @@ public class LuceneQuery<Q, S, E extends Throwable> extends BaseQuery implements
|
|||||||
{
|
{
|
||||||
if ((getOrderings() == null) || (getOrderings().size() == 0))
|
if ((getOrderings() == null) || (getOrderings().size() == 0))
|
||||||
{
|
{
|
||||||
return Collections.<SortDefinition>emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<SortDefinition> definitions = new ArrayList<SortDefinition>(getOrderings().size());
|
List<SortDefinition> definitions = new ArrayList<>(getOrderings().size());
|
||||||
|
|
||||||
for (Ordering ordering : getOrderings())
|
for (Ordering ordering : getOrderings())
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user