mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-11 00:42:29 +00:00
Merge pull request #1344 from camelliazhang/master
more refactoring so that the methods can be override internally
This commit is contained in:
commit
3d8a090962
@ -21,6 +21,7 @@ import wherehows.dao.table.DictDatasetDao;
|
|||||||
import wherehows.dao.table.FieldDetailDao;
|
import wherehows.dao.table.FieldDetailDao;
|
||||||
import wherehows.dao.table.AclDao;
|
import wherehows.dao.table.AclDao;
|
||||||
import wherehows.dao.table.LineageDao;
|
import wherehows.dao.table.LineageDao;
|
||||||
|
import wherehows.dao.table.SearchDao;
|
||||||
import wherehows.dao.view.DataTypesViewDao;
|
import wherehows.dao.view.DataTypesViewDao;
|
||||||
import wherehows.dao.view.DatasetViewDao;
|
import wherehows.dao.view.DatasetViewDao;
|
||||||
import wherehows.dao.view.OwnerViewDao;
|
import wherehows.dao.view.OwnerViewDao;
|
||||||
@ -50,6 +51,8 @@ public class DaoFactory {
|
|||||||
|
|
||||||
private static AclDao aclDao;
|
private static AclDao aclDao;
|
||||||
|
|
||||||
|
private static SearchDao searchDao;
|
||||||
|
|
||||||
public DaoFactory(EntityManagerFactory entityManagerFactory) {
|
public DaoFactory(EntityManagerFactory entityManagerFactory) {
|
||||||
this.entityManagerFactory = entityManagerFactory;
|
this.entityManagerFactory = entityManagerFactory;
|
||||||
}
|
}
|
||||||
@ -123,4 +126,11 @@ public class DaoFactory {
|
|||||||
}
|
}
|
||||||
return aclDao;
|
return aclDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SearchDao getSearchDao() {
|
||||||
|
if (searchDao == null) {
|
||||||
|
searchDao = new SearchDao();
|
||||||
|
}
|
||||||
|
return searchDao;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,26 +31,26 @@ import wherehows.models.table.Dataset;
|
|||||||
|
|
||||||
import static wherehows.util.Search.*;
|
import static wherehows.util.Search.*;
|
||||||
|
|
||||||
public class SearchDAO
|
public class SearchDao
|
||||||
{
|
{
|
||||||
public static String ELASTICSEARCH_DATASET_URL_KEY = "elasticsearch.dataset.url";
|
public static String ELASTICSEARCH_DATASET_URL_KEY = "elasticsearch.dataset.url";
|
||||||
public static String WHEREHOWS_SEARCH_ENGINE_KEY = "search.engine";
|
public static String WHEREHOWS_SEARCH_ENGINE_KEY = "search.engine";
|
||||||
|
|
||||||
public static List<String> getAutoCompleteList(String input, int limit)
|
public List<String> getAutoCompleteList(String input, int limit)
|
||||||
{
|
{
|
||||||
List<String> names = new ArrayList<>();
|
List<String> names = new ArrayList<>();
|
||||||
names.addAll(getAutoCompleteListDataset(input, limit / 3));
|
names.addAll(getAutoCompleteListDataset(input, limit / 3));
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getAutoCompleteListDataset(String input, int limit)
|
public List<String> getAutoCompleteListDataset(String input, int limit)
|
||||||
{
|
{
|
||||||
String elasticSearchTypeURLKey = "elasticsearch.dataset.url";
|
String elasticSearchTypeURLKey = "elasticsearch.dataset.url";
|
||||||
String fieldName = "name_suggest";
|
String fieldName = "name_suggest";
|
||||||
return getAutoCompleteListbyES(elasticSearchTypeURLKey,fieldName,input,limit);
|
return getAutoCompleteListbyES(elasticSearchTypeURLKey,fieldName,input,limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getAutoCompleteListbyES(String elasticSearchTypeURLKey, String fieldName, String input,
|
public List<String> getAutoCompleteListbyES(String elasticSearchTypeURLKey, String fieldName, String input,
|
||||||
int limit)
|
int limit)
|
||||||
{
|
{
|
||||||
// use elastic search completion suggester, ES will validate the input and limit
|
// use elastic search completion suggester, ES will validate the input and limit
|
||||||
@ -211,7 +211,7 @@ public class SearchDAO
|
|||||||
return SuggestionList;
|
return SuggestionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonNode elasticSearchDatasetByKeyword(
|
public JsonNode elasticSearchDatasetByKeyword(
|
||||||
String category,
|
String category,
|
||||||
String keywords,
|
String keywords,
|
||||||
String source,
|
String source,
|
||||||
@ -262,7 +262,7 @@ public class SearchDAO
|
|||||||
" === elasticSearchDatasetByKeyword === The query sent to Elastic Search is: " + queryNode.toString());
|
" === elasticSearchDatasetByKeyword === The query sent to Elastic Search is: " + queryNode.toString());
|
||||||
|
|
||||||
Promise<WSResponse> responsePromise =
|
Promise<WSResponse> responsePromise =
|
||||||
WS.url(Play.application().configuration().getString(SearchDAO.ELASTICSEARCH_DATASET_URL_KEY)).post(queryNode);
|
WS.url(Play.application().configuration().getString(SearchDao.ELASTICSEARCH_DATASET_URL_KEY)).post(queryNode);
|
||||||
responseNode = responsePromise.get(1000).asJson();
|
responseNode = responsePromise.get(1000).asJson();
|
||||||
|
|
||||||
// Logger.debug("The responseNode from Elastic Search is: " + responseNode.toString());
|
// Logger.debug("The responseNode from Elastic Search is: " + responseNode.toString());
|
||||||
@ -14,6 +14,7 @@
|
|||||||
package controllers.api.v1;
|
package controllers.api.v1;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import controllers.Application;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.commons.lang3.math.NumberUtils;
|
import org.apache.commons.lang3.math.NumberUtils;
|
||||||
import play.Logger;
|
import play.Logger;
|
||||||
@ -25,7 +26,7 @@ import play.mvc.Result;
|
|||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.*;
|
import static org.apache.commons.lang3.StringUtils.*;
|
||||||
|
|
||||||
import wherehows.dao.table.SearchDAO;
|
import wherehows.dao.table.SearchDao;
|
||||||
|
|
||||||
|
|
||||||
public class Search extends Controller {
|
public class Search extends Controller {
|
||||||
@ -34,6 +35,8 @@ public class Search extends Controller {
|
|||||||
private static final int DEFAULT_AUTOCOMPLETE_SIZE = 20;
|
private static final int DEFAULT_AUTOCOMPLETE_SIZE = 20;
|
||||||
private static final int DEFAULT_AUTOCOMPLETE_CACHE_TIME = 3600; // cache for an hour
|
private static final int DEFAULT_AUTOCOMPLETE_CACHE_TIME = 3600; // cache for an hour
|
||||||
|
|
||||||
|
private static final SearchDao SEARCH_DAO = Application.DAO_FACTORY.getSearchDao();
|
||||||
|
|
||||||
public static Result getSearchAutoComplete() {
|
public static Result getSearchAutoComplete() {
|
||||||
// if not input, then get all search names (without limit).
|
// if not input, then get all search names (without limit).
|
||||||
String input = request().getQueryString("input");
|
String input = request().getQueryString("input");
|
||||||
@ -45,7 +48,7 @@ public class Search extends Controller {
|
|||||||
String cacheKey = AUTOCOMPLETE_ALL_KEY + (isNotBlank(input) ? "." + input : "-all");
|
String cacheKey = AUTOCOMPLETE_ALL_KEY + (isNotBlank(input) ? "." + input : "-all");
|
||||||
List<String> names = (List<String>) Cache.get(cacheKey);
|
List<String> names = (List<String>) Cache.get(cacheKey);
|
||||||
if (names == null || names.size() == 0) {
|
if (names == null || names.size() == 0) {
|
||||||
names = SearchDAO.getAutoCompleteList(input, size);
|
names = SEARCH_DAO.getAutoCompleteList(input, size);
|
||||||
Cache.set(cacheKey, names, DEFAULT_AUTOCOMPLETE_CACHE_TIME);
|
Cache.set(cacheKey, names, DEFAULT_AUTOCOMPLETE_CACHE_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +70,7 @@ public class Search extends Controller {
|
|||||||
String cacheKey = AUTOCOMPLETE_DATASET_KEY + (isNotBlank(input) ? "." + input : "-all");
|
String cacheKey = AUTOCOMPLETE_DATASET_KEY + (isNotBlank(input) ? "." + input : "-all");
|
||||||
List<String> names = (List<String>) Cache.get(cacheKey);
|
List<String> names = (List<String>) Cache.get(cacheKey);
|
||||||
if (names == null || names.size() == 0) {
|
if (names == null || names.size() == 0) {
|
||||||
names = SearchDAO.getAutoCompleteListDataset(input, size);
|
names = SEARCH_DAO.getAutoCompleteListDataset(input, size);
|
||||||
Cache.set(cacheKey, names, DEFAULT_AUTOCOMPLETE_CACHE_TIME);
|
Cache.set(cacheKey, names, DEFAULT_AUTOCOMPLETE_CACHE_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,10 +124,10 @@ public class Search extends Controller {
|
|||||||
source = null;
|
source = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String searchEngine = Play.application().configuration().getString(SearchDAO.WHEREHOWS_SEARCH_ENGINE_KEY);
|
String searchEngine = Play.application().configuration().getString(SearchDao.WHEREHOWS_SEARCH_ENGINE_KEY);
|
||||||
Logger.info("searchEngine is: " + searchEngine); // TODO: deprecated this setting
|
Logger.info("searchEngine is: " + searchEngine); // TODO: deprecated this setting
|
||||||
|
|
||||||
result.set("result", SearchDAO.elasticSearchDatasetByKeyword(category, keyword, source, page, size));
|
result.set("result", SEARCH_DAO.elasticSearchDatasetByKeyword(category, keyword, source, page, size));
|
||||||
|
|
||||||
return ok(result);
|
return ok(result);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user