Example usage for com.liferay.portal.kernel.search SearchContext getEntryClassNames

List of usage examples for com.liferay.portal.kernel.search SearchContext getEntryClassNames

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.search SearchContext getEntryClassNames.

Prototype

public String[] getEntryClassNames() 

Source Link

Usage

From source file:com.rivetlogic.portal.search.elasticsearch.util.ElasticsearchHelper.java

License:Open Source License

/**
 * Gets the documents.//from   w  w w  . j  a  va 2  s.co m
 *
 * @param searchHits the search hits
 * @param searchContext the search context
 * @return the documents
 */
private Document[] getDocuments(SearchHits searchHits, SearchContext searchContext) {
    if (_log.isInfoEnabled()) {
        _log.info("Getting document objects from SearchHits");
    }

    String[] types = searchContext.getEntryClassNames();
    int total = Integer.parseInt((searchHits != null) ? String.valueOf(searchHits.getTotalHits()) : "0");
    int failedJsonCount = 0;
    String className = null;
    if (total > 0) {
        List<Document> documentsList = new ArrayList<Document>(total);
        @SuppressWarnings("rawtypes")
        Iterator itr = searchHits.iterator();
        while (itr.hasNext()) {
            Document document = new DocumentImpl();
            SearchHit hit = (SearchHit) itr.next();

            JSONObject json;
            try {
                json = JSONFactoryUtil.createJSONObject(hit.getSourceAsString());
                @SuppressWarnings("rawtypes")
                Iterator jsonItr = json.keys();
                while (jsonItr.hasNext()) {
                    String key = (String) jsonItr.next();
                    String value = (String) json.getString(key);
                    if (_log.isDebugEnabled()) {
                        _log.debug(">>>>>>>>>> " + key + " : " + value);
                    }
                    document.add(new Field(key, value));
                    if (key.equalsIgnoreCase("entryClassName")) {
                        className = value;
                    }
                }
                if (ArrayUtil.contains(types, className)) {
                    documentsList.add(document);
                }
            } catch (JSONException e) {
                failedJsonCount++;
                _log.error("Error while processing the search result json objects", e);
            }
        }
        if (_log.isInfoEnabled()) {
            _log.info("Total size of the search results: " + documentsList.size());
        }
        return documentsList.toArray(new Document[documentsList.size() - failedJsonCount]);
    } else {
        if (_log.isInfoEnabled()) {
            _log.info("No search results found");
        }
        return new Document[0];
    }
}

From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexSearcher.java

License:Open Source License

private Query getPermissionQuery(SearchContext searchContext, Query query) {
    if (searchContext.getEntryClassNames() == null) {
        return query;
    }/*from   w w  w  .ja  v  a  2s . c  o m*/
    for (String className : searchContext.getEntryClassNames()) {
        Indexer indexer = IndexerRegistryUtil.getIndexer(className);
        if (indexer != null) {
            if (indexer.isFilterSearch() && indexer.isPermissionAware()) {
                SearchPermissionChecker searchPermissionChecker = SearchEngineUtil.getSearchPermissionChecker();
                query = searchPermissionChecker.getPermissionQuery(searchContext.getCompanyId(),
                        searchContext.getGroupIds(), searchContext.getUserId(), className, query,
                        searchContext);
            }
        }
    }
    return query;
}

From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexSearcher.java

License:Open Source License

private boolean isFilterSearch(SearchContext searchContext) {
    if (searchContext.getEntryClassNames() == null) {
        return false;
    }// www  .  jav a 2  s  . co m

    for (String entryClassName : searchContext.getEntryClassNames()) {
        Indexer indexer = IndexerRegistryUtil.getIndexer(entryClassName);

        if (indexer == null) {
            continue;
        }

        if (indexer.isFilterSearch()) {
            return true;
        }
    }

    return false;
}