2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
5 * of this software and associated documentation files (the "Software"), to deal
\r
6 * in the Software without restriction, including without limitation the rights
\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
8 * copies of the Software, and to permit persons to whom the Software is
\r
9 * furnished to do so, subject to the following conditions:
\r
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
\r
23 package com.liferay.portlet.blogs.util.service.impl;
\r
26 import java.util.ArrayList;
\r
27 import java.util.List;
\r
29 import com.liferay.portal.kernel.exception.SystemException;
\r
30 import com.liferay.portal.kernel.log.Log;
\r
31 import com.liferay.portal.kernel.log.LogFactoryUtil;
\r
32 import com.liferay.portal.kernel.search.BooleanClauseOccur;
\r
33 import com.liferay.portal.kernel.search.BooleanQuery;
\r
34 import com.liferay.portal.kernel.search.BooleanQueryFactoryUtil;
\r
35 import com.liferay.portal.kernel.search.Field;
\r
36 import com.liferay.portal.kernel.search.Hits;
\r
37 import com.liferay.portal.kernel.search.Indexer;
\r
38 import com.liferay.portal.kernel.search.IndexerRegistryUtil;
\r
39 import com.liferay.portal.kernel.search.SearchContext;
\r
40 import com.liferay.portal.kernel.search.SearchEngineUtil;
\r
41 import com.liferay.portal.kernel.search.SolrQueryUtil;
\r
42 import com.liferay.portal.model.User;
\r
43 import com.liferay.portal.service.UserLocalServiceUtil;
\r
44 import com.liferay.portlet.blogs.model.BlogsEntry;
\r
45 import com.liferay.portlet.blogs.service.impl.BlogsEntryLocalServiceImpl;
\r
46 import com.liferay.portlet.blogs.util.BlogsIndexer;
\r
47 import com.liferay.portlet.blogs.util.service.BlogsEntryLocalService;
\r
48 import com.pentila.entSavoie.ENTRolesConstants;
\r
49 import com.pentila.entSavoie.search.util.IndexerUtil;
\r
52 * <a href="BlogsEntryLocalServiceImpl.java.html"><b><i>View Source</i></b>
\r
55 * @author Brian Wing Shun Chan
\r
56 * @author Wilson S. Man
\r
57 * @author Raymond Augé
\r
60 public class BlogsEntryLocalServiceImplOverride extends BlogsEntryLocalServiceImpl implements BlogsEntryLocalService {
\r
62 private static Log logger = LogFactoryUtil.getLog(BlogsEntryLocalServiceImplOverride.class);
\r
64 public Hits searchByDate(
\r
65 long companyId, long groupId, long userId, long ownerUserId,
\r
66 String keywords, int start, int end)
\r
67 throws SystemException {
\r
70 Indexer indexer = IndexerRegistryUtil.getIndexer(BlogsEntry.class);
\r
71 String searchEngineId = indexer.getSearchEngineId();
\r
73 SearchContext searchContext = new SearchContext();
\r
74 searchContext.setSearchEngineId(searchEngineId);
\r
76 User user = UserLocalServiceUtil.getUser(userId);
\r
77 BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext);
\r
79 contextQuery.addRequiredTerm(Field.PORTLET_ID, BlogsIndexer.PORTLET_ID);
\r
81 List<String> solrFilters = new ArrayList<String>();
\r
83 if (ownerUserId > 0) {
\r
84 solrFilters.add(Field.USER_ID + ":" + ownerUserId);
\r
88 solrFilters.add(Field.GROUP_ID + ":" + groupId);
\r
89 } else if (ENTRolesConstants.hasGlobalVisibilityOnGroupOnItsSchool(user)) {
\r
90 String filterQuery = new String();
\r
91 String listGroupId = IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.DONT_INCLUDE_USER_GROUP);
\r
92 if (!listGroupId.equals("")) {
\r
93 filterQuery += "(" + Field.GROUP_ID + ":" + IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.DONT_INCLUDE_USER_GROUP) + ") OR ";
\r
95 filterQuery += "(" + Field.ETAB_ID + ":" + IndexerUtil.getEtabVisibility(user) + ")";
\r
96 solrFilters.add(filterQuery);
\r
98 String listGroupId = IndexerUtil.getSearchGroupsQuery(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY,
\r
99 IndexerUtil.INCLUDE_GLOBAL_ORG, IndexerUtil.DONT_INCLUDE_USER_GROUP);
\r
100 solrFilters.add(Field.GROUP_ID + ":" + listGroupId);
\r
103 if(!keywords.isEmpty()){
\r
104 //Field.MODIFIED_DATE = "modified" only
\r
105 solrFilters.add("modifiedDate" + ":" + keywords);
\r
108 BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
\r
110 fullQuery.add(contextQuery, BooleanClauseOccur.MUST);
\r
112 //userId a 0 car on gere nous meme les permissions
\r
113 return SearchEngineUtil.search(
\r
114 searchEngineId, companyId, fullQuery, solrFilters, start, end);
\r
116 catch (Exception e) {
\r
117 throw new SystemException(e);
\r
121 public Hits search(
\r
122 long companyId, long groupId, long userId, long ownerUserId,
\r
123 String keywords, int start, int end)
\r
124 throws SystemException {
\r
126 logger.info("Searching '"+keywords+"' in blogs/news ... ");
\r
129 Indexer indexer = IndexerRegistryUtil.getIndexer(BlogsEntry.class);
\r
130 String searchEngineId = indexer.getSearchEngineId();
\r
132 SearchContext searchContext = new SearchContext();
\r
133 searchContext.setSearchEngineId(searchEngineId);
\r
135 User user = UserLocalServiceUtil.getUser(userId);
\r
137 BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext);
\r
139 contextQuery.addRequiredTerm(Field.PORTLET_ID, BlogsIndexer.PORTLET_ID);
\r
141 List<String> solrFilters = new ArrayList<String>();
\r
143 if (ownerUserId > 0) {
\r
144 solrFilters.add(Field.USER_ID + ":" + ownerUserId);
\r
148 solrFilters.add(Field.GROUP_ID + ":" + groupId);
\r
149 } else if (ENTRolesConstants.hasGlobalVisibilityOnGroupOnItsSchool(user)) {
\r
150 String filterQuery = new String();
\r
151 String listGroupId = IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.DONT_INCLUDE_USER_GROUP);
\r
152 if (!listGroupId.equals("")) {
\r
153 filterQuery += "(" + Field.GROUP_ID + ":" + IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.DONT_INCLUDE_USER_GROUP) + ") OR ";
\r
155 filterQuery += "(" + Field.ETAB_ID + ":" + IndexerUtil.getEtabVisibility(user) + ")";
\r
156 solrFilters.add(filterQuery);
\r
158 String listGroupId = IndexerUtil.getSearchGroupsQuery(user,
\r
159 IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.INCLUDE_GLOBAL_ORG, IndexerUtil.DONT_INCLUDE_USER_GROUP);
\r
160 solrFilters.add(Field.GROUP_ID + ":" + listGroupId);
\r
163 // Manage search tolerance
\r
164 String query = SolrQueryUtil.getQueryFromKeywords(keywords, true);
\r
165 String queryWithoutFuzzySearch = SolrQueryUtil.getQueryFromKeywords(keywords, false);
\r
167 solrFilters.add("(" + Field.TITLE + ":" + query + ") "
\r
168 + "OR (" + Field.CONTENT + ":" + queryWithoutFuzzySearch + ")");
\r
170 BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
\r
171 fullQuery.add(contextQuery, BooleanClauseOccur.MUST);
\r
173 //userId a 0 car on gere nous meme les permissions
\r
174 return SearchEngineUtil.search(
\r
175 searchEngineId, companyId, fullQuery, solrFilters, start, end);
\r
177 catch (Exception e) {
\r
178 throw new SystemException(e);
\r