Search in sources :

Example 1 with ElasticSearchClassInfo

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;
}
Also used : ElasticSearchClassInfo(org.meveo.service.index.ElasticSearchClassInfo) BusinessEntity(org.meveo.model.BusinessEntity)

Example 2 with ElasticSearchClassInfo

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;
}
Also used : DocumentField(org.elasticsearch.common.document.DocumentField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ElasticSearchClassInfo(org.meveo.service.index.ElasticSearchClassInfo) CustomModelObject(org.meveo.model.customEntities.CustomModelObject) Map(java.util.Map) HashMap(java.util.HashMap) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

ElasticSearchClassInfo (org.meveo.service.index.ElasticSearchClassInfo)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 DocumentField (org.elasticsearch.common.document.DocumentField)1 BusinessEntity (org.meveo.model.BusinessEntity)1 CustomModelObject (org.meveo.model.customEntities.CustomModelObject)1