Commit 14df38de by Madhan Neethiraj

ATLAS-2320: basic-search with wildcard classification fails when full-text query is specified

parent db77c65b
...@@ -155,7 +155,7 @@ public class ClassificationSearchProcessor extends SearchProcessor { ...@@ -155,7 +155,7 @@ public class ClassificationSearchProcessor extends SearchProcessor {
entityPredicateTraitNames = SearchPredicateUtil.getContainsAnyPredicateGenerator().generatePredicate(Constants.TRAIT_NAMES_PROPERTY_KEY, classificationType.getTypeAndAllSubTypes(), List.class); entityPredicateTraitNames = SearchPredicateUtil.getContainsAnyPredicateGenerator().generatePredicate(Constants.TRAIT_NAMES_PROPERTY_KEY, classificationType.getTypeAndAllSubTypes(), List.class);
} else { } else {
entityGraphQueryTraitNames = graph.query().has(Constants.TRAIT_NAMES_PROPERTY_KEY, NOT_EQUAL, null); entityGraphQueryTraitNames = graph.query().has(Constants.TRAIT_NAMES_PROPERTY_KEY, NOT_EQUAL, null);
entityPredicateTraitNames = SearchPredicateUtil.getNotNullPredicateGenerator().generatePredicate(Constants.TRAIT_NAMES_PROPERTY_KEY, null, List.class); entityPredicateTraitNames = SearchPredicateUtil.getNotEmptyPredicateGenerator().generatePredicate(Constants.TRAIT_NAMES_PROPERTY_KEY, null, List.class);
} }
if (context.getSearchParameters().getExcludeDeletedEntities()) { if (context.getSearchParameters().getExcludeDeletedEntities()) {
......
...@@ -93,7 +93,7 @@ public class EntitySearchProcessor extends SearchProcessor { ...@@ -93,7 +93,7 @@ public class EntitySearchProcessor extends SearchProcessor {
final Predicate traitPredicate; final Predicate traitPredicate;
if (classificationType == SearchContext.MATCH_ALL_CLASSIFICATION) { if (classificationType == SearchContext.MATCH_ALL_CLASSIFICATION) {
traitPredicate = SearchPredicateUtil.getNotNullPredicateGenerator().generatePredicate(Constants.TRAIT_NAMES_PROPERTY_KEY, null, List.class); traitPredicate = SearchPredicateUtil.getNotEmptyPredicateGenerator().generatePredicate(Constants.TRAIT_NAMES_PROPERTY_KEY, null, List.class);
} else { } else {
traitPredicate = SearchPredicateUtil.getContainsAnyPredicateGenerator().generatePredicate(Constants.TRAIT_NAMES_PROPERTY_KEY, classificationTypeAndSubTypes, List.class); traitPredicate = SearchPredicateUtil.getContainsAnyPredicateGenerator().generatePredicate(Constants.TRAIT_NAMES_PROPERTY_KEY, classificationTypeAndSubTypes, List.class);
} }
......
...@@ -61,7 +61,7 @@ public class FullTextSearchProcessor extends SearchProcessor { ...@@ -61,7 +61,7 @@ public class FullTextSearchProcessor extends SearchProcessor {
// if search includes classification criteria, adding a filter here can help avoid unnecessary // if search includes classification criteria, adding a filter here can help avoid unnecessary
// processing (and rejection) by subsequent ClassificationSearchProcessor or EntitySearchProcessor // processing (and rejection) by subsequent ClassificationSearchProcessor or EntitySearchProcessor
if (context.getClassificationType() != null) { if (context.getClassificationType() != null && context.getClassificationType() != SearchContext.MATCH_ALL_CLASSIFICATION) {
String typeAndSubTypeNamesStr = context.getClassificationType().getTypeAndAllSubTypesQryStr(); String typeAndSubTypeNamesStr = context.getClassificationType().getTypeAndAllSubTypesQryStr();
if (typeAndSubTypeNamesStr.length() <= MAX_QUERY_STR_LENGTH_TAGS) { if (typeAndSubTypeNamesStr.length() <= MAX_QUERY_STR_LENGTH_TAGS) {
......
...@@ -21,6 +21,7 @@ import org.apache.atlas.repository.graphdb.AtlasVertex; ...@@ -21,6 +21,7 @@ import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1; import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate; import org.apache.commons.collections.Predicate;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -605,6 +606,50 @@ public class SearchPredicateUtil { ...@@ -605,6 +606,50 @@ public class SearchPredicateUtil {
return ret; return ret;
} }
public static VertexAttributePredicateGenerator getNotEmptyPredicateGenerator() {
if (LOG.isDebugEnabled()) {
LOG.debug("==> getNotEmptyPredicateGenerator");
}
VertexAttributePredicateGenerator ret = new VertexAttributePredicateGenerator() {
@Override
public Predicate generatePredicate(final String attrName, final Object attrVal, final Class attrClass) {
final Predicate ret;
if (attrName == null || attrClass == null) {
ret = ALWAYS_FALSE;
} else {
ret = new VertexAttributePredicate(attrName, attrClass, true) {
@Override
protected boolean compareValue(final Object vertexAttrVal) {
boolean ret = false;
if (vertexAttrVal != null) {
if (vertexAttrVal instanceof Collection) {
ret = CollectionUtils.isNotEmpty((Collection) vertexAttrVal);
} else if (vertexAttrVal instanceof String) {
ret = StringUtils.isNotEmpty((String) vertexAttrVal);
} else {
ret = true; // for other datatypes, a non-null is treated as non-empty
}
}
return ret;
}
};
}
return ret;
}
};
if (LOG.isDebugEnabled()) {
LOG.debug("<== getNotEmptyPredicateGenerator");
}
return ret;
}
public interface VertexAttributePredicateGenerator { public interface VertexAttributePredicateGenerator {
Predicate generatePredicate(String attrName, Object attrVal, Class attrClass); Predicate generatePredicate(String attrName, Object attrVal, Class attrClass);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment