001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.search;
016    
017    import com.liferay.portlet.bookmarks.model.BookmarksFolder;
018    import com.liferay.portlet.documentlibrary.model.DLFolder;
019    import com.liferay.portlet.journal.model.JournalFolder;
020    
021    import java.util.Locale;
022    
023    import javax.portlet.PortletURL;
024    
025    /**
026     * @author Eduardo Garcia
027     */
028    public class FolderSearcher extends BaseIndexer {
029    
030            public static final String[] CLASS_NAMES = {
031                    BookmarksFolder.class.getName(), DLFolder.class.getName(),
032                    JournalFolder.class.getName()
033            };
034    
035            public static Indexer getInstance() {
036                    return new FolderSearcher();
037            }
038    
039            public FolderSearcher() {
040                    setFilterSearch(true);
041                    setPermissionAware(true);
042            }
043    
044            @Override
045            public String[] getClassNames() {
046                    return CLASS_NAMES;
047            }
048    
049            @Override
050            public IndexerPostProcessor[] getIndexerPostProcessors() {
051                    throw new UnsupportedOperationException();
052            }
053    
054            @Override
055            public String getPortletId() {
056                    return null;
057            }
058    
059            @Override
060            public void registerIndexerPostProcessor(
061                    IndexerPostProcessor indexerPostProcessor) {
062    
063                    throw new UnsupportedOperationException();
064            }
065    
066            @Override
067            protected BooleanQuery createFullQuery(
068                            BooleanQuery contextQuery, SearchContext searchContext)
069                    throws Exception {
070    
071                    long[] folderIds = searchContext.getFolderIds();
072    
073                    BooleanQuery entryClassPKQuery = BooleanQueryFactoryUtil.create(
074                            searchContext);
075    
076                    for (long folderId : folderIds) {
077                            entryClassPKQuery.addTerm(Field.ENTRY_CLASS_PK, folderId);
078                    }
079    
080                    contextQuery.add(entryClassPKQuery, BooleanClauseOccur.MUST);
081    
082                    return super.createFullQuery(contextQuery, searchContext);
083            }
084    
085            @Override
086            protected void doDelete(Object obj) throws Exception {
087                    throw new UnsupportedOperationException();
088            }
089    
090            @Override
091            protected Document doGetDocument(Object obj) throws Exception {
092                    throw new UnsupportedOperationException();
093            }
094    
095            @Override
096            protected Summary doGetSummary(
097                            Document document, Locale locale, String snippet,
098                            PortletURL portletURL)
099                    throws Exception {
100    
101                    throw new UnsupportedOperationException();
102            }
103    
104            @Override
105            protected void doReindex(Object obj) throws Exception {
106                    throw new UnsupportedOperationException();
107            }
108    
109            @Override
110            protected void doReindex(String className, long classPK) throws Exception {
111                    throw new UnsupportedOperationException();
112            }
113    
114            @Override
115            protected void doReindex(String[] ids) throws Exception {
116                    throw new UnsupportedOperationException();
117            }
118    
119            @Override
120            protected String getPortletId(SearchContext searchContext) {
121                    return null;
122            }
123    
124    }