Search in sources :

Example 6 with AtlasSearchResult

use of org.apache.atlas.model.discovery.AtlasSearchResult in project incubator-atlas by apache.

the class EntityDiscoveryJerseyResourceIT method testSearchDSLLimits.

@Test
public void testSearchDSLLimits() throws Exception {
    String dslQuery = "from " + DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\"";
    AtlasSearchResult searchResult = atlasClientV2.dslSearch(dslQuery);
    assertNotNull(searchResult);
    //higher limit, all results returned
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, 0);
    assertEquals(searchResult.getEntities().size(), 1);
    //default limit and offset -1, all results returned
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, -1, -1);
    assertEquals(searchResult.getEntities().size(), 1);
    //uses the limit parameter passed
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 1, 0);
    assertEquals(searchResult.getEntities().size(), 1);
    //uses the offset parameter passed
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, 1);
    assertNull(searchResult.getEntities());
    //limit > 0
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 0, 10);
    assertNull(searchResult.getEntities());
    //limit > maxlimit
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, Integer.MAX_VALUE, 10);
    assertNull(searchResult.getEntities());
    //offset >= 0
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, -2);
    assertEquals(searchResult.getEntities().size(), 1);
}
Also used : AtlasSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult) Test(org.testng.annotations.Test)

Example 7 with AtlasSearchResult

use of org.apache.atlas.model.discovery.AtlasSearchResult in project incubator-atlas by apache.

the class EntityDiscoveryJerseyResourceIT method testSearchUsingFullText.

@Test(dependsOnMethods = "testSearchDSLLimits")
public void testSearchUsingFullText() throws Exception {
    AtlasSearchResult searchResult = atlasClientV2.fullTextSearchWithParams(dbName, 10, 0);
    assertNotNull(searchResult);
    assertEquals(searchResult.getQueryText(), dbName);
    assertEquals(searchResult.getQueryType(), AtlasQueryType.FULL_TEXT);
    List<AtlasFullTextResult> fullTextResults = searchResult.getFullTextResult();
    assertEquals(fullTextResults.size(), 1);
    AtlasFullTextResult result = fullTextResults.get(0);
    assertNotNull(result.getEntity());
    assertEquals(result.getEntity().getTypeName(), DATABASE_TYPE_BUILTIN);
    assertNotNull(result.getScore());
    //API works without limit and offset
    String query = dbName;
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add("query", query);
    searchResult = atlasClientV2.fullTextSearch(query);
    assertNotNull(searchResult);
    assertEquals(searchResult.getFullTextResult().size(), 1);
    //verify passed in limits and offsets are used
    //higher limit and 0 offset returns all results
    searchResult = atlasClientV2.fullTextSearchWithParams(query, 10, 0);
    assertEquals(searchResult.getFullTextResult().size(), 1);
    //offset is used
    searchResult = atlasClientV2.fullTextSearchWithParams(query, 10, 1);
    assertEquals(searchResult.getFullTextResult().size(), 1);
    //limit is used
    searchResult = atlasClientV2.fullTextSearchWithParams(query, 1, 0);
    assertEquals(searchResult.getFullTextResult().size(), 1);
    //higher offset returns 0 results
    searchResult = atlasClientV2.fullTextSearchWithParams(query, 1, 2);
    assertEquals(searchResult.getFullTextResult().size(), 1);
}
Also used : AtlasFullTextResult(org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) AtlasSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult) Test(org.testng.annotations.Test)

Example 8 with AtlasSearchResult

use of org.apache.atlas.model.discovery.AtlasSearchResult in project incubator-atlas by apache.

the class EntityDiscoveryJerseyResourceIT method testSearchUsingDSL.

@Test
public void testSearchUsingDSL() throws Exception {
    String query = "from " + DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\"";
    AtlasSearchResult searchResult = atlasClientV2.dslSearch(query);
    assertNotNull(searchResult);
    assertEquals(searchResult.getQueryText(), query);
    assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL);
    List<AtlasEntityHeader> entities = searchResult.getEntities();
    assertNotNull(entities);
    assertEquals(entities.size(), 1);
    AtlasEntityHeader dbEntity = entities.get(0);
    assertEquals(dbEntity.getTypeName(), DATABASE_TYPE_BUILTIN);
    assertEquals(dbEntity.getDisplayText(), dbName);
    assertEquals(dbEntity.getStatus(), Status.ACTIVE);
    assertNotNull(dbEntity.getGuid());
    assertNull(searchResult.getAttributes());
    assertNull(searchResult.getFullTextResult());
}
Also used : AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult) Test(org.testng.annotations.Test)

Example 9 with AtlasSearchResult

use of org.apache.atlas.model.discovery.AtlasSearchResult in project incubator-atlas by apache.

the class EntityDiscoveryJerseyResourceIT method testSearchFullTextOnDSLFailure.

@Test
public void testSearchFullTextOnDSLFailure() throws Exception {
    String query = "*";
    AtlasSearchResult searchResult = atlasClientV2.fullTextSearch(query);
    assertNotNull(searchResult);
    assertEquals(searchResult.getQueryText(), query);
    assertEquals(searchResult.getQueryType(), AtlasQueryType.FULL_TEXT);
}
Also used : AtlasSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult) Test(org.testng.annotations.Test)

Aggregations

AtlasSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult)9 Test (org.testng.annotations.Test)5 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)4 AtlasFullTextResult (org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 AttributeSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult)2 QueryParams (org.apache.atlas.query.QueryParams)2 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)2 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)1 Map (java.util.Map)1 ScriptEngine (javax.script.ScriptEngine)1 ScriptException (javax.script.ScriptException)1 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)1 GremlinQuery (org.apache.atlas.query.GremlinQuery)1 AtlasIndexQuery (org.apache.atlas.repository.graphdb.AtlasIndexQuery)1 Result (org.apache.atlas.repository.graphdb.AtlasIndexQuery.Result)1 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)1 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)1