Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete PR #3948

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ jobs:
[{
"id": "github",
"username": "atlan-ci",
"password": "${{ secrets.my_pat }}"
"password": "${{ secrets.ORG_PAT_GITHUB }}"
}]

- name: Build with Maven
@@ -77,7 +77,7 @@ jobs:
shell: bash

- name: Get version tag
run: echo "##[set-output name=version;]$(echo `git ls-remote https://${{ secrets.my_pat }}@github.com/atlanhq/${REPOSITORY_NAME}.git ${{ steps.get_branch.outputs.branch }} | awk '{ print $1}' | cut -c1-7`)abcd"
run: echo "##[set-output name=version;]$(echo `git ls-remote https://${{ secrets.ORG_PAT_GITHUB }}@github.com/atlanhq/${REPOSITORY_NAME}.git ${{ steps.get_branch.outputs.branch }} | awk '{ print $1}' | cut -c1-7`)abcd"
id: get_version

- name: Set up Buildx
@@ -89,7 +89,7 @@ jobs:
with:
registry: ghcr.io
username: $GITHUB_ACTOR
password: ${{ secrets.my_pat }}
password: ${{ secrets.ORG_PAT_GITHUB }}

- name: Build and push
id: docker_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.apache.atlas.discovery;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.atlas.type.AtlasType;
import org.apache.http.util.EntityUtils;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class ESBasedSuggestionService {
private static final Logger LOG = LoggerFactory.getLogger(ESBasedSuggestionService.class);

private RestClient esRestClient;

public static final String INDEX_NAME = "suggest";

public ESBasedSuggestionService(RestClient lowLevelClient) {
this.esRestClient = lowLevelClient;
}

public SuggestionResponse searchSuggestions(String queryStr) throws IOException {
Request queryRequest = new Request("POST", "/autocomplete/_search");
queryRequest.setJsonEntity(queryStr);
Response response = esRestClient.performRequest(queryRequest);

SuggestionResponse suggestionResponse = new SuggestionResponse();
String esResponseString = EntityUtils.toString(response.getEntity());

// Parse the response and return the suggestions
Map<String, Object> responseMap = AtlasType.fromJson(esResponseString, Map.class);
suggestionResponse.setResponseMap(responseMap);

return suggestionResponse;
}

@JsonAutoDetect(getterVisibility=JsonAutoDetect.Visibility.PUBLIC_ONLY, setterVisibility=JsonAutoDetect.Visibility.PUBLIC_ONLY, fieldVisibility=JsonAutoDetect.Visibility.PUBLIC_ONLY)
@JsonSerialize(include=JsonSerialize.Inclusion.ALWAYS)
@JsonIgnoreProperties(ignoreUnknown=true)
public class SuggestionResponse {

public SuggestionResponse() { }
private Map<String, Object> responseMap = new LinkedHashMap<>();

public Map<String, Object> getResponseMap() {
return responseMap;
}

public void setResponseMap(Map<String, Object> responseMap) {
this.responseMap = responseMap;
}

}


}
15 changes: 11 additions & 4 deletions webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
import org.apache.atlas.annotation.Timed;
import org.apache.atlas.authorize.AtlasAuthorizationUtils;
import org.apache.atlas.discovery.AtlasDiscoveryService;
import org.apache.atlas.discovery.ESBasedSuggestionService;
import org.apache.atlas.discovery.EntityDiscoveryService;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.discovery.*;
@@ -34,9 +35,11 @@
import org.apache.atlas.model.searchlog.SearchLogSearchResult;
import org.apache.atlas.model.searchlog.SearchRequestLogData.SearchRequestLogDataBuilder;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.janus.AtlasElasticsearchDatabase;
import org.apache.atlas.searchlog.SearchLoggingManagement;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.utils.AtlasPerfMetrics;
import org.apache.atlas.utils.AtlasPerfTracer;
@@ -92,6 +95,8 @@ public class DiscoveryREST {
private final AtlasDiscoveryService discoveryService;
private final SearchLoggingManagement loggerManagement;

private final ESBasedSuggestionService esBasedSuggestionService = new ESBasedSuggestionService(AtlasElasticsearchDatabase.getLowLevelClient());

private static final String INDEXSEARCH_TAG_NAME = "indexsearch";
private static final Set<String> TRACKING_UTM_TAGS = new HashSet<>(Arrays.asList("ui_main_list", "ui_popup_searchbar"));
private static final String UTM_TAG_FROM_PRODUCT = "project_webapp";
@@ -827,17 +832,19 @@ public AtlasQuickSearchResult quickSearch(QuickSearchParameters quickSearchParam
}

@Path("suggestions")
@GET
@POST
@Timed
public AtlasSuggestionsResult getSuggestions(@QueryParam("prefixString") String prefixString, @QueryParam("fieldName") String fieldName) {
public ESBasedSuggestionService.SuggestionResponse getSuggestions(Object queryStr) {
AtlasPerfTracer perf = null;

try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.getSuggestions(" + prefixString + "," + fieldName + ")");
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.getSuggestions(" + queryStr + ")");
}

return discoveryService.getSuggestions(prefixString, fieldName);
return esBasedSuggestionService.searchSuggestions(AtlasType.toJson(queryStr));
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
AtlasPerfTracer.log(perf);
}