Commit 8a0c08f7 by Shwetha GS

rest API for fulll text search

parent 84a28168
......@@ -73,7 +73,8 @@ public class MetadataServiceClient {
//Search operations
SEARCH("api/metadata/discovery/search", HttpMethod.GET),
SEARCH_DSL("api/metadata/discovery/search/dsl", HttpMethod.GET),
SEARCH_GREMLIN("api/metadata/discovery/search/gremlin", HttpMethod.GET);
SEARCH_GREMLIN("api/metadata/discovery/search/gremlin", HttpMethod.GET),
SEARCH_FULL_TEXT("api/metadata/discovery/search/fulltext", HttpMethod.GET);
private final String method;
private final String path;
......@@ -157,6 +158,8 @@ public class MetadataServiceClient {
"g.V.has(\"typeName\",\"%s\").and(_().has(\"%s.%s\", T.eq, \"%s\")).toList()",
typeName, typeName, attributeName, attributeValue);
return searchByGremlin(gremlinQuery);
// String dslQuery = String.format("%s where %s = \"%s\"", typeName, attributeName, attributeValue);
// return searchByDSL(dslQuery);
}
/**
......@@ -183,6 +186,18 @@ public class MetadataServiceClient {
return callAPIWithResource(API.SEARCH_GREMLIN, resource);
}
/**
* Search given full text search
* @param query Query
* @return result json object
* @throws MetadataServiceException
*/
public JSONObject searchByFullText(String query) throws MetadataServiceException {
WebResource resource = getResource(API.SEARCH_FULL_TEXT);
resource = resource.queryParam("query", query);
return callAPIWithResource(API.SEARCH_FULL_TEXT, resource);
}
public String getRequestId(JSONObject json) throws MetadataServiceException {
try {
return json.getString(REQUEST_ID);
......
......@@ -92,16 +92,24 @@ public class MetadataDiscoveryResource {
} catch (Throwable throwable) {
LOG.error("Unable to get entity list for query {} using dsl", query, throwable);
// todo: fall back to full text search
response.put("queryType", "full-text");
response.put(MetadataServiceClient.RESULTS, new JSONObject());
try { //fall back to full-text
final String jsonResult = discoveryService.searchByFullText(query);
response.put("queryType", "full-text");
response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult));
} catch (DiscoveryException e) {
LOG.error("Unable to get entity list for query {}", query, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) {
LOG.error("Unable to get entity list for query {}", query, e);
throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
return Response.ok(response).build();
} catch (JSONException e) {
LOG.error("Unable to get entity list for query {}", query, e);
throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
......@@ -177,4 +185,36 @@ public class MetadataDiscoveryResource {
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
}
/**
* Search using full text search.
*
* @param query search query.
* @return JSON representing the type and results.
*/
@GET
@Path("search/fulltext")
@Produces(MediaType.APPLICATION_JSON)
public Response searchUsingFullText(@QueryParam("query") String query) {
Preconditions.checkNotNull(query, "query cannot be null");
try {
final String jsonResult = discoveryService.searchByFullText(query);
JSONObject response = new JSONObject();
response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put("query", query);
response.put("queryType", "full-text");
response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult));
return Response.ok(response).build();
} catch (DiscoveryException e) {
LOG.error("Unable to get entity list for query {}", query, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) {
LOG.error("Unable to get entity list for query {}", query, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
}
\ No newline at end of file
......@@ -147,6 +147,16 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
Assert.assertEquals(response.getString("queryType"), "dsl");
}
@Test(enabled = false)
public void testSearchUsingFullText() throws Exception {
String query = "foo bar";
JSONObject response = serviceClient.searchByFullText(query);
Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
Assert.assertEquals(response.getString("query"), query);
Assert.assertEquals(response.getString("queryType"), "full-text");
}
private void createTypes() throws Exception {
HierarchicalTypeDefinition<ClassType> dslTestTypeDefinition =
TypesUtil.createClassTypeDef("dsl_test_type",
......
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