mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +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)
|
||||
throws E
|
||||
{
|
||||
|
||||
QueryParserExpressionAdaptor<Q, E> expressionAdaptor = luceneContext.getLuceneQueryParserAdaptor().getExpressionAdaptor();
|
||||
boolean must = false;
|
||||
boolean must_not = false;
|
||||
boolean mustNot = false;
|
||||
for (Constraint constraint : getConstraints())
|
||||
{
|
||||
if (constraint instanceof LuceneQueryBuilderComponent)
|
||||
@@ -84,23 +83,20 @@ public class LuceneConjunction<Q, S, E extends Throwable> extends BaseConjunctio
|
||||
break;
|
||||
case EXCLUDE:
|
||||
expressionAdaptor.addExcluded(constraintQuery, constraint.getBoost());
|
||||
must_not = true;
|
||||
mustNot = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
if(!must && must_not)
|
||||
{
|
||||
expressionAdaptor.addRequired(luceneContext.getLuceneQueryParserAdaptor().getMatchAllNodesQuery());
|
||||
}
|
||||
}
|
||||
if(!must && mustNot)
|
||||
{
|
||||
expressionAdaptor.addRequired(luceneContext.getLuceneQueryParserAdaptor().getMatchAllNodesQuery());
|
||||
}
|
||||
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.Source;
|
||||
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.Score;
|
||||
import org.alfresco.service.cmr.search.SearchParameters.SortDefinition;
|
||||
import org.alfresco.service.cmr.search.SearchParameters.SortDefinition.SortType;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* @author andyh
|
||||
@@ -72,10 +70,8 @@ public class LuceneQuery<Q, S, E extends Throwable> extends BaseQuery implements
|
||||
QueryParserExpressionAdaptor<Q, E> expressionBuilder = luceneContext.getLuceneQueryParserAdaptor().getExpressionAdaptor();
|
||||
|
||||
boolean must = false;
|
||||
boolean must_not = false;
|
||||
boolean mustNot = false;
|
||||
|
||||
ArrayList<Pair<Constraint, Q>> queriestoConjoin = new ArrayList<>();
|
||||
|
||||
if (selectors != null)
|
||||
{
|
||||
for (String selector : selectors)
|
||||
@@ -86,7 +82,6 @@ public class LuceneQuery<Q, S, E extends Throwable> extends BaseQuery implements
|
||||
@SuppressWarnings("unchecked")
|
||||
LuceneQueryBuilderComponent<Q, S, E> luceneQueryBuilderComponent = (LuceneQueryBuilderComponent<Q, S, E>) current;
|
||||
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)
|
||||
{
|
||||
expressionBuilder.addRequired(selectorQuery);
|
||||
@@ -108,8 +103,7 @@ public class LuceneQuery<Q, S, E extends Throwable> extends BaseQuery implements
|
||||
@SuppressWarnings("unchecked")
|
||||
LuceneQueryBuilderComponent<Q, S, E> luceneQueryBuilderComponent = (LuceneQueryBuilderComponent<Q, S, E>) constraint;
|
||||
Q constraintQuery = luceneQueryBuilderComponent.addComponent(selectors, null, luceneContext, functionContext);
|
||||
queriestoConjoin.add(new Pair<Constraint, Q>(constraint, constraintQuery));
|
||||
|
||||
|
||||
if (constraintQuery != null)
|
||||
{
|
||||
switch (constraint.getOccur())
|
||||
@@ -124,7 +118,7 @@ public class LuceneQuery<Q, S, E extends Throwable> extends BaseQuery implements
|
||||
break;
|
||||
case EXCLUDE:
|
||||
expressionBuilder.addExcluded(constraintQuery, constraint.getBoost());
|
||||
must_not = true;
|
||||
mustNot = true;
|
||||
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());
|
||||
}
|
||||
|
||||
return expressionBuilder.getQuery();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -165,10 +158,10 @@ public class LuceneQuery<Q, S, E extends Throwable> extends BaseQuery implements
|
||||
{
|
||||
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())
|
||||
{
|
||||
|
Reference in New Issue
Block a user