Commit 4bc3e738 by Shwetha GS

ATLAS-1006 Paginate full text search results (shwethags)

parent 9ab13a31
......@@ -1101,7 +1101,6 @@ public class AtlasClient {
* @param query Query
* @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value
* @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0
* NOTE: Pagination is not implemented currently for full text search, so limit and offset are not used
* @return result json object
* @throws AtlasServiceException
*/
......
......@@ -6,6 +6,7 @@ INCOMPATIBLE CHANGES:
ALL CHANGES:
ATLAS-1006 Paginate full text search results (shwethags)
ATLAS-1046 UI: Search pagination refinements (Kalyanikashikar via sumasai)
ATLAS-1056 Differentiate between tag and term using attribute "taxonomy.namespace" (kevalbhat18 via sumasai)
ATLAS-1059 Change log level to debug for search APIs(sumasai)
......
......@@ -91,7 +91,13 @@ public class GraphBackedDiscoveryService implements DiscoveryService {
titanGraph.indexQuery(Constants.FULLTEXT_INDEX, graphQuery).vertices().iterator();
JSONArray response = new JSONArray();
while (results.hasNext()) {
int index = 0;
while (results.hasNext() && index < queryParams.offset()) {
results.next();
index++;
}
while (results.hasNext() && response.length() < queryParams.limit()) {
TitanIndexQuery.Result<Vertex> result = results.next();
Vertex vertex = result.getElement();
......
......@@ -546,6 +546,23 @@ public class GraphBackedMetadataRepositoryTest {
Assert.assertEquals(results.length(), 1);
row = (JSONObject) results.get(0);
Assert.assertEquals(row.get("typeName"), "Person");
//verify limit and offset
//higher limit should return all results
results = new JSONArray(discoveryService.searchByFullText("Department", queryParams));
assertEquals(results.length(), 5);
//smaller limit should return those many rows
results = new JSONArray(discoveryService.searchByFullText("Department", new QueryParams(2, 0)));
assertEquals(results.length(), 2);
//offset should offset the results
results = new JSONArray(discoveryService.searchByFullText("Department", new QueryParams(5, 2)));
assertEquals(results.length(), 3);
//higher offset shouldn't return any rows
results = new JSONArray(discoveryService.searchByFullText("Department", new QueryParams(2, 6)));
assertEquals(results.length(), 0);
}
private ITypedReferenceableInstance createHiveTableInstance(Referenceable databaseInstance) throws Exception {
......
......@@ -217,7 +217,6 @@ public class MetadataDiscoveryResource {
* @param query search query.
* @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value
* @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0
* NOTE: Pagination is not implemented currently for full text search, so limit and offset are not used
* @return JSON representing the type and results.
*/
@GET
......
......@@ -86,10 +86,10 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
JSONArray results = response.getJSONArray(AtlasClient.RESULTS);
Assert.assertNotNull(results);
assertEquals(results.length(), 1);
assertEquals(results.length(), 2);
int numRows = response.getInt(AtlasClient.COUNT);
assertEquals(numRows, 1);
assertEquals(numRows, 2);
}
@Test
......@@ -196,7 +196,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
assertEquals(response.getString("queryType"), "dsl");
}
@Test
@Test(dependsOnMethods = "testSearchDSLLimits")
public void testSearchUsingFullText() throws Exception {
JSONObject response = serviceClient.searchByFullText(tagName, 10, 0);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
......@@ -214,6 +214,32 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
int numRows = response.getInt(AtlasClient.COUNT);
assertEquals(numRows, 1);
//API works without limit and offset
String query = "dsl_test_type";
WebResource resource = service.path("api/atlas/discovery/search/fulltext").queryParam("query", query);
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
results = new JSONObject(clientResponse.getEntity(String.class)).getJSONArray(AtlasClient.RESULTS);
assertEquals(results.length(), 2);
//verify passed in limits and offsets are used
//higher limit and 0 offset returns all results
results = serviceClient.searchByFullText(query, 10, 0).getJSONArray(AtlasClient.RESULTS);
assertEquals(results.length(), 2);
//offset is used
results = serviceClient.searchByFullText(query, 10, 1).getJSONArray(AtlasClient.RESULTS);
assertEquals(results.length(), 1);
//limit is used
results = serviceClient.searchByFullText(query, 1, 0).getJSONArray(AtlasClient.RESULTS);
assertEquals(results.length(), 1);
//higher offset returns 0 results
results = serviceClient.searchByFullText(query, 1, 2).getJSONArray(AtlasClient.RESULTS);
assertEquals(results.length(), 0);
}
private void createTypes() throws Exception {
......
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