Example usage for com.liferay.portal.kernel.search QueryConfig setScoreEnabled

List of usage examples for com.liferay.portal.kernel.search QueryConfig setScoreEnabled

Introduction

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

Prototype

public void setScoreEnabled(boolean scoreEnabled) 

Source Link

Usage

From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java

License:Open Source License

protected SearchContext buildSearchContext(long userId, long groupId, long ownerUserId, String company,
        String fullName, int status, LinkedHashMap<String, Object> params, boolean andSearch, int start,
        int end, Sort sort) throws PortalException {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, status);

    if (Validator.isNotNull(company)) {
        searchContext.setAttribute("company", company);
    }//w  w w. j av  a 2  s  .  com

    if (Validator.isNotNull(fullName)) {
        searchContext.setAttribute("fullName", fullName);
    }

    searchContext.setAttribute("paginationType", "more");

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    if (ownerUserId > 0) {
        searchContext.setOwnerUserId(ownerUserId);
    }

    searchContext.setEnd(end);
    if (groupId > 0) {
        searchContext.setGroupIds(new long[] { groupId });
    }
    searchContext.setSorts(sort);
    searchContext.setStart(start);
    searchContext.setUserId(userId);

    searchContext.setAndSearch(andSearch);

    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);

    return searchContext;
}

From source file:ch.inofix.referencemanager.service.impl.ReferenceLocalServiceImpl.java

License:Open Source License

protected SearchContext buildSearchContext(long userId, long groupId, long bibliographyId, String author,
        String title, String year, int status, LinkedHashMap<String, Object> params, boolean andSearch,
        int start, int end, Sort sort) throws PortalException {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, status);

    if (Validator.isNotNull(author)) {
        searchContext.setAttribute("author", author);
    }/*from   w ww  . jav  a 2  s . c o m*/

    if (bibliographyId > 0) {
        searchContext.setAttribute("bibliographyId", bibliographyId);
    }

    if (Validator.isNotNull(title)) {
        searchContext.setAttribute("title", title);
    }

    if (Validator.isNotNull(year)) {
        searchContext.setAttribute("year", year);
    }

    searchContext.setAttribute("paginationType", "more");

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    searchContext.setEnd(end);
    if (groupId > 0) {
        searchContext.setGroupIds(new long[] { groupId });
    }
    searchContext.setSorts(sort);
    searchContext.setStart(start);
    searchContext.setUserId(userId);

    searchContext.setAndSearch(andSearch);

    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);

    return searchContext;
}

From source file:com.liferay.asset.internal.util.AssetHelperImpl.java

License:Open Source License

private AssetSearcher _getAssetSearcher(SearchContext searchContext, AssetEntryQuery assetEntryQuery, int start,
        int end) throws Exception {

    Indexer<?> searcher = AssetSearcher.getInstance();

    AssetSearcher assetSearcher = (AssetSearcher) searcher;

    assetSearcher.setAssetEntryQuery(assetEntryQuery);

    Layout layout = assetEntryQuery.getLayout();

    if (layout != null) {
        searchContext.setAttribute(Field.LAYOUT_UUID, layout.getUuid());
    }/*  www .  ja  v  a  2 s.c  om*/

    String ddmStructureFieldName = (String) assetEntryQuery.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = assetEntryQuery.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

        searchContext.setAttribute("ddmStructureFieldName", ddmStructureFieldName);
        searchContext.setAttribute("ddmStructureFieldValue", ddmStructureFieldValue);
    }

    String paginationType = GetterUtil.getString(assetEntryQuery.getPaginationType(), "more");

    if (!paginationType.equals("none") && !paginationType.equals("simple")) {

        searchContext.setAttribute("paginationType", paginationType);
    }

    searchContext.setClassTypeIds(assetEntryQuery.getClassTypeIds());
    searchContext.setEnd(end);
    searchContext.setGroupIds(assetEntryQuery.getGroupIds());

    if (Validator.isNull(assetEntryQuery.getKeywords())) {
        QueryConfig queryConfig = searchContext.getQueryConfig();

        queryConfig.setScoreEnabled(false);
    } else {
        searchContext.setLike(true);
    }

    searchContext.setSorts(_getSorts(assetEntryQuery, searchContext.getLocale()));
    searchContext.setStart(start);

    return assetSearcher;
}

From source file:com.liferay.bookmarks.service.impl.BookmarksEntryLocalServiceImpl.java

License:Open Source License

@Override
public Hits search(long groupId, long userId, long creatorUserId, int status, int start, int end)
        throws PortalException {

    Indexer<BookmarksEntry> indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class.getName());

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, status);

    if (creatorUserId > 0) {
        searchContext.setAttribute(Field.USER_ID, String.valueOf(creatorUserId));
    }/*from w  w  w.ja  va 2 s  . c  om*/

    searchContext.setAttribute("paginationType", "none");

    Group group = groupLocalService.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    searchContext.setEnd(end);
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setSorts(new Sort(Field.MODIFIED_DATE, true));
    searchContext.setStart(start);
    searchContext.setUserId(userId);

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setHighlightEnabled(false);
    queryConfig.setScoreEnabled(false);

    return indexer.search(searchContext);
}

From source file:com.liferay.bookmarks.util.test.BookmarksTestUtil.java

License:Open Source License

public static SearchContext getSearchContext(long companyId, long groupId, long folderId, String keywords,
        boolean highlight, boolean score) {

    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(companyId);
    searchContext.setFolderIds(new long[] { folderId });
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setKeywords(keywords);

    QueryConfig queryConfig = new QueryConfig();

    queryConfig.setHighlightEnabled(highlight);
    queryConfig.setScoreEnabled(score);

    searchContext.setQueryConfig(queryConfig);

    return searchContext;
}

From source file:com.liferay.configuration.admin.web.internal.portlet.action.SearchMVCRenderCommand.java

License:Open Source License

@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {

    Indexer indexer = _indexerRegistry.nullSafeGetIndexer(ConfigurationModel.class);

    SearchContext searchContext = new SearchContext();

    searchContext.setAndSearch(false);//from   w w  w .j ava2  s  .c o  m
    searchContext.setCompanyId(CompanyConstants.SYSTEM);
    searchContext.setLocale(renderRequest.getLocale());

    String keywords = renderRequest.getParameter("keywords");

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

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setHighlightEnabled(true);
    queryConfig.setLocale(renderRequest.getLocale());
    queryConfig.setScoreEnabled(true);

    try {
        Hits hits = indexer.search(searchContext);

        Document[] documents = hits.getDocs();

        Map<String, ConfigurationModel> configurationModels = _configurationModelRetriever
                .getConfigurationModels();

        List<ConfigurationModel> searchResults = new ArrayList<>(documents.length);

        for (Document document : documents) {
            String configurationModelId = document.get(FieldNames.CONFIGURATION_MODEL_ID);

            ConfigurationModel configurationModel = configurationModels.get(configurationModelId);

            if (configurationModel == null) {
                String configurationModelFactoryId = document.get(FieldNames.CONFIGURATION_MODEL_FACTORY_PID);

                configurationModel = configurationModels.get(configurationModelFactoryId);
            }

            if (configurationModel != null) {
                searchResults.add(configurationModel);
            }
        }

        ConfigurationModelIterator configurationModelIterator = new ConfigurationModelIterator(searchResults);

        renderRequest.setAttribute(ConfigurationAdminWebKeys.CONFIGURATION_MODEL_ITERATOR,
                configurationModelIterator);

        renderRequest.setAttribute(ConfigurationAdminWebKeys.RESOURCE_BUNDLE_LOADER_PROVIDER,
                _resourceBundleLoaderProvider);
    } catch (Exception e) {
        throw new PortletException(e);
    }

    return "/view.jsp";
}

From source file:com.liferay.document.library.repository.cmis.internal.CMISRepository.java

License:Open Source License

@Override
public Hits search(SearchContext searchContext, Query query) throws SearchException {

    try {//  w w w. j ava2s  .c  o m
        QueryConfig queryConfig = searchContext.getQueryConfig();

        queryConfig.setScoreEnabled(false);

        return doSearch(searchContext, query);
    } catch (Exception e) {
        throw new SearchException(e);
    }
}

From source file:com.liferay.document.library.repository.cmis.search.BaseCmisSearchQueryBuilderTest.java

License:Open Source License

protected SearchContext getSearchContext() {
    SearchContext searchContext = new SearchContext();

    searchContext.setSearchEngineId(SearchEngineHelper.GENERIC_ENGINE_ID);

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setScoreEnabled(true);

    return searchContext;
}

From source file:com.liferay.document.library.service.test.DLAppServiceTest.java

License:Open Source License

protected static void search(FileEntry fileEntry, String keywords, boolean expected) throws Exception {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute("paginationType", "regular");
    searchContext.setCompanyId(fileEntry.getCompanyId());
    searchContext.setFolderIds(new long[] { fileEntry.getFolderId() });
    searchContext.setGroupIds(new long[] { fileEntry.getRepositoryId() });
    searchContext.setKeywords(keywords);

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setHighlightEnabled(false);
    queryConfig.setScoreEnabled(false);

    Indexer<DLFileEntry> indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName());

    Hits hits = indexer.search(searchContext);

    boolean found = false;

    for (Document document : hits.getDocs()) {
        long fileEntryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

        if (fileEntryId == fileEntry.getFileEntryId()) {
            found = true;//from   w w w  . java  2 s.co m

            break;
        }
    }

    Assert.assertEquals(hits.toString(), expected, found);
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected SearchContext buildSearchContext(long companyId, long groupId, List<Long> folderIds, long classNameId,
        String articleId, String title, String description, String content, int status, String ddmStructureKey,
        String ddmTemplateKey, LinkedHashMap<String, Object> params, boolean andSearch, int start, int end,
        Sort sort) {//from w w  w.  j  av  a 2s. co  m

    SearchContext searchContext = new SearchContext();

    searchContext.setAndSearch(andSearch);

    Map<String, Serializable> attributes = new HashMap<>();

    attributes.put(Field.ARTICLE_ID, articleId);
    attributes.put(Field.CLASS_NAME_ID, classNameId);
    attributes.put(Field.CONTENT, content);
    attributes.put(Field.DESCRIPTION, description);
    attributes.put(Field.STATUS, status);
    attributes.put(Field.TITLE, title);
    attributes.put("ddmStructureKey", ddmStructureKey);
    attributes.put("ddmTemplateKey", ddmTemplateKey);
    attributes.put("params", params);

    searchContext.setAttributes(attributes);

    searchContext.setCompanyId(companyId);
    searchContext.setEnd(end);
    searchContext.setFolderIds(folderIds);
    searchContext.setGroupIds(new long[] { groupId });

    if (params != null) {
        searchContext.setIncludeDiscussions(GetterUtil.getBoolean(params.get("includeDiscussions")));

        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);

    return searchContext;
}