Search in sources :

Example 11 with Document

use of com.liferay.portal.kernel.search.Document in project liferay-ide by liferay.

the class ArtistIndexer method doGetDocument.

@Override
protected Document doGetDocument(Object obj) throws Exception {
    Artist artist = (Artist) obj;
    Document document = getBaseModelDocument(PORTLET_ID, artist);
    document.addDate(Field.MODIFIED_DATE, artist.getModifiedDate());
    document.addText(Field.TITLE, artist.getName());
    document.addKeyword("artistId", artist.getArtistId());
    document.addText("bio", artist.getBio());
    return document;
}
Also used : Artist(org.liferay.jukebox.model.Artist) Document(com.liferay.portal.kernel.search.Document)

Example 12 with Document

use of com.liferay.portal.kernel.search.Document in project liferay-ide by liferay.

the class SongIndexer method reindexEntries.

protected void reindexEntries(long companyId) throws PortalException, SystemException {
    final Collection<Document> documents = new ArrayList<Document>();
    ActionableDynamicQuery actionableDynamicQuery = new SongActionableDynamicQuery() {

        @Override
        protected void addCriteria(DynamicQuery dynamicQuery) {
        }

        @Override
        protected void performAction(Object object) throws PortalException {
            Song song = (Song) object;
            Document document = getDocument(song);
            documents.add(document);
        }
    };
    actionableDynamicQuery.setCompanyId(companyId);
    actionableDynamicQuery.performActions();
    SearchEngineUtil.updateDocuments(getSearchEngineId(), companyId, documents);
}
Also used : SongActionableDynamicQuery(org.liferay.jukebox.service.persistence.SongActionableDynamicQuery) Song(org.liferay.jukebox.model.Song) DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) SongActionableDynamicQuery(org.liferay.jukebox.service.persistence.SongActionableDynamicQuery) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery) ArrayList(java.util.ArrayList) Document(com.liferay.portal.kernel.search.Document) SongActionableDynamicQuery(org.liferay.jukebox.service.persistence.SongActionableDynamicQuery) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)

Example 13 with Document

use of com.liferay.portal.kernel.search.Document in project liferay-ide by liferay.

the class SearchResultTest method getSearchResults.

public static List<SearchResult> getSearchResults(Hits hits, Locale locale, PortletURL portletURL) {
    List<SearchResult> searchResults = new ArrayList<SearchResult>();
    for (Document document : hits.getDocs()) {
        String entryClassName = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME));
        long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));
        try {
            String className = entryClassName;
            long classPK = entryClassPK;
            FileEntry fileEntry = null;
            MBMessage mbMessage = null;
            if (entryClassName.equals(DLFileEntry.class.getName()) || entryClassName.equals(MBMessage.class.getName())) {
                classPK = GetterUtil.getLong(document.get(Field.CLASS_PK));
                long classNameId = GetterUtil.getLong(document.get(Field.CLASS_NAME_ID));
                if ((classPK > 0) && (classNameId > 0)) {
                    className = PortalUtil.getClassName(classNameId);
                    if (entryClassName.equals(DLFileEntry.class.getName())) {
                        fileEntry = DLAppLocalServiceUtil.getFileEntry(entryClassPK);
                    } else if (entryClassName.equals(MBMessage.class.getName())) {
                        mbMessage = MBMessageLocalServiceUtil.getMessage(entryClassPK);
                    }
                } else {
                    className = entryClassName;
                    classPK = entryClassPK;
                }
            }
            SearchResult searchResult = new SearchResult(className, classPK);
            int index = searchResults.indexOf(searchResult);
            if (index < 0) {
                searchResults.add(searchResult);
            } else {
                searchResult = searchResults.get(index);
            }
            if (fileEntry != null) {
                Summary summary = getSummary(document, DLFileEntry.class.getName(), fileEntry.getFileEntryId(), locale, portletURL);
                searchResult.addFileEntry(fileEntry, summary);
            }
            if (mbMessage != null) {
                searchResult.addMBMessage(mbMessage);
                searchResult.getMBMessages();
                searchResult.getFileEntryTuples();
            }
            if (entryClassName.equals(JournalArticle.class.getName())) {
                String version = document.get(Field.VERSION);
                searchResult.addVersion(version);
            }
            if ((mbMessage == null) && (fileEntry == null)) {
                Summary summary = getSummary(document, className, classPK, locale, portletURL);
                searchResult.setSummary(summary);
            } else {
                if (searchResult.getSummary() == null) {
                    Summary summary = getSummary(className, classPK, locale, portletURL);
                    searchResult.setSummary(summary);
                }
            }
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn("Search index is stale and contains entry {" + entryClassPK + "}");
            }
        }
    }
    return searchResults;
}
Also used : ArrayList(java.util.ArrayList) SearchResult(com.liferay.portal.kernel.search.SearchResult) Document(com.liferay.portal.kernel.search.Document) MBMessage(com.liferay.portlet.messageboards.model.MBMessage) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) Summary(com.liferay.portal.kernel.search.Summary) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) JournalArticle(com.liferay.portlet.journal.model.JournalArticle)

Aggregations

Document (com.liferay.portal.kernel.search.Document)13 ArrayList (java.util.ArrayList)5 Artist (org.liferay.jukebox.model.Artist)5 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)4 KBArticle (com.liferay.knowledgebase.model.KBArticle)3 DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)3 Album (org.liferay.jukebox.model.Album)3 Song (org.liferay.jukebox.model.Song)3 KBArticleActionableDynamicQuery (com.liferay.knowledgebase.service.persistence.KBArticleActionableDynamicQuery)1 Property (com.liferay.portal.kernel.dao.orm.Property)1 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)1 SearchResult (com.liferay.portal.kernel.search.SearchResult)1 Summary (com.liferay.portal.kernel.search.Summary)1 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)1 JournalArticle (com.liferay.portlet.journal.model.JournalArticle)1 MBMessage (com.liferay.portlet.messageboards.model.MBMessage)1 ArtistActionableDynamicQuery (org.liferay.jukebox.service.persistence.ArtistActionableDynamicQuery)1 SongActionableDynamicQuery (org.liferay.jukebox.service.persistence.SongActionableDynamicQuery)1