2 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
\r
4 * This library is free software; you can redistribute it and/or modify it under
\r
5 * the terms of the GNU Lesser General Public License as published by the Free
\r
6 * Software Foundation; either version 2.1 of the License, or (at your option)
\r
9 * This library is distributed in the hope that it will be useful, but WITHOUT
\r
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
\r
15 package com.liferay.portlet.documentlibrary.store;
\r
17 import java.util.ArrayList;
\r
18 import java.util.List;
\r
20 import com.liferay.portal.kernel.exception.SystemException;
\r
21 import com.liferay.portal.kernel.log.Log;
\r
22 import com.liferay.portal.kernel.log.LogFactoryUtil;
\r
23 import com.liferay.portal.kernel.search.BooleanClauseOccur;
\r
24 import com.liferay.portal.kernel.search.BooleanQuery;
\r
25 import com.liferay.portal.kernel.search.BooleanQueryFactoryUtil;
\r
26 import com.liferay.portal.kernel.search.Field;
\r
27 import com.liferay.portal.kernel.search.Hits;
\r
28 import com.liferay.portal.kernel.search.Indexer;
\r
29 import com.liferay.portal.kernel.search.IndexerRegistryUtil;
\r
30 import com.liferay.portal.kernel.search.SearchContext;
\r
31 import com.liferay.portal.kernel.search.SearchEngineUtil;
\r
32 import com.liferay.portal.kernel.search.SolrQueryUtil;
\r
33 import com.liferay.portal.kernel.search.TermQuery;
\r
34 import com.liferay.portal.kernel.search.TermQueryFactoryUtil;
\r
35 import com.liferay.portal.model.User;
\r
36 import com.liferay.portal.service.UserLocalServiceUtil;
\r
37 import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants;
\r
38 import com.liferay.portlet.documentlibrary.service.DLFolderServiceUtil;
\r
39 import com.pentila.entSavoie.ENTRolesConstants;
\r
40 import com.pentila.entSavoie.search.util.IndexerUtil;
\r
43 * @author Brian Wing Shun Chan
\r
44 * @author Alexander Chow
\r
45 * @author Edward Han
\r
47 public class CustomDLStoreImpl extends DLStoreImpl implements CustomDLStore {
\r
49 private static Log logger = LogFactoryUtil.getLog(CustomDLStoreImpl.class);
\r
52 long companyId, long userId, String portletId, long groupId,
\r
53 long[] repositoryIds, String keywords, int start, int end)
\r
54 throws SystemException {
\r
56 logger.info("Searching '"+keywords+"' in documents (files) ...");
\r
59 SearchContext searchContext = new SearchContext();
\r
61 searchContext.setCompanyId(companyId);
\r
62 searchContext.setEnd(end);
\r
63 searchContext.setEntryClassNames(
\r
64 new String[] {DLFileEntryConstants.getClassName()});
\r
65 searchContext.setGroupIds(new long[] {groupId});
\r
67 Indexer indexer = IndexerRegistryUtil.getIndexer(
\r
68 DLFileEntryConstants.getClassName());
\r
70 searchContext.setSearchEngineId(indexer.getSearchEngineId());
\r
72 searchContext.setStart(start);
\r
73 searchContext.setUserId(userId);
\r
75 BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(
\r
78 contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId);
\r
80 List<String> solrFilters = new ArrayList<String>();
\r
82 User user = UserLocalServiceUtil.getUser(userId);
\r
85 solrFilters.add(Field.GROUP_ID + ":" + groupId);
\r
86 } else if (ENTRolesConstants.hasGlobalVisibilityOnGroupOnItsSchool(user)) {
\r
87 solrFilters.add("(" + Field.GROUP_ID + ":" + IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.INCLUDE_USER_GROUP) + ") "
\r
88 + "OR (" + Field.ETAB_ID + ":" + IndexerUtil.getEtabVisibility(user) + ")");
\r
90 String listGroupId = IndexerUtil.getSearchGroupsQuery(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY,
\r
91 IndexerUtil.INCLUDE_GLOBAL_ORG, IndexerUtil.INCLUDE_USER_GROUP);
\r
92 solrFilters.add(Field.GROUP_ID + ":" + listGroupId);
\r
96 if ((repositoryIds != null) && (repositoryIds.length > 0)) {
\r
97 BooleanQuery repositoryIdsQuery =
\r
98 BooleanQueryFactoryUtil.create(searchContext);
\r
100 boolean repositoryIdsQueryValid = false;
\r
102 for (long repositoryId : repositoryIds) {
\r
103 if(repositoryId > 0){
\r
107 DLFolderServiceUtil.getFolder(repositoryId);
\r
108 repositoryIdsQueryValid = true;
\r
110 catch (Exception e) {
\r
115 TermQuery termQuery = TermQueryFactoryUtil.create(
\r
116 searchContext, "repositoryId", repositoryId);
\r
118 repositoryIdsQuery.add(
\r
119 termQuery, BooleanClauseOccur.SHOULD);
\r
121 catch (Exception e) {
\r
126 if(repositoryIdsQueryValid){
\r
127 contextQuery.add(repositoryIdsQuery, BooleanClauseOccur.MUST);
\r
131 String query = SolrQueryUtil.getQueryFromKeywords(keywords, true);
\r
132 String queryWithoutFuzzySearch = SolrQueryUtil.getQueryFromKeywords(keywords, false);
\r
134 solrFilters.add("(" + Field.TITLE + ":" + query + ") "
\r
135 + "OR (" + Field.CONTENT + ":" + queryWithoutFuzzySearch + ") "
\r
136 + "OR (" + Field.PROPERTIES + ":" + queryWithoutFuzzySearch + ") "
\r
137 + "OR (" + Field.ASSET_TAG_NAMES + ":" + query + ") "
\r
138 + "OR (" + Field.KEYWORD_LIST + ":" + queryWithoutFuzzySearch+ ") "
\r
139 + "OR (" + Field.TAG_LIST + ":" + queryWithoutFuzzySearch + ") "
\r
140 + "OR (" + Field.LINK_LIST + ":" + queryWithoutFuzzySearch + ")");
\r
142 BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
\r
144 fullQuery.add(contextQuery, BooleanClauseOccur.MUST);
\r
146 //userId a 0 car on gere nous meme les permissions
\r
147 return SearchEngineUtil.search(
\r
148 indexer.getSearchEngineId(), companyId, fullQuery, solrFilters, start, end);
\r
150 catch (Exception e) {
\r
151 throw new SystemException(e);
\r
155 public Hits searchByDate(
\r
156 long companyId, String portletId, long groupId,
\r
157 long userId, long[] repositoryIds, String keywords, int start,
\r
158 int end) throws SystemException {
\r
161 SearchContext searchContext = new SearchContext();
\r
163 searchContext.setCompanyId(companyId);
\r
164 searchContext.setEnd(end);
\r
165 searchContext.setEntryClassNames(
\r
166 new String[] {DLFileEntryConstants.getClassName()});
\r
167 searchContext.setGroupIds(new long[] {groupId});
\r
169 Indexer indexer = IndexerRegistryUtil.getIndexer(
\r
170 DLFileEntryConstants.getClassName());
\r
172 searchContext.setSearchEngineId(indexer.getSearchEngineId());
\r
174 searchContext.setStart(start);
\r
175 searchContext.setUserId(userId);
\r
177 BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(
\r
180 contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId);
\r
182 List<String> solrFilters = new ArrayList<String>();
\r
184 User user = UserLocalServiceUtil.getUser(userId);
\r
187 solrFilters.add(Field.GROUP_ID + ":" + groupId);
\r
188 } else if (ENTRolesConstants.hasGlobalVisibilityOnGroupOnItsSchool(user)) {
\r
189 solrFilters.add("(" + Field.GROUP_ID + ":" + IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.INCLUDE_USER_GROUP) + ") "
\r
190 + "OR (" + Field.ETAB_ID + ":" + IndexerUtil.getEtabVisibility(user) + ")");
\r
192 String listGroupId = IndexerUtil.getSearchGroupsQuery(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY,
\r
193 IndexerUtil.INCLUDE_GLOBAL_ORG, IndexerUtil.INCLUDE_USER_GROUP);
\r
194 solrFilters.add(Field.GROUP_ID + ":" + listGroupId);
\r
198 if ((repositoryIds != null) && (repositoryIds.length > 0)) {
\r
199 BooleanQuery repositoryIdsQuery =
\r
200 BooleanQueryFactoryUtil.create(searchContext);
\r
202 for (long repositoryId : repositoryIds) {
\r
206 DLFolderServiceUtil.getFolder(repositoryId);
\r
208 catch (Exception e) {
\r
213 TermQuery termQuery = TermQueryFactoryUtil.create(
\r
214 searchContext, "repositoryId", repositoryId);
\r
216 repositoryIdsQuery.add(
\r
217 termQuery, BooleanClauseOccur.SHOULD);
\r
219 catch (Exception e) {
\r
223 contextQuery.add(repositoryIdsQuery, BooleanClauseOccur.MUST);
\r
226 if (!keywords.isEmpty()) {
\r
227 //Field.MODIFIED_DATE = "modified" only
\r
228 solrFilters.add("modifiedDate" + ":" + keywords);
\r
231 BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
\r
233 fullQuery.add(contextQuery, BooleanClauseOccur.MUST);
\r
235 //userId a 0 car on gere nous meme les permissions
\r
236 return SearchEngineUtil.search(
\r
237 indexer.getSearchEngineId(), companyId, fullQuery, solrFilters, start, end);
\r
239 catch (Exception e) {
\r
240 throw new SystemException(e);
\r