com.liferay.blade.samples.searchkeywordquerycontributor.AllKeywordQueryContributor.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.blade.samples.searchkeywordquerycontributor.AllKeywordQueryContributor.java

Source

/**
 * Copyright 2000-present Liferay, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.liferay.blade.samples.searchkeywordquerycontributor;

import com.liferay.portal.kernel.search.BooleanQuery;
import com.liferay.portal.kernel.search.Field;
import com.liferay.portal.kernel.search.SearchContext;
import com.liferay.portal.search.query.QueryHelper;
import com.liferay.portal.search.spi.model.query.contributor.KeywordQueryContributor;
import com.liferay.portal.search.spi.model.query.contributor.helper.KeywordQueryContributorHelper;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
 * @author Liferay
 */
@Component(immediate = true, property = "indexer.class.name=com.liferay.calendar.model.Calendar", service = KeywordQueryContributor.class)
public class AllKeywordQueryContributor implements KeywordQueryContributor {

    @Override
    public void contribute(String keywords, BooleanQuery booleanQuery,
            KeywordQueryContributorHelper keywordQueryContributorHelper) {

        SearchContext searchContext = keywordQueryContributorHelper.getSearchContext();

        queryHelper.addSearchLocalizedTerm(booleanQuery, searchContext, Field.CAPTION, true);
    }

    @Reference
    protected QueryHelper queryHelper;

}