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

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

Introduction

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

Prototype

public Map<String, Serializable> getAttributes() 

Source Link

Usage

From source file:com.liferay.alloy.mvc.BaseAlloyControllerImpl.java

License:Open Source License

protected AlloySearchResult search(Indexer indexer, AlloyServiceInvoker alloyServiceInvoker,
        HttpServletRequest request, PortletRequest portletRequest,
        SearchContainer<? extends BaseModel<?>> searchContainer, Map<String, Serializable> attributes,
        String keywords, Sort[] sorts) throws Exception {

    if (indexer == null) {
        throw new Exception("No indexer found for " + controllerPath);
    }/*  w  ww  .j  a v  a  2s  .c om*/

    AlloySearchResult alloySearchResult = new AlloySearchResult();

    alloySearchResult.setAlloyServiceInvoker(alloyServiceInvoker);

    if (searchContainer == null) {
        searchContainer = new SearchContainer<BaseModel<?>>(portletRequest, portletURL, null, null);
    }

    SearchContext searchContext = SearchContextFactory.getInstance(request);

    boolean andOperator = ParamUtil.getBoolean(request, "andOperator");

    searchContext.setAndSearch(andOperator);

    if ((attributes != null) && !attributes.isEmpty()) {
        searchContext.setAttributes(attributes);
    }

    searchContext.setEnd(searchContainer.getEnd());

    Class<?> indexerClass = Class.forName(indexer.getClassNames()[0]);

    if (!GroupedModel.class.isAssignableFrom(indexerClass)) {
        searchContext.setGroupIds(null);
    } else if (searchContext.getAttribute(Field.GROUP_ID) != null) {
        long groupId = GetterUtil.getLong(searchContext.getAttribute(Field.GROUP_ID));

        searchContext.setGroupIds(new long[] { groupId });
    }

    if (Validator.isNotNull(keywords)) {
        searchContext.setKeywords(keywords);
    }

    if (ArrayUtil.isNotEmpty(sorts)) {
        searchContext.setSorts(sorts);
    }

    searchContext.setStart(searchContainer.getStart());

    Hits hits = indexer.search(searchContext);

    alloySearchResult.setHits(hits);

    alloySearchResult.setPortletURL(portletURL, searchContext.getAttributes());

    alloySearchResult.afterPropertiesSet();

    return alloySearchResult;
}

From source file:com.liferay.asset.internal.search.AssetEntryIndexer.java

License:Open Source License

@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, BooleanFilter fullQueryBooleanFilter,
        SearchContext searchContext) throws Exception {

    if (searchContext.getAttributes() == null) {
        return;/*from   w  w w  .  j  a  v a2 s  .  com*/
    }

    addSearchTerm(searchQuery, searchContext, Field.DESCRIPTION, false);
    addSearchTerm(searchQuery, searchContext, Field.TITLE, false);
    addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false);
}

From source file:com.liferay.portlet.assetpublisher.util.AssetIndexer.java

License:Open Source License

@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) throws Exception {

    if (searchContext.getAttributes() == null) {
        return;/*ww w  .  jav  a  2s .  c o  m*/
    }

    addSearchTerm(searchQuery, searchContext, Field.DESCRIPTION, false);
    addSearchTerm(searchQuery, searchContext, Field.TITLE, false);
    addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false);
}

From source file:com.liferay.trash.internal.search.TrashIndexer.java

License:Open Source License

@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, BooleanFilter fullQueryBooleanFilter,
        SearchContext searchContext) throws Exception {

    if (searchContext.getAttributes() == null) {
        return;/*from  www.ja v  a 2  s .c  om*/
    }

    addSearchLocalizedTerm(searchQuery, searchContext, Field.CONTENT, true);
    addSearchLocalizedTerm(searchQuery, searchContext, Field.DESCRIPTION, true);
    addSearchTerm(searchQuery, searchContext, Field.REMOVED_BY_USER_NAME, true);
    addSearchLocalizedTerm(searchQuery, searchContext, Field.TITLE, true);
    addSearchTerm(searchQuery, searchContext, Field.TYPE, false);
    addSearchTerm(searchQuery, searchContext, Field.USER_NAME, true);
}

From source file:org.liferay.jukebox.util.AlbumIndexer.java

License:Open Source License

@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) throws Exception {

    if (searchContext.getAttributes() == null) {
        return;/*from   w  ww . ja  va2s  .com*/
    }

    addSearchTerm(searchQuery, searchContext, Field.TITLE, true);
    addSearchTerm(searchQuery, searchContext, "artist", true);
    addSearchTerm(searchQuery, searchContext, "year", false);
}

From source file:org.liferay.jukebox.util.ArtistIndexer.java

License:Open Source License

@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) throws Exception {

    if (searchContext.getAttributes() == null) {
        return;// www .ja  v  a 2s.  c o m
    }

    addSearchTerm(searchQuery, searchContext, Field.TITLE, true);
    addSearchTerm(searchQuery, searchContext, "bio", true);
}

From source file:org.liferay.jukebox.util.SongIndexer.java

License:Open Source License

@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) throws Exception {

    if (searchContext.getAttributes() == null) {
        return;/*from  ww w  .j a  v  a 2s  .  com*/
    }

    addSearchTerm(searchQuery, searchContext, Field.TITLE, true);
    addSearchTerm(searchQuery, searchContext, "album", true);
    addSearchTerm(searchQuery, searchContext, "artist", true);
}