Commit 62d85a4c by Madhan Neethiraj

ATLAS-1961: Basic search improvement in use of Solr index for attribute filtering (# 5)

parent 13ba156f
...@@ -18,10 +18,8 @@ ...@@ -18,10 +18,8 @@
package org.apache.atlas.discovery; package org.apache.atlas.discovery;
import org.apache.atlas.model.discovery.SearchParameters.FilterCriteria; import org.apache.atlas.model.discovery.SearchParameters.FilterCriteria;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.*; import org.apache.atlas.repository.graphdb.*;
import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1;
import org.apache.atlas.type.AtlasClassificationType; import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType; import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.utils.AtlasPerfTracer;
......
...@@ -20,12 +20,10 @@ package org.apache.atlas.discovery; ...@@ -20,12 +20,10 @@ package org.apache.atlas.discovery;
import org.apache.atlas.model.discovery.SearchParameters; import org.apache.atlas.model.discovery.SearchParameters;
import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasIndexQuery; import org.apache.atlas.repository.graphdb.AtlasIndexQuery;
import org.apache.atlas.repository.graphdb.AtlasVertex; 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.atlas.utils.AtlasPerfTracer; import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -55,7 +53,8 @@ public class FullTextSearchProcessor extends SearchProcessor { ...@@ -55,7 +53,8 @@ public class FullTextSearchProcessor extends SearchProcessor {
Set<String> typeAndSubTypeNames = context.getEntityType().getTypeAndAllSubTypes(); Set<String> typeAndSubTypeNames = context.getEntityType().getTypeAndAllSubTypes();
if (typeAndSubTypeNames.size() <= MAX_ENTITY_TYPES_IN_INDEX_QUERY) { if (typeAndSubTypeNames.size() <= MAX_ENTITY_TYPES_IN_INDEX_QUERY) {
queryString.append(AND_STR).append("(").append(StringUtils.join(typeAndSubTypeNames, SPACE_STRING)).append(")"); queryString.append(AND_STR);
appendIndexQueryValue(typeAndSubTypeNames, queryString);
} else { } else {
LOG.warn("'{}' has too many subtypes ({}) to include in index-query; might cause poor performance", LOG.warn("'{}' has too many subtypes ({}) to include in index-query; might cause poor performance",
context.getEntityType().getTypeName(), typeAndSubTypeNames.size()); context.getEntityType().getTypeName(), typeAndSubTypeNames.size());
...@@ -68,17 +67,14 @@ public class FullTextSearchProcessor extends SearchProcessor { ...@@ -68,17 +67,14 @@ public class FullTextSearchProcessor extends SearchProcessor {
Set<String> typeAndSubTypeNames = context.getClassificationType().getTypeAndAllSubTypes(); Set<String> typeAndSubTypeNames = context.getClassificationType().getTypeAndAllSubTypes();
if (typeAndSubTypeNames.size() <= MAX_CLASSIFICATION_TYPES_IN_INDEX_QUERY) { if (typeAndSubTypeNames.size() <= MAX_CLASSIFICATION_TYPES_IN_INDEX_QUERY) {
queryString.append(AND_STR).append("(").append(StringUtils.join(typeAndSubTypeNames, SPACE_STRING)).append(")"); queryString.append(AND_STR);
appendIndexQueryValue(typeAndSubTypeNames, queryString);
} else { } else {
LOG.warn("'{}' has too many subtypes ({}) to include in index-query; might cause poor performance", LOG.warn("'{}' has too many subtypes ({}) to include in index-query; might cause poor performance",
context.getClassificationType().getTypeName(), typeAndSubTypeNames.size()); context.getClassificationType().getTypeName(), typeAndSubTypeNames.size());
} }
} }
if (context.getSearchParameters().getExcludeDeletedEntities()) {
queryString.append(AND_STR).append("(ACTIVE)");
}
queryString.append(")"); queryString.append(")");
indexQuery = context.getGraph().indexQuery(Constants.FULLTEXT_INDEX, queryString.toString()); indexQuery = context.getGraph().indexQuery(Constants.FULLTEXT_INDEX, queryString.toString());
......
...@@ -48,12 +48,12 @@ public abstract class SearchProcessor { ...@@ -48,12 +48,12 @@ public abstract class SearchProcessor {
public static final String AND_STR = " AND "; public static final String AND_STR = " AND ";
public static final String EMPTY_STRING = ""; public static final String EMPTY_STRING = "";
public static final String SPACE_STRING = " "; public static final String SPACE_STRING = " ";
public static final String BRACE_OPEN_STR = "( "; public static final String BRACE_OPEN_STR = "(";
public static final String BRACE_CLOSE_STR = " )"; public static final String BRACE_CLOSE_STR = ")";
public static final char DOUBLE_QUOTE = '"'; public static final char DOUBLE_QUOTE = '"';
private static final Map<SearchParameters.Operator, String> OPERATOR_MAP = new HashMap<>(); private static final Map<SearchParameters.Operator, String> OPERATOR_MAP = new HashMap<>();
private static final char[] OFFENDING_CHARS = {'@', '/', ' '}; // This can grow as we discover corner cases private static final char[] OFFENDING_CHARS = { '@', '/', ' ' }; // This can grow as we discover corner cases
static static
{ {
...@@ -182,16 +182,13 @@ public abstract class SearchProcessor { ...@@ -182,16 +182,13 @@ public abstract class SearchProcessor {
} }
protected void constructTypeTestQuery(StringBuilder solrQuery, Set<String> typeAndAllSubTypes) { protected void constructTypeTestQuery(StringBuilder solrQuery, Set<String> typeAndAllSubTypes) {
String typeAndSubtypesString = StringUtils.join(typeAndAllSubTypes, SPACE_STRING);
if (CollectionUtils.isNotEmpty(typeAndAllSubTypes)) { if (CollectionUtils.isNotEmpty(typeAndAllSubTypes)) {
if (solrQuery.length() > 0) { if (solrQuery.length() > 0) {
solrQuery.append(AND_STR); solrQuery.append(AND_STR);
} }
solrQuery.append("v.\"").append(Constants.TYPE_NAME_PROPERTY_KEY).append("\": (") solrQuery.append("v.\"").append(Constants.TYPE_NAME_PROPERTY_KEY).append("\":");
.append(typeAndSubtypesString) appendIndexQueryValue(typeAndAllSubTypes, solrQuery);
.append(")");
} }
} }
...@@ -392,6 +389,16 @@ public abstract class SearchProcessor { ...@@ -392,6 +389,16 @@ public abstract class SearchProcessor {
return ret; return ret;
} }
protected String appendIndexQueryValue(Set<String> values, StringBuilder sb) {
sb.append(BRACE_OPEN_STR);
for (String value : values) {
sb.append(escapeIndexQueryValue(value)).append(SPACE_STRING);
}
sb.append(BRACE_CLOSE_STR);
return sb.toString();
}
private static int getApplicationProperty(String propertyName, int defaultValue) { private static int getApplicationProperty(String propertyName, int defaultValue) {
try { try {
return ApplicationProperties.get().getInt(propertyName, defaultValue); return ApplicationProperties.get().getInt(propertyName, defaultValue);
......
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