001    /**
002     * Copyright (c) 2000-2010 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.portlet.assetpublisher.util;
016    
017    import com.liferay.portal.kernel.search.BaseIndexer;
018    import com.liferay.portal.kernel.search.BooleanQuery;
019    import com.liferay.portal.kernel.search.Document;
020    import com.liferay.portal.kernel.search.Field;
021    import com.liferay.portal.kernel.search.SearchContext;
022    import com.liferay.portal.kernel.search.Summary;
023    import com.liferay.portal.kernel.util.Validator;
024    import com.liferay.portal.util.PortletKeys;
025    import com.liferay.portlet.asset.model.AssetEntry;
026    
027    import javax.portlet.PortletURL;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     * @author Julio Camarero
032     */
033    public class AssetIndexer extends BaseIndexer {
034    
035            public static final String[] CLASS_NAMES = {AssetEntry.class.getName()};
036    
037            public static final String PORTLET_ID = PortletKeys.ASSET_PUBLISHER;
038    
039            public String[] getClassNames() {
040                    return CLASS_NAMES;
041            }
042    
043            public Summary getSummary(
044                    Document document, String snippet, PortletURL portletURL) {
045    
046                    return null;
047            }
048    
049            protected void doDelete(Object obj) {
050            }
051    
052            protected Document doGetDocument(Object obj) {
053                    return null;
054            }
055    
056            protected void doReindex(Object obj) {
057            }
058    
059            protected void doReindex(String className, long classPK) {
060            }
061    
062            protected void doReindex(String[] ids) {
063            }
064    
065            protected String getPortletId(SearchContext searchContext) {
066                    return PORTLET_ID;
067            }
068    
069            protected void postProcessSearchQuery(
070                            BooleanQuery searchQuery, SearchContext searchContext)
071                    throws Exception {
072    
073                    if (searchContext.getAttributes() == null) {
074                            return;
075                    }
076    
077                    String description = (String)searchContext.getAttribute(
078                            Field.DESCRIPTION);
079    
080                    if (Validator.isNotNull(description)) {
081                            if (searchContext.isAndSearch()) {
082                                    searchQuery.addRequiredTerm(
083                                            Field.DESCRIPTION, description, true);
084                            }
085                            else {
086                                    searchQuery.addTerm(Field.DESCRIPTION, description, true);
087                            }
088                    }
089    
090                    String title = (String)searchContext.getAttribute(Field.TITLE);
091    
092                    if (Validator.isNotNull(title)) {
093                            if (searchContext.isAndSearch()) {
094                                    searchQuery.addRequiredTerm(Field.TITLE, title, true);
095                            }
096                            else {
097                                    searchQuery.addTerm(Field.TITLE, title, true);
098                            }
099                    }
100    
101                    String userName = (String)searchContext.getAttribute(Field.USER_NAME);
102    
103                    if (Validator.isNotNull(userName)) {
104                            if (searchContext.isAndSearch()) {
105                                    searchQuery.addRequiredTerm(Field.USER_NAME, userName, true);
106                            }
107                            else {
108                                    searchQuery.addTerm(Field.USER_NAME, userName, true);
109                            }
110                    }
111            }
112    
113    }