Commit 13fed7a9 by apoorvnaik Committed by Madhan Neethiraj

ATLAS-2117: basic search updates to handle issue caused by tokenization in indexer

parent 8eb9c956
...@@ -163,14 +163,12 @@ public abstract class SearchProcessor { ...@@ -163,14 +163,12 @@ public abstract class SearchProcessor {
} }
} else if (StringUtils.isNotEmpty(filterCriteria.getAttributeName())) { } else if (StringUtils.isNotEmpty(filterCriteria.getAttributeName())) {
try { try {
String attributeName = filterCriteria.getAttributeName(); String attributeName = filterCriteria.getAttributeName();
String qualifiedName = structType.getQualifiedAttributeName(attributeName);
Set<String> indexedKeys = context.getIndexedKeys();
if (indexedKeys != null && indexedKeys.contains(qualifiedName)) { if (isIndexSearchable(filterCriteria, structType)) {
indexFiltered.add(attributeName); indexFiltered.add(attributeName);
} else { } else {
LOG.warn("search includes non-indexed attribute '{}'; might cause poor performance", qualifiedName); LOG.warn("not using index-search for attribute '{}' - its either non-indexed or a string attribute used with NEQ operator; might cause poor performance", structType.getQualifiedAttributeName(attributeName));
graphFiltered.add(attributeName); graphFiltered.add(attributeName);
} }
...@@ -222,9 +220,7 @@ public abstract class SearchProcessor { ...@@ -222,9 +220,7 @@ public abstract class SearchProcessor {
} }
} else if (StringUtils.isNotEmpty(filterCriteria.getAttributeName())) { } else if (StringUtils.isNotEmpty(filterCriteria.getAttributeName())) {
try { try {
String qualifiedName = structType.getQualifiedAttributeName(filterCriteria.getAttributeName()); if (insideOrCondition && !isIndexSearchable(filterCriteria, structType)) {
if (insideOrCondition && (indexedKeys == null || !indexedKeys.contains(qualifiedName))) {
ret = false; ret = false;
} }
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
...@@ -326,6 +322,25 @@ public abstract class SearchProcessor { ...@@ -326,6 +322,25 @@ public abstract class SearchProcessor {
indexQuery.append("v.\"").append(Constants.STATE_PROPERTY_KEY).append("\":ACTIVE"); indexQuery.append("v.\"").append(Constants.STATE_PROPERTY_KEY).append("\":ACTIVE");
} }
private boolean isIndexSearchable(FilterCriteria filterCriteria, AtlasStructType structType) throws AtlasBaseException {
String qualifiedName = structType.getQualifiedAttributeName(filterCriteria.getAttributeName());
Set<String> indexedKeys = context.getIndexedKeys();
boolean ret = indexedKeys != null && indexedKeys.contains(qualifiedName);
if (ret) { // index exists
// Don't use index query for NEQ on string type attributes - as it might return fewer entries due to tokenization of vertex property value by indexer
if (filterCriteria.getOperator() == SearchParameters.Operator.NEQ) {
AtlasType attributeType = structType.getAttributeType(filterCriteria.getAttributeName());
if (AtlasBaseTypeDef.ATLAS_TYPE_STRING.equals(attributeType.getTypeName())) {
ret = false;
}
}
}
return ret;
}
private String toIndexQuery(AtlasStructType type, FilterCriteria criteria, Set<String> indexAttributes, int level) { private String toIndexQuery(AtlasStructType type, FilterCriteria criteria, Set<String> indexAttributes, int level) {
return toIndexQuery(type, criteria, indexAttributes, new StringBuilder(), level); return toIndexQuery(type, criteria, indexAttributes, new StringBuilder(), level);
} }
......
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