Search in sources :

Example 1 with SearchContext

use of com.liferay.portal.kernel.search.SearchContext in project liferay-ide by liferay.

the class AssetEntriesFacet method doGetFacetClause.

@Override
protected BooleanClause doGetFacetClause() {
    SearchContext searchContext = getSearchContext();
    String[] entryClassNames = searchContext.getEntryClassNames();
    BooleanQuery facetQuery = BooleanQueryFactoryUtil.create(searchContext);
    for (String entryClassName : entryClassNames) {
        Indexer indexer = IndexerRegistryUtil.getIndexer(entryClassName);
        if (indexer == null) {
            continue;
        }
        String searchEngineId = searchContext.getSearchEngineId();
        if (!searchEngineId.equals(indexer.getSearchEngineId())) {
            continue;
        }
        try {
            BooleanQuery indexerBooleanQuery = indexer.getFacetQuery(entryClassName, searchContext);
            if ((indexerBooleanQuery == null) || !indexerBooleanQuery.hasClauses()) {
                continue;
            }
            BooleanQuery entityQuery = BooleanQueryFactoryUtil.create(searchContext);
            entityQuery.add(indexerBooleanQuery, BooleanClauseOccur.MUST);
            indexer.postProcessContextQuery(entityQuery, searchContext);
            for (IndexerPostProcessor indexerPostProcessor : indexer.getIndexerPostProcessors()) {
                indexerPostProcessor.postProcessContextQuery(entityQuery, searchContext);
            }
            if (indexer.isStagingAware()) {
                if (!searchContext.isIncludeLiveGroups() && searchContext.isIncludeStagingGroups()) {
                    entityQuery.addRequiredTerm(Field.STAGING_GROUP, true);
                } else if (searchContext.isIncludeLiveGroups() && !searchContext.isIncludeStagingGroups()) {
                    entityQuery.addRequiredTerm(Field.STAGING_GROUP, false);
                }
            }
            if (entityQuery.hasClauses()) {
                facetQuery.add(entityQuery, BooleanClauseOccur.SHOULD);
            }
        } catch (Exception e) {
            _log.error(e, e);
        }
    }
    if (!facetQuery.hasClauses()) {
        return null;
    }
    return BooleanClauseFactoryUtil.create(searchContext, facetQuery, BooleanClauseOccur.MUST.getName());
}
Also used : BooleanQuery(com.liferay.portal.kernel.search.BooleanQuery) Indexer(com.liferay.portal.kernel.search.Indexer) SearchContext(com.liferay.portal.kernel.search.SearchContext) IndexerPostProcessor(com.liferay.portal.kernel.search.IndexerPostProcessor)

Example 2 with SearchContext

use of com.liferay.portal.kernel.search.SearchContext in project liferay-ide by liferay.

the class AssetEntriesFacet method initFacetClause.

protected void initFacetClause() {
    SearchContext searchContext = getSearchContext();
    FacetConfiguration facetConfiguration = getFacetConfiguration();
    JSONObject dataJSONObject = facetConfiguration.getData();
    String[] entryClassNames = null;
    if (dataJSONObject.has("values")) {
        JSONArray valuesJSONArray = dataJSONObject.getJSONArray("values");
        entryClassNames = new String[valuesJSONArray.length()];
        for (int i = 0; i < valuesJSONArray.length(); i++) {
            entryClassNames[i] = valuesJSONArray.getString(i);
        }
    }
    if (ArrayUtil.isEmpty(entryClassNames)) {
        entryClassNames = searchContext.getEntryClassNames();
    }
    if (!isStatic()) {
        String[] entryClassNameParam = StringUtil.split(GetterUtil.getString(searchContext.getAttribute(getFieldName())));
        if (ArrayUtil.isNotEmpty(entryClassNameParam)) {
            entryClassNames = entryClassNameParam;
        }
    }
    if (ArrayUtil.isEmpty(entryClassNames)) {
        entryClassNames = SearchEngineUtil.getEntryClassNames();
        if (!dataJSONObject.has("values")) {
            JSONArray entriesJSONArray = JSONFactoryUtil.createJSONArray();
            for (String entryClassName : entryClassNames) {
                entriesJSONArray.put(entryClassName);
            }
            dataJSONObject.put("values", entriesJSONArray);
        }
    }
    searchContext.setEntryClassNames(entryClassNames);
}
Also used : FacetConfiguration(com.liferay.portal.kernel.search.facet.config.FacetConfiguration) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray) SearchContext(com.liferay.portal.kernel.search.SearchContext)

Example 3 with SearchContext

use of com.liferay.portal.kernel.search.SearchContext in project liferay-ide by liferay.

the class UserLocalServiceImpl method search.

protected Hits search(long companyId, String firstName, String middleName, String lastName, String fullName, String screenName, String emailAddress, String street, String city, String zip, String region, String country, int status, LinkedHashMap<String, Object> params, boolean andSearch, int start, int end, Sort sort) throws SystemException {
    try {
        SearchContext searchContext = new SearchContext();
        searchContext.setAndSearch(andSearch);
        Map<String, Serializable> attributes = new HashMap<String, Serializable>();
        attributes.put("city", city);
        attributes.put("country", country);
        attributes.put("emailAddress", emailAddress);
        attributes.put("firstName", firstName);
        attributes.put("fullName", fullName);
        attributes.put("lastName", lastName);
        attributes.put("middleName", middleName);
        attributes.put("params", params);
        attributes.put("region", region);
        attributes.put("screenName", screenName);
        attributes.put("street", street);
        attributes.put("status", status);
        attributes.put("zip", zip);
        searchContext.setAttributes(attributes);
        searchContext.setCompanyId(companyId);
        searchContext.setEnd(end);
        if (params != null) {
            String keywords = (String) params.remove("keywords");
            if (Validator.isNotNull(keywords)) {
                searchContext.setKeywords(keywords);
            }
        }
        QueryConfig queryConfig = new QueryConfig();
        queryConfig.setHighlightEnabled(false);
        queryConfig.setScoreEnabled(false);
        searchContext.setQueryConfig(queryConfig);
        if (sort != null) {
            searchContext.setSorts(sort);
        }
        searchContext.setStart(start);
        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
        return indexer.search(searchContext);
    } catch (Exception e) {
        throw new SystemException(e);
    }
}
Also used : Serializable(java.io.Serializable) QueryConfig(com.liferay.portal.kernel.search.QueryConfig) Indexer(com.liferay.portal.kernel.search.Indexer) SystemException(com.liferay.portal.kernel.exception.SystemException) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SearchContext(com.liferay.portal.kernel.search.SearchContext) ContactFirstNameException(com.liferay.portal.ContactFirstNameException) ModelListenerException(com.liferay.portal.ModelListenerException) NoSuchImageException(com.liferay.portal.NoSuchImageException) GroupFriendlyURLException(com.liferay.portal.GroupFriendlyURLException) DuplicateOpenIdException(com.liferay.portal.DuplicateOpenIdException) ImageSizeException(com.liferay.portlet.documentlibrary.ImageSizeException) PasswordExpiredException(com.liferay.portal.PasswordExpiredException) UserPasswordException(com.liferay.portal.UserPasswordException) NoSuchUserException(com.liferay.portal.NoSuchUserException) UserSmsException(com.liferay.portal.UserSmsException) NoSuchRoleException(com.liferay.portal.NoSuchRoleException) PortalException(com.liferay.portal.kernel.exception.PortalException) UserIdException(com.liferay.portal.UserIdException) UserPortraitTypeException(com.liferay.portal.UserPortraitTypeException) RequiredUserException(com.liferay.portal.RequiredUserException) ReservedUserScreenNameException(com.liferay.portal.ReservedUserScreenNameException) IOException(java.io.IOException) ContactBirthdayException(com.liferay.portal.ContactBirthdayException) UserReminderQueryException(com.liferay.portal.UserReminderQueryException) DuplicateUserScreenNameException(com.liferay.portal.DuplicateUserScreenNameException) UserEmailAddressException(com.liferay.portal.UserEmailAddressException) ContactFullNameException(com.liferay.portal.ContactFullNameException) EncryptorException(com.liferay.util.EncryptorException) CompanyMaxUsersException(com.liferay.portal.CompanyMaxUsersException) NoSuchTicketException(com.liferay.portal.NoSuchTicketException) UserScreenNameException(com.liferay.portal.UserScreenNameException) ContactLastNameException(com.liferay.portal.ContactLastNameException) ReservedUserEmailAddressException(com.liferay.portal.ReservedUserEmailAddressException) DuplicateUserEmailAddressException(com.liferay.portal.DuplicateUserEmailAddressException) NoSuchUserGroupException(com.liferay.portal.NoSuchUserGroupException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchOrganizationException(com.liferay.portal.NoSuchOrganizationException) UserLockoutException(com.liferay.portal.UserLockoutException) UserPortraitSizeException(com.liferay.portal.UserPortraitSizeException)

Aggregations

SearchContext (com.liferay.portal.kernel.search.SearchContext)3 Indexer (com.liferay.portal.kernel.search.Indexer)2 CompanyMaxUsersException (com.liferay.portal.CompanyMaxUsersException)1 ContactBirthdayException (com.liferay.portal.ContactBirthdayException)1 ContactFirstNameException (com.liferay.portal.ContactFirstNameException)1 ContactFullNameException (com.liferay.portal.ContactFullNameException)1 ContactLastNameException (com.liferay.portal.ContactLastNameException)1 DuplicateOpenIdException (com.liferay.portal.DuplicateOpenIdException)1 DuplicateUserEmailAddressException (com.liferay.portal.DuplicateUserEmailAddressException)1 DuplicateUserScreenNameException (com.liferay.portal.DuplicateUserScreenNameException)1 GroupFriendlyURLException (com.liferay.portal.GroupFriendlyURLException)1 ModelListenerException (com.liferay.portal.ModelListenerException)1 NoSuchImageException (com.liferay.portal.NoSuchImageException)1 NoSuchOrganizationException (com.liferay.portal.NoSuchOrganizationException)1 NoSuchRoleException (com.liferay.portal.NoSuchRoleException)1 NoSuchTicketException (com.liferay.portal.NoSuchTicketException)1 NoSuchUserException (com.liferay.portal.NoSuchUserException)1 NoSuchUserGroupException (com.liferay.portal.NoSuchUserGroupException)1 PasswordExpiredException (com.liferay.portal.PasswordExpiredException)1 RequiredUserException (com.liferay.portal.RequiredUserException)1