Example usage for com.liferay.portal.kernel.search Field ENTRY_CLASS_PK

List of usage examples for com.liferay.portal.kernel.search Field ENTRY_CLASS_PK

Introduction

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

Prototype

String ENTRY_CLASS_PK

To view the source code for com.liferay.portal.kernel.search Field ENTRY_CLASS_PK.

Click Source Link

Usage

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

License:Open Source License

@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) {

    String title = document.get(Field.TITLE);

    String content = snippet;/*  w w w.ja v  a2 s .  c om*/

    if (Validator.isNull(snippet)) {
        content = StringUtil.shorten(document.get(Field.CONTENT), 200);
    }

    String messageId = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("struts_action", "/message_boards/view_message");
    portletURL.setParameter("messageId", messageId);

    return new Summary(title, content, portletURL);
}

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

License:Open Source License

@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) {

    String title = document.get(Field.TITLE);

    String content = snippet;/*from  w  ww  .  java2 s .c  om*/

    if (Validator.isNull(snippet)) {
        content = StringUtil.shorten(document.get(Field.CONTENT), 200);
    }

    String productEntryId = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("struts_action", "/software_catalog/view_product_entry");
    portletURL.setParameter("productEntryId", productEntryId);

    return new Summary(title, content, portletURL);
}

From source file:com.liferay.portlet.tags.service.impl.TagsAssetLocalServiceImpl.java

License:Open Source License

protected TagsAsset getAsset(Document doc) throws PortalException, SystemException {

    String portletId = GetterUtil.getString(doc.get(Field.PORTLET_ID));

    if (portletId.equals(PortletKeys.BLOGS)) {
        long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));

        long classNameId = PortalUtil.getClassNameId(BlogsEntry.class.getName());
        long classPK = entryId;

        return tagsAssetPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.BOOKMARKS)) {
        long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));

        long classNameId = PortalUtil.getClassNameId(BookmarksEntry.class.getName());
        long classPK = entryId;

        return tagsAssetPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)) {
        long folderId = GetterUtil.getLong(doc.get("repositoryId"));
        String name = doc.get("path");

        DLFileEntry fileEntry = dlFileEntryLocalService.getFileEntry(folderId, name);

        long classNameId = PortalUtil.getClassNameId(DLFileEntry.class.getName());
        long classPK = fileEntry.getFileEntryId();

        return tagsAssetPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.IMAGE_GALLERY)) {
        long imageId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));

        long classNameId = PortalUtil.getClassNameId(IGImage.class.getName());
        long classPK = imageId;

        return tagsAssetPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.JOURNAL)) {
        long groupId = GetterUtil.getLong(doc.get(Field.GROUP_ID));
        String articleId = doc.get(Field.ENTRY_CLASS_PK);
        // double version = GetterUtil.getDouble(doc.get("version"));

        long articleResourcePrimKey = journalArticleResourceLocalService.getArticleResourcePrimKey(groupId,
                articleId);/*from  w w  w .  ja  v a 2s  .co m*/

        long classNameId = PortalUtil.getClassNameId(JournalArticle.class.getName());
        long classPK = articleResourcePrimKey;

        return tagsAssetPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
        long messageId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));

        long classNameId = PortalUtil.getClassNameId(MBMessage.class.getName());
        long classPK = messageId;

        return tagsAssetPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.WIKI)) {
        long nodeId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
        String title = doc.get(Field.TITLE);

        long pageResourcePrimKey = wikiPageResourceLocalService.getPageResourcePrimKey(nodeId, title);

        long classNameId = PortalUtil.getClassNameId(WikiPage.class.getName());
        long classPK = pageResourcePrimKey;

        return tagsAssetPersistence.findByC_C(classNameId, classPK);
    }

    return null;
}

From source file:com.liferay.repository.external.ExtRepositoryAdapter.java

License:Open Source License

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

    long startTime = System.currentTimeMillis();

    List<ExtRepositorySearchResult<?>> extRepositorySearchResults = null;

    try {//from   w ww.j ava  2  s  .c  o m
        extRepositorySearchResults = _extRepository.search(searchContext, query,
                new ExtRepositoryQueryMapperImpl(this));
    } catch (PortalException pe) {
        throw new SearchException("Unable to perform search", pe);
    } catch (SystemException se) {
        throw new SearchException("Unable to perform search", se);
    }

    QueryConfig queryConfig = searchContext.getQueryConfig();

    List<Document> documents = new ArrayList<Document>();
    List<String> snippets = new ArrayList<String>();
    List<Float> scores = new ArrayList<Float>();

    int total = 0;

    for (ExtRepositorySearchResult<?> extRepositorySearchResult : extRepositorySearchResults) {

        try {
            ExtRepositoryObjectAdapter<?> extRepositoryEntryAdapter = _toExtRepositoryObjectAdapter(
                    ExtRepositoryObjectAdapterType.OBJECT, extRepositorySearchResult.getObject());

            Document document = new DocumentImpl();

            document.addKeyword(Field.ENTRY_CLASS_NAME, extRepositoryEntryAdapter.getModelClassName());
            document.addKeyword(Field.ENTRY_CLASS_PK, extRepositoryEntryAdapter.getPrimaryKey());
            document.addKeyword(Field.TITLE, extRepositoryEntryAdapter.getName());

            documents.add(document);

            if (queryConfig.isScoreEnabled()) {
                scores.add(extRepositorySearchResult.getScore());
            } else {
                scores.add(1.0F);
            }

            snippets.add(extRepositorySearchResult.getSnippet());

            total++;
        } catch (SystemException se) {
            if (_log.isWarnEnabled()) {
                _log.warn("Invalid entry returned from search", se);
            }
        } catch (PortalException pe) {
            if (_log.isWarnEnabled()) {
                _log.warn("Invalid entry returned from search", pe);
            }
        }
    }

    float searchTime = (float) (System.currentTimeMillis() - startTime) / Time.SECOND;

    Hits hits = new HitsImpl();

    hits.setDocs(documents.toArray(new Document[documents.size()]));
    hits.setLength(total);
    hits.setQueryTerms(new String[0]);
    hits.setScores(ArrayUtil.toFloatArray(scores));
    hits.setSearchTime(searchTime);
    hits.setSnippets(snippets.toArray(new String[snippets.size()]));
    hits.setStart(startTime);

    return hits;
}

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

License:Open Source License

public TrashIndexer() {
    setDefaultSelectedFieldNames(Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.REMOVED_BY_USER_NAME,
            Field.REMOVED_DATE, Field.ROOT_ENTRY_CLASS_NAME, Field.ROOT_ENTRY_CLASS_PK, Field.UID);
    setFilterSearch(true);//from   w  w w .  ja v a2s  .c  o m
    setPermissionAware(true);
}

From source file:com.liferay.trash.service.impl.TrashEntryLocalServiceImpl.java

License:Open Source License

private List<TrashEntry> _getEntries(Hits hits) {
    List<TrashEntry> entries = new ArrayList<>();

    for (Document document : hits.getDocs()) {
        String entryClassName = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME));
        long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

        TrashEntry entry = fetchEntry(entryClassName, classPK);

        if (entry != null) {
            entries.add(entry);/*from  w ww.  j a  v  a  2s .c  o  m*/

            continue;
        }

        try {
            String userName = GetterUtil.getString(document.get(Field.REMOVED_BY_USER_NAME));

            Date removedDate = document.getDate(Field.REMOVED_DATE);

            entry = new TrashEntryImpl();

            entry.setUserName(userName);
            entry.setCreateDate(removedDate);

            TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(entryClassName);

            TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

            entry.setClassName(trashRenderer.getClassName());
            entry.setClassPK(trashRenderer.getClassPK());

            String rootEntryClassName = GetterUtil.getString(document.get(Field.ROOT_ENTRY_CLASS_NAME));
            long rootEntryClassPK = GetterUtil.getLong(document.get(Field.ROOT_ENTRY_CLASS_PK));

            TrashEntry rootTrashEntry = fetchEntry(rootEntryClassName, rootEntryClassPK);

            if (rootTrashEntry != null) {
                entry.setRootEntry(rootTrashEntry);
            }

            entries.add(entry);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(StringBundler.concat("Unable to find trash entry for ", entryClassName,
                        " with primary key ", String.valueOf(classPK)));
            }
        }
    }

    return entries;
}

From source file:com.liferay.users.admin.internal.search.UserIndexer.java

License:Open Source License

public UserIndexer() {
    setDefaultSelectedFieldNames(Field.ASSET_TAG_NAMES, Field.COMPANY_ID, Field.ENTRY_CLASS_NAME,
            Field.ENTRY_CLASS_PK, Field.GROUP_ID, Field.MODIFIED_DATE, Field.SCOPE_GROUP_ID, Field.UID,
            Field.USER_ID);/*w w  w  . j  a  va  2s  . c om*/
    setPermissionAware(true);
    setStagingAware(false);
}

From source file:com.liferay.wiki.search.WikiNodeIndexer.java

License:Open Source License

public WikiNodeIndexer() {
    setDefaultSelectedFieldNames(Field.COMPANY_ID, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.UID);
    setFilterSearch(false);
    setPermissionAware(false);
}

From source file:com.liferay.wiki.search.WikiPageIndexer.java

License:Open Source License

public WikiPageIndexer() {
    setDefaultSelectedFieldNames(Field.ASSET_TAG_NAMES, Field.COMPANY_ID, Field.CONTENT, Field.ENTRY_CLASS_NAME,
            Field.ENTRY_CLASS_PK, Field.GROUP_ID, Field.MODIFIED_DATE, Field.SCOPE_GROUP_ID, Field.TITLE,
            Field.UID);/*  ww w .j a va 2  s. c o  m*/
    setFilterSearch(true);
    setPermissionAware(true);
}

From source file:com.slayer.service.impl.LMSBookLocalServiceImpl.java

License:Open Source License

public List<LMSBook> searchIndex(String keyword, long companyId, long groupId) throws SystemException {

    Hits hits = getHits(keyword, companyId, groupId);

    // 4. return null if no results
    if (Validator.isNull(hits) || hits.getLength() == 0)
        return null;

    // 5. Convert results into a List of LMSBook objects
    List<LMSBook> books = new ArrayList<LMSBook>();
    for (Document document : hits.getDocs()) {
        long bookId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

        LMSBook book = fetchLMSBook(bookId);

        books.add(book);//  w  w w .j a  va 2 s.co m
    }

    return books;
}