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

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

Introduction

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

Prototype

public Serializable getAttribute(String name) 

Source Link

Usage

From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java

License:Open Source License

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

    addSearchTerm(searchQuery, searchContext, Field.CLASS_PK, false);
    addSearchLocalizedTerm(searchQuery, searchContext, Field.CONTENT, false);
    addSearchLocalizedTerm(searchQuery, searchContext, Field.DESCRIPTION, false);
    addSearchTerm(searchQuery, searchContext, Field.ENTRY_CLASS_PK, false);
    addSearchLocalizedTerm(searchQuery, searchContext, Field.TITLE, false);
    addSearchTerm(searchQuery, searchContext, Field.TYPE, false);
    //        addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false);

    addSearchTerm(searchQuery, searchContext, "articleId", false);

    LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    if (params != null) {
        String expandoAttributes = (String) params.get("expandoAttributes");

        if (Validator.isNotNull(expandoAttributes)) {
            addSearchExpando(searchQuery, searchContext, expandoAttributes);
        }//ww  w  .j  av  a 2 s.  co  m
    }
}

From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java

License:Open Source License

@Override
protected void addSearchLocalizedTerm(BooleanQuery searchQuery, SearchContext searchContext, String field,
        boolean like) throws Exception {

    if (Validator.isNull(field)) {
        return;//from w  ww  .  j a v a2s.  c o m
    }

    String value = String.valueOf(searchContext.getAttribute(field));

    if (Validator.isNull(value)) {
        value = searchContext.getKeywords();
    }

    if (Validator.isNull(value)) {
        return;
    }

    String localizedField = DocumentImpl.getLocalizedName(searchContext.getLocale(), field);

    if (Validator.isNull(searchContext.getKeywords())) {
        BooleanQuery localizedQuery = BooleanQueryFactoryUtil.create(searchContext);

        localizedQuery.addTerm(field, value, like);
        localizedQuery.addTerm(localizedField, value, like);

        BooleanClauseOccur booleanClauseOccur = BooleanClauseOccur.SHOULD;

        if (searchContext.isAndSearch()) {
            booleanClauseOccur = BooleanClauseOccur.MUST;
        }

        searchQuery.add(localizedQuery, booleanClauseOccur);
    } else {
        searchQuery.addTerm(localizedField, value, like);
    }
}

From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java

License:Open Source License

@Override
protected void addStatus(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    boolean includeScheduledArticles = false;

    if (params != null) {
        includeScheduledArticles = GetterUtil.getBoolean(params.get("includeScheduledArticles"));
    }/* ww w . j av  a  2 s . c  om*/

    if (includeScheduledArticles) {
        BooleanQuery statusQuery = BooleanQueryFactoryUtil.create(searchContext);

        BooleanQuery statusHeadQuery = BooleanQueryFactoryUtil.create(searchContext);

        statusHeadQuery.addRequiredTerm("head", Boolean.TRUE);
        statusHeadQuery.addRequiredTerm(Field.STATUS, WorkflowConstants.STATUS_APPROVED);

        statusQuery.add(statusHeadQuery, BooleanClauseOccur.SHOULD);

        BooleanQuery statusScheduledHeadQuery = BooleanQueryFactoryUtil.create(searchContext);

        statusScheduledHeadQuery.addRequiredTerm("scheduledHead", Boolean.TRUE);
        statusScheduledHeadQuery.addRequiredTerm(Field.STATUS, WorkflowConstants.STATUS_SCHEDULED);

        statusQuery.add(statusScheduledHeadQuery, BooleanClauseOccur.SHOULD);

        contextQuery.add(statusQuery, BooleanClauseOccur.MUST);
    } else {
        super.addStatus(contextQuery, searchContext);

        boolean head = GetterUtil.getBoolean(searchContext.getAttribute("head"), Boolean.TRUE);
        boolean relatedClassName = GetterUtil.getBoolean(searchContext.getAttribute("relatedClassName"));

        if (head && !relatedClassName) {
            contextQuery.addRequiredTerm("head", Boolean.TRUE);
        }
    }
}

From source file:com.liferay.portlet.journal.util.JournalIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    Long classNameId = (Long) searchContext.getAttribute(Field.CLASS_NAME_ID);

    if (classNameId != null) {
        contextQuery.addRequiredTerm("classNameId", classNameId.toString());
    }/*  w ww.  jav  a  2s  .c  om*/

    int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS),
            WorkflowConstants.STATUS_APPROVED);

    if (status != WorkflowConstants.STATUS_ANY) {
        contextQuery.addRequiredTerm(Field.STATUS, status);
    }

    String articleType = (String) searchContext.getAttribute("articleType");

    if (Validator.isNotNull(articleType)) {
        contextQuery.addRequiredTerm(Field.TYPE, articleType);
    }

    String structureId = (String) searchContext.getAttribute("structureId");

    if (Validator.isNotNull(structureId)) {
        contextQuery.addRequiredTerm("structureId", structureId);
    }

    String templateId = (String) searchContext.getAttribute("templateId");

    if (Validator.isNotNull(templateId)) {
        contextQuery.addRequiredTerm("templateId", templateId);
    }
}

From source file:com.liferay.portlet.journal.util.JournalIndexer.java

License:Open Source License

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

    addSearchTerm(searchQuery, searchContext, Field.CLASS_PK, false);
    addLocalizedSearchTerm(searchQuery, searchContext, Field.CONTENT, false);
    addLocalizedSearchTerm(searchQuery, searchContext, Field.DESCRIPTION, false);
    addSearchTerm(searchQuery, searchContext, Field.ENTRY_CLASS_PK, false);
    addLocalizedSearchTerm(searchQuery, searchContext, Field.TITLE, false);
    addSearchTerm(searchQuery, searchContext, Field.TYPE, false);
    addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false);

    LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    if (params != null) {
        String expandoAttributes = (String) params.get("expandoAttributes");

        if (Validator.isNotNull(expandoAttributes)) {
            addSearchExpando(searchQuery, searchContext, expandoAttributes);
        }//from   w  ww.j  a v a2s  .  c  om
    }
}

From source file:com.liferay.portlet.messageboards.util.MBIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_ANY);

    if (status != WorkflowConstants.STATUS_ANY) {
        contextQuery.addRequiredTerm(Field.STATUS, status);
    }/*  w  w w  .j a  va 2 s  .c o m*/

    boolean discussion = GetterUtil.getBoolean(searchContext.getAttribute("discussion"), false);

    contextQuery.addRequiredTerm("discussion", discussion);

    long threadId = GetterUtil.getLong((String) searchContext.getAttribute("threadId"));

    if (threadId > 0) {
        contextQuery.addRequiredTerm("threadId", threadId);
    }

    long[] categoryIds = searchContext.getCategoryIds();

    if ((categoryIds != null) && (categoryIds.length > 0)) {
        if (categoryIds[0] == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {

            return;
        }

        BooleanQuery categoriesQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (long categoryId : categoryIds) {
            try {
                MBCategoryServiceUtil.getCategory(categoryId);
            } catch (Exception e) {
                continue;
            }

            categoriesQuery.addTerm(Field.CATEGORY_ID, categoryId);
        }

        contextQuery.add(categoriesQuery, BooleanClauseOccur.MUST);
    }
}

From source file:com.liferay.portlet.softwarecatalog.util.SCIndexer.java

License:Open Source License

@Override
protected void postProcessFullQuery(BooleanQuery fullQuery, SearchContext searchContext) throws Exception {

    String type = (String) searchContext.getAttribute("type");

    if (Validator.isNotNull(type)) {
        BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);

        searchQuery.addRequiredTerm("type", type);

        fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
    }/*ww  w .j a  v  a 2s .  co m*/
}

From source file:com.liferay.portlet.usersadmin.util.OrganizationIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    if (params == null) {
        return;//w  w  w  .j a  v  a2 s . c o  m
    }

    List<Organization> organizationsTree = (List<Organization>) params.get("organizationsTree");

    if ((organizationsTree != null) && !organizationsTree.isEmpty()) {
        BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (Organization organization : organizationsTree) {
            String treePath = organization.buildTreePath();

            booleanQuery.addTerm("treePath", treePath, true);
        }

        contextQuery.add(booleanQuery, BooleanClauseOccur.MUST);
    }
}

From source file:com.liferay.portlet.usersadmin.util.OrganizationIndexer.java

License:Open Source License

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

    addSearchTerm(searchQuery, searchContext, "city", false);
    addSearchTerm(searchQuery, searchContext, "country", false);
    addSearchTerm(searchQuery, searchContext, "name", false);
    addSearchTerm(searchQuery, searchContext, "parentOrganizationId", false);
    addSearchTerm(searchQuery, searchContext, "region", false);
    addSearchTerm(searchQuery, searchContext, "street", false);
    addSearchTerm(searchQuery, searchContext, "type", false);
    addSearchTerm(searchQuery, searchContext, "zip", false);

    LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    if (params != null) {
        String expandoAttributes = (String) params.get("expandoAttributes");

        if (Validator.isNotNull(expandoAttributes)) {
            addSearchExpando(searchQuery, searchContext, expandoAttributes);
        }//from  www. j ava  2 s . c om
    }
}

From source file:com.liferay.portlet.usersadmin.util.UserIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS),
            WorkflowConstants.STATUS_APPROVED);

    if (status != WorkflowConstants.STATUS_ANY) {
        contextQuery.addRequiredTerm(Field.STATUS, status);
    }/* ww w.ja v a2  s.c o m*/

    LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    if (params != null) {
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();

            if (value == null) {
                continue;
            }

            addContextQueryParams(contextQuery, searchContext, key, value);
        }
    }
}