use of org.meveo.service.index.ElasticSearchClassInfo in project meveo by meveo-org.
the class FullTextSearchBean method getViewAndId.
/**
* Get navigation link and identifier
*
* @param indexName Index name
* @param type Class simple name or CET code
* @param id Identifier
* @return Navigation link/view name to entity's view screen
*/
@SuppressWarnings("unchecked")
public String getViewAndId(String indexName, String type, Long id) {
String viewName = null;
if (StringUtils.isBlank(type)) {
type = null;
}
ElasticSearchClassInfo scopeInfo = elasticClient.getSearchScopeInfo(indexName, type);
if (scopeInfo != null) {
BusinessEntity entity = null;
if (BusinessEntity.class.isAssignableFrom(scopeInfo.getClazz())) {
businessEntityService.setEntityClass((Class<BusinessEntity>) scopeInfo.getClazz());
entity = businessEntityService.findById(id);
}
if (entity != null) {
viewName = BaseBean.getEditViewName(entity.getClass());
if (getCurrentUser().hasRole("marketingCatalogManager") || getCurrentUser().hasRole("marketingCatalogVisualization")) {
viewName = "mm_" + viewName;
}
}
}
if (viewName == null) {
log.warn("Could not resolve view and ID for {}/{} {}", indexName, type, id);
viewName = "fullTextSearch";
}
return viewName;
}
use of org.meveo.service.index.ElasticSearchClassInfo in project meveo by meveo-org.
the class CustomTableService method search.
/**
* Execute a search on given fields for given query values. See ElasticClient.search() for a query format.
*
* @param cetCodeOrTablename Custom entity template code, or custom table name to query
* @param queryValues Fields and values to match
* @param from Pagination - starting record. Defaults to 0.
* @param size Pagination - number of records per page. Defaults to ElasticClient.DEFAULT_SEARCH_PAGE_SIZE.
* @param sortFields - Fields to sort by. If omitted, will sort by score. If search query contains a 'closestMatch' expression, sortFields and sortOrder will be overwritten
* with a corresponding field and descending order.
* @param sortOrders Sorting orders
* @param returnFields Return only certain fields - see Elastic Search documentation for details
* @return Search result
* @throws BusinessException General business exception
*/
public List<Map<String, Object>> search(String cetCodeOrTablename, Map<String, Object> queryValues, Integer from, Integer size, String[] sortFields, SortOrder[] sortOrders, String[] returnFields) throws BusinessException {
ElasticSearchClassInfo classInfo = new ElasticSearchClassInfo(CustomTableRecord.class, cetCodeOrTablename);
SearchResponse searchResult = elasticClient.search(queryValues, from, size, sortFields, sortOrders, returnFields, Collections.singletonList(classInfo));
if (searchResult == null) {
return new ArrayList<>();
}
List<Map<String, Object>> responseValues = new ArrayList<>();
searchResult.getHits().forEach(hit -> {
Map<String, Object> values = new HashMap<>();
responseValues.add(values);
if (hit.getFields() != null && !hit.getFields().values().isEmpty()) {
for (DocumentField field : hit.getFields().values()) {
if (field.getValues() != null) {
if (field.getValues().size() > 1) {
values.put(field.getName(), field.getValues());
} else {
values.put(field.getName(), field.getValue());
}
}
}
} else if (hit.getSourceAsMap() != null) {
values.putAll(hit.getSourceAsMap());
}
});
// log.debug("AKK ES search result values are {}", responseValues);
return responseValues;
}
Aggregations