Search in sources :

Example 1 with AtlasFullTextResult

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

the class QuickStartV2 method search.

private void search() throws Exception {
    System.out.println("\nSample DSL Queries: ");
    for (String dslQuery : getDSLQueries()) {
        try {
            AtlasSearchResult results = atlasClientV2.dslSearchWithParams(dslQuery, 10, 0);
            if (results != null) {
                List<AtlasEntityHeader> entitiesResult = results.getEntities();
                List<AtlasFullTextResult> fullTextResults = results.getFullTextResult();
                AttributeSearchResult attribResult = results.getAttributes();
                if (CollectionUtils.isNotEmpty(entitiesResult)) {
                    System.out.println("query [" + dslQuery + "] returned [" + entitiesResult.size() + "] rows.");
                } else if (CollectionUtils.isNotEmpty(fullTextResults)) {
                    System.out.println("query [" + dslQuery + "] returned [" + fullTextResults.size() + "] rows.");
                } else if (attribResult != null) {
                    System.out.println("query [" + dslQuery + "] returned [" + attribResult.getValues().size() + "] rows.");
                }
            } else {
                System.out.println("query [" + dslQuery + "] failed, results:" + results);
            }
        } catch (Exception e) {
            System.out.println("query [" + dslQuery + "] execution failed!");
        }
    }
}
Also used : AttributeSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasFullTextResult(org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasException(org.apache.atlas.AtlasException) AtlasSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult)

Example 2 with AtlasFullTextResult

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

the class EntityDiscoveryJerseyResourceIT method testSearchUsingFullText.

@Test(enabled = false, 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 3 with AtlasFullTextResult

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

the class QuickStartV2 method search.

private void search() throws Exception {
    System.out.println("\nSample DSL Queries: ");
    for (String dslQuery : getDSLQueries()) {
        AtlasSearchResult results = atlasClientV2.dslSearchWithParams(dslQuery, 10, 0);
        if (results != null) {
            List<AtlasEntityHeader> entitiesResult = results.getEntities();
            List<AtlasFullTextResult> fullTextResults = results.getFullTextResult();
            AttributeSearchResult attribResult = results.getAttributes();
            if (CollectionUtils.isNotEmpty(entitiesResult)) {
                System.out.println("query [" + dslQuery + "] returned [" + entitiesResult.size() + "] rows.");
            } else if (CollectionUtils.isNotEmpty(fullTextResults)) {
                System.out.println("query [" + dslQuery + "] returned [" + fullTextResults.size() + "] rows.");
            } else if (attribResult != null) {
                System.out.println("query [" + dslQuery + "] returned [" + attribResult.getValues().size() + "] rows.");
            }
        } else {
            System.out.println("query [" + dslQuery + "] failed, results:" + results);
        }
    }
}
Also used : AttributeSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasFullTextResult(org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult) AtlasSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult)

Example 4 with AtlasFullTextResult

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

the class EntityDiscoveryService method getIndexQueryResults.

private List<AtlasFullTextResult> getIndexQueryResults(AtlasIndexQuery query, QueryParams params, boolean excludeDeletedEntities) throws AtlasBaseException {
    List<AtlasFullTextResult> ret = new ArrayList<>();
    Iterator<Result> iter = query.vertices();
    while (iter.hasNext() && ret.size() < params.limit()) {
        Result idxQueryResult = iter.next();
        AtlasVertex vertex = idxQueryResult.getVertex();
        if (skipDeletedEntities(excludeDeletedEntities, vertex)) {
            continue;
        }
        String guid = vertex != null ? vertex.getProperty(Constants.GUID_PROPERTY_KEY, String.class) : null;
        if (guid != null) {
            AtlasEntityHeader entity = entityRetriever.toAtlasEntityHeader(vertex);
            Double score = idxQueryResult.getScore();
            ret.add(new AtlasFullTextResult(entity, score));
        }
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasFullTextResult(org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasFullTextResult(org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult) AtlasSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult) Result(org.apache.atlas.repository.graphdb.AtlasIndexQuery.Result) AttributeSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult)

Example 5 with AtlasFullTextResult

use of org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult 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)

Aggregations

AtlasSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult)6 AtlasFullTextResult (org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult)6 AttributeSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult)4 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)4 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)2 Result (org.apache.atlas.repository.graphdb.AtlasIndexQuery.Result)2 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)2 Test (org.testng.annotations.Test)2 AtlasException (org.apache.atlas.AtlasException)1 AtlasServiceException (org.apache.atlas.AtlasServiceException)1