Merge pull request #1344 from camelliazhang/master

more refactoring so that the methods can be override internally
This commit is contained in:
na zhang 2018-08-28 17:03:50 -07:00 committed by GitHub
commit 3d8a090962
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 11 deletions

View File

@ -21,6 +21,7 @@ import wherehows.dao.table.DictDatasetDao;
import wherehows.dao.table.FieldDetailDao;
import wherehows.dao.table.AclDao;
import wherehows.dao.table.LineageDao;
import wherehows.dao.table.SearchDao;
import wherehows.dao.view.DataTypesViewDao;
import wherehows.dao.view.DatasetViewDao;
import wherehows.dao.view.OwnerViewDao;
@ -50,6 +51,8 @@ public class DaoFactory {
private static AclDao aclDao;
private static SearchDao searchDao;
public DaoFactory(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}
@ -123,4 +126,11 @@ public class DaoFactory {
}
return aclDao;
}
public SearchDao getSearchDao() {
if (searchDao == null) {
searchDao = new SearchDao();
}
return searchDao;
}
}

View File

@ -31,26 +31,26 @@ import wherehows.models.table.Dataset;
import static wherehows.util.Search.*;
public class SearchDAO
public class SearchDao
{
public static String ELASTICSEARCH_DATASET_URL_KEY = "elasticsearch.dataset.url";
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<>();
names.addAll(getAutoCompleteListDataset(input, limit / 3));
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 fieldName = "name_suggest";
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)
{
// use elastic search completion suggester, ES will validate the input and limit
@ -211,7 +211,7 @@ public class SearchDAO
return SuggestionList;
}
public static JsonNode elasticSearchDatasetByKeyword(
public JsonNode elasticSearchDatasetByKeyword(
String category,
String keywords,
String source,
@ -262,7 +262,7 @@ public class SearchDAO
" === elasticSearchDatasetByKeyword === The query sent to Elastic Search is: " + queryNode.toString());
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();
// Logger.debug("The responseNode from Elastic Search is: " + responseNode.toString());

View File

@ -14,6 +14,7 @@
package controllers.api.v1;
import com.fasterxml.jackson.databind.node.ObjectNode;
import controllers.Application;
import java.util.List;
import org.apache.commons.lang3.math.NumberUtils;
import play.Logger;
@ -25,7 +26,7 @@ import play.mvc.Result;
import static org.apache.commons.lang3.StringUtils.*;
import wherehows.dao.table.SearchDAO;
import wherehows.dao.table.SearchDao;
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_CACHE_TIME = 3600; // cache for an hour
private static final SearchDao SEARCH_DAO = Application.DAO_FACTORY.getSearchDao();
public static Result getSearchAutoComplete() {
// if not input, then get all search names (without limit).
String input = request().getQueryString("input");
@ -45,7 +48,7 @@ public class Search extends Controller {
String cacheKey = AUTOCOMPLETE_ALL_KEY + (isNotBlank(input) ? "." + input : "-all");
List<String> names = (List<String>) Cache.get(cacheKey);
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);
}
@ -67,7 +70,7 @@ public class Search extends Controller {
String cacheKey = AUTOCOMPLETE_DATASET_KEY + (isNotBlank(input) ? "." + input : "-all");
List<String> names = (List<String>) Cache.get(cacheKey);
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);
}
@ -121,10 +124,10 @@ public class Search extends Controller {
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
result.set("result", SearchDAO.elasticSearchDatasetByKeyword(category, keyword, source, page, size));
result.set("result", SEARCH_DAO.elasticSearchDatasetByKeyword(category, keyword, source, page, size));
return ok(result);
}