Commit 670a4c00 by Sarath Subramanian Committed by Madhan Neethiraj

ATLAS-1630: basic search implementation (#2)

parent 2bbbd1a5
...@@ -52,6 +52,10 @@ public class AtlasSearchResult implements Serializable { ...@@ -52,6 +52,10 @@ public class AtlasSearchResult implements Serializable {
public AtlasSearchResult() {} public AtlasSearchResult() {}
public AtlasSearchResult(AtlasQueryType queryType) {
this(null, queryType);
}
public AtlasSearchResult(String queryText, AtlasQueryType queryType) { public AtlasSearchResult(String queryText, AtlasQueryType queryType) {
setQueryText(queryText); setQueryText(queryText);
setQueryType(queryType); setQueryType(queryType);
......
...@@ -158,7 +158,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService { ...@@ -158,7 +158,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
@Override @Override
public AtlasSearchResult searchUsingBasicQuery(String query, String typeName, String classification, int limit, int offset) throws AtlasBaseException { public AtlasSearchResult searchUsingBasicQuery(String query, String typeName, String classification, int limit, int offset) throws AtlasBaseException {
AtlasSearchResult ret = new AtlasSearchResult(query, AtlasQueryType.BASIC); AtlasSearchResult ret = new AtlasSearchResult(AtlasQueryType.BASIC);
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Executing basic search query: {} with type: {} and classification: {}", query, typeName, classification); LOG.debug("Executing basic search query: {} with type: {} and classification: {}", query, typeName, classification);
...@@ -197,7 +197,12 @@ public class EntityDiscoveryService implements AtlasDiscoveryService { ...@@ -197,7 +197,12 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
ret.setClassification(classification); ret.setClassification(classification);
} }
if (StringUtils.isNotEmpty(query)) {
basicQuery += String.format(gremlinQueryProvider.getQuery(AtlasGremlinQuery.BASIC_SEARCH_QUERY_FILTER), query); basicQuery += String.format(gremlinQueryProvider.getQuery(AtlasGremlinQuery.BASIC_SEARCH_QUERY_FILTER), query);
ret.setQueryText(query);
}
basicQuery += String.format(gremlinQueryProvider.getQuery(AtlasGremlinQuery.TO_RANGE_LIST), params.offset(), params.limit()); basicQuery += String.format(gremlinQueryProvider.getQuery(AtlasGremlinQuery.TO_RANGE_LIST), params.offset(), params.limit());
try { try {
......
...@@ -21,6 +21,7 @@ import org.apache.atlas.exception.AtlasBaseException; ...@@ -21,6 +21,7 @@ import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.discovery.AtlasDiscoveryService; import org.apache.atlas.discovery.AtlasDiscoveryService;
import org.apache.atlas.model.discovery.AtlasSearchResult; import org.apache.atlas.model.discovery.AtlasSearchResult;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.apache.commons.lang3.StringUtils;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
...@@ -46,6 +47,8 @@ public class DiscoveryREST { ...@@ -46,6 +47,8 @@ public class DiscoveryREST {
/** /**
* Retrieve data for the specified DSL * Retrieve data for the specified DSL
* @param query DSL query * @param query DSL query
* @param type limit the result to only entities of specified type or its sub-types
* @param classification limit the result to only entities tagged with the given classification or or its sub-types
* @param limit limit the result set to only include the specified number of entries * @param limit limit the result set to only include the specified number of entries
* @param offset start offset of the result set (useful for pagination) * @param offset start offset of the result set (useful for pagination)
* @return Search results * @return Search results
...@@ -59,10 +62,24 @@ public class DiscoveryREST { ...@@ -59,10 +62,24 @@ public class DiscoveryREST {
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasSearchResult searchUsingDSL(@QueryParam("query") String query, public AtlasSearchResult searchUsingDSL(@QueryParam("query") String query,
@QueryParam("type") String type,
@QueryParam("classification") String classification,
@QueryParam("limit") int limit, @QueryParam("limit") int limit,
@QueryParam("offset") int offset) throws AtlasBaseException { @QueryParam("offset") int offset) throws AtlasBaseException {
String queryStr = query == null ? "" : query;
if (StringUtils.isNoneEmpty(type)) {
queryStr = type + " " + queryStr;
}
if (StringUtils.isNoneEmpty(classification)) {
// isa works with a type name only - like hive_column isa PII; it doesn't work with more complex query
if (StringUtils.isEmpty(query)) {
queryStr += (" isa " + classification);
}
}
AtlasSearchResult ret = atlasDiscoveryService.searchUsingDslQuery(query, limit, offset); AtlasSearchResult ret = atlasDiscoveryService.searchUsingDslQuery(queryStr, limit, offset);
return ret; return ret;
} }
......
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