Search in sources :

Example 1 with AtlasQuickSearchResult

use of org.apache.atlas.model.discovery.AtlasQuickSearchResult in project atlas by apache.

the class DiscoveryExample method quickSearch.

public void quickSearch(String searchString) {
    try {
        AtlasQuickSearchResult result = client.quickSearch(searchString, SampleAppConstants.TABLE_TYPE, false, 2, 0);
        List<AtlasEntityHeader> entities = result != null && result.getSearchResults() != null ? result.getSearchResults().getEntities() : null;
        int resultCount = entities == null ? 0 : entities.size();
        SampleApp.log("Quick search: query-string=" + searchString);
        SampleApp.log("  result count: " + resultCount);
        for (int i = 0; i < resultCount; i++) {
            SampleApp.log("  result # " + (i + 1) + ": " + entities.get(i));
        }
    } catch (AtlasServiceException e) {
        e.printStackTrace();
    }
}
Also used : AtlasQuickSearchResult(org.apache.atlas.model.discovery.AtlasQuickSearchResult) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader)

Example 2 with AtlasQuickSearchResult

use of org.apache.atlas.model.discovery.AtlasQuickSearchResult in project atlas by apache.

the class AtlasDiscoveryServiceTest method specialCharQuickSearchAssertQFName.

@Test(dataProvider = "specialCharSearchQFName")
public void specialCharQuickSearchAssertQFName(String attrName, SearchParameters.Operator operator, String attrValue, int expected) throws AtlasBaseException {
    QuickSearchParameters params = new QuickSearchParameters();
    params.setTypeName(HIVE_TABLE_TYPE);
    SearchParameters.FilterCriteria filterCriteria = getSingleFilterCondition(attrName, operator, attrValue);
    params.setEntityFilters(filterCriteria);
    params.setLimit(20);
    AtlasQuickSearchResult searchResult = discoveryService.quickSearch(params);
    assertSearchResult(searchResult.getSearchResults(), expected, attrValue);
    if (expected > 0) {
        assertAggregationMetrics(searchResult);
    }
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) QuickSearchParameters(org.apache.atlas.model.discovery.QuickSearchParameters) QuickSearchParameters(org.apache.atlas.model.discovery.QuickSearchParameters) AtlasQuickSearchResult(org.apache.atlas.model.discovery.AtlasQuickSearchResult)

Example 3 with AtlasQuickSearchResult

use of org.apache.atlas.model.discovery.AtlasQuickSearchResult in project atlas by apache.

the class AtlasDiscoveryServiceTest method specialCharQuickSearch.

@Test(dataProvider = "specialCharQuickSearch")
public void specialCharQuickSearch(String searchValue, int expected) throws AtlasBaseException {
    QuickSearchParameters params = new QuickSearchParameters();
    params.setQuery(searchValue);
    params.setLimit(5);
    params.setOffset(0);
    AtlasQuickSearchResult searchResult = discoveryService.quickSearch(params);
    assertSearchResult(searchResult.getSearchResults(), expected, searchValue);
    if (expected > 0) {
        assertAggregationMetrics(searchResult);
    }
}
Also used : QuickSearchParameters(org.apache.atlas.model.discovery.QuickSearchParameters) AtlasQuickSearchResult(org.apache.atlas.model.discovery.AtlasQuickSearchResult)

Example 4 with AtlasQuickSearchResult

use of org.apache.atlas.model.discovery.AtlasQuickSearchResult in project atlas by apache.

the class AtlasDiscoveryServiceTest method specialCharQuickSearchAssertName.

@Test(dataProvider = "specialCharSearchName")
public void specialCharQuickSearchAssertName(String attrName, SearchParameters.Operator operator, String attrValue, int expected) throws AtlasBaseException {
    QuickSearchParameters params = new QuickSearchParameters();
    params.setTypeName(HIVE_TABLE_TYPE);
    SearchParameters.FilterCriteria filterCriteria = getSingleFilterCondition(attrName, operator, attrValue);
    params.setEntityFilters(filterCriteria);
    params.setLimit(20);
    AtlasQuickSearchResult searchResult = discoveryService.quickSearch(params);
    assertSearchResult(searchResult.getSearchResults(), expected, attrValue);
    if (expected > 0) {
        assertAggregationMetrics(searchResult);
    }
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) QuickSearchParameters(org.apache.atlas.model.discovery.QuickSearchParameters) QuickSearchParameters(org.apache.atlas.model.discovery.QuickSearchParameters) AtlasQuickSearchResult(org.apache.atlas.model.discovery.AtlasQuickSearchResult)

Example 5 with AtlasQuickSearchResult

use of org.apache.atlas.model.discovery.AtlasQuickSearchResult in project atlas by apache.

the class EntityDiscoveryService method quickSearch.

@Override
@GraphTransaction
public AtlasQuickSearchResult quickSearch(QuickSearchParameters quickSearchParameters) throws AtlasBaseException {
    String query = quickSearchParameters.getQuery();
    if (StringUtils.isNotEmpty(query) && !AtlasStructType.AtlasAttribute.hastokenizeChar(query)) {
        query = query + "*";
    }
    quickSearchParameters.setQuery(query);
    SearchContext searchContext = new SearchContext(createSearchParameters(quickSearchParameters), typeRegistry, graph, indexer.getVertexIndexKeys());
    if (LOG.isDebugEnabled()) {
        LOG.debug("Generating the search results for the query {} .", searchContext.getSearchParameters().getQuery());
    }
    AtlasSearchResult searchResult = searchWithSearchContext(searchContext);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Generating the aggregated metrics for the query {} .", searchContext.getSearchParameters().getQuery());
    }
    // load the facet fields and attributes.
    Set<String> aggregationFields = getAggregationFields();
    Set<AtlasAttribute> aggregationAttributes = getAggregationAtlasAttributes();
    SearchAggregator searchAggregator = new SearchAggregatorImpl(searchContext);
    Map<String, List<AtlasAggregationEntry>> aggregatedMetrics = searchAggregator.getAggregatedMetrics(aggregationFields, aggregationAttributes);
    AtlasQuickSearchResult ret = new AtlasQuickSearchResult(searchResult, aggregatedMetrics);
    return ret;
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasQuickSearchResult(org.apache.atlas.model.discovery.AtlasQuickSearchResult) List(java.util.List) ArrayList(java.util.ArrayList) AtlasSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Aggregations

AtlasQuickSearchResult (org.apache.atlas.model.discovery.AtlasQuickSearchResult)10 QuickSearchParameters (org.apache.atlas.model.discovery.QuickSearchParameters)7 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)5 AtlasServiceException (org.apache.atlas.AtlasServiceException)3 SearchParameters (org.apache.atlas.model.discovery.SearchParameters)3 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)1 AtlasSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult)1 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)1