--- /dev/null
+/**\r
+ * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to deal\r
+ * in the Software without restriction, including without limitation the rights\r
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ * copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+package com.liferay.portlet.blogs.util.service.impl;\r
+\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import com.liferay.portal.kernel.exception.SystemException;\r
+import com.liferay.portal.kernel.log.Log;\r
+import com.liferay.portal.kernel.log.LogFactoryUtil;\r
+import com.liferay.portal.kernel.search.BooleanClauseOccur;\r
+import com.liferay.portal.kernel.search.BooleanQuery;\r
+import com.liferay.portal.kernel.search.BooleanQueryFactoryUtil;\r
+import com.liferay.portal.kernel.search.Field;\r
+import com.liferay.portal.kernel.search.Hits;\r
+import com.liferay.portal.kernel.search.Indexer;\r
+import com.liferay.portal.kernel.search.IndexerRegistryUtil;\r
+import com.liferay.portal.kernel.search.SearchContext;\r
+import com.liferay.portal.kernel.search.SearchEngineUtil;\r
+import com.liferay.portal.kernel.search.SolrQueryUtil;\r
+import com.liferay.portal.model.User;\r
+import com.liferay.portal.service.UserLocalServiceUtil;\r
+import com.liferay.portlet.blogs.model.BlogsEntry;\r
+import com.liferay.portlet.blogs.service.impl.BlogsEntryLocalServiceImpl;\r
+import com.liferay.portlet.blogs.util.BlogsIndexer;\r
+import com.liferay.portlet.blogs.util.service.BlogsEntryLocalService;\r
+import com.pentila.entSavoie.ENTRolesConstants;\r
+import com.pentila.entSavoie.search.util.IndexerUtil;\r
+\r
+/**\r
+ * <a href="BlogsEntryLocalServiceImpl.java.html"><b><i>View Source</i></b>\r
+ * </a>\r
+ *\r
+ * @author Brian Wing Shun Chan\r
+ * @author Wilson S. Man\r
+ * @author Raymond Augé\r
+ *\r
+ */\r
+public class BlogsEntryLocalServiceImplOverride extends BlogsEntryLocalServiceImpl implements BlogsEntryLocalService {\r
+\r
+ private static Log logger = LogFactoryUtil.getLog(BlogsEntryLocalServiceImplOverride.class);\r
+\r
+ public Hits searchByDate(\r
+ long companyId, long groupId, long userId, long ownerUserId,\r
+ String keywords, int start, int end)\r
+ throws SystemException {\r
+ \r
+ try {\r
+ Indexer indexer = IndexerRegistryUtil.getIndexer(BlogsEntry.class);\r
+ String searchEngineId = indexer.getSearchEngineId();\r
+ \r
+ SearchContext searchContext = new SearchContext();\r
+ searchContext.setSearchEngineId(searchEngineId);\r
+ \r
+ User user = UserLocalServiceUtil.getUser(userId);\r
+ BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext); \r
+\r
+ contextQuery.addRequiredTerm(Field.PORTLET_ID, BlogsIndexer.PORTLET_ID);\r
+ \r
+ List<String> solrFilters = new ArrayList<String>();\r
+ \r
+ if (ownerUserId > 0) {\r
+ solrFilters.add(Field.USER_ID + ":" + ownerUserId);\r
+ }\r
+\r
+ if (groupId > 0) {\r
+ solrFilters.add(Field.GROUP_ID + ":" + groupId);\r
+ } else if (ENTRolesConstants.hasGlobalVisibilityOnGroupOnItsSchool(user)) {\r
+ String filterQuery = new String();\r
+ String listGroupId = IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.DONT_INCLUDE_USER_GROUP);\r
+ if (!listGroupId.equals("")) {\r
+ filterQuery += "(" + Field.GROUP_ID + ":" + IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.DONT_INCLUDE_USER_GROUP) + ") OR ";\r
+ }\r
+ filterQuery += "(" + Field.ETAB_ID + ":" + IndexerUtil.getEtabVisibility(user) + ")";\r
+ solrFilters.add(filterQuery);\r
+ } else {\r
+ String listGroupId = IndexerUtil.getSearchGroupsQuery(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, \r
+ IndexerUtil.INCLUDE_GLOBAL_ORG, IndexerUtil.DONT_INCLUDE_USER_GROUP);\r
+ solrFilters.add(Field.GROUP_ID + ":" + listGroupId);\r
+ }\r
+\r
+ if(!keywords.isEmpty()){\r
+ //Field.MODIFIED_DATE = "modified" only\r
+ solrFilters.add("modifiedDate" + ":" + keywords);\r
+ }\r
+ \r
+ BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);\r
+\r
+ fullQuery.add(contextQuery, BooleanClauseOccur.MUST);\r
+ \r
+ //userId a 0 car on gere nous meme les permissions\r
+ return SearchEngineUtil.search(\r
+ searchEngineId, companyId, fullQuery, solrFilters, start, end);\r
+ }\r
+ catch (Exception e) {\r
+ throw new SystemException(e);\r
+ }\r
+ }\r
+\r
+ public Hits search(\r
+ long companyId, long groupId, long userId, long ownerUserId,\r
+ String keywords, int start, int end)\r
+ throws SystemException {\r
+ \r
+ logger.info("Searching '"+keywords+"' in blogs/news ... ");\r
+ \r
+ try {\r
+ Indexer indexer = IndexerRegistryUtil.getIndexer(BlogsEntry.class);\r
+ String searchEngineId = indexer.getSearchEngineId();\r
+ \r
+ SearchContext searchContext = new SearchContext();\r
+ searchContext.setSearchEngineId(searchEngineId);\r
+ \r
+ User user = UserLocalServiceUtil.getUser(userId);\r
+ \r
+ BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext);\r
+\r
+ contextQuery.addRequiredTerm(Field.PORTLET_ID, BlogsIndexer.PORTLET_ID);\r
+ \r
+ List<String> solrFilters = new ArrayList<String>();\r
+ \r
+ if (ownerUserId > 0) {\r
+ solrFilters.add(Field.USER_ID + ":" + ownerUserId);\r
+ }\r
+\r
+ if (groupId > 0) {\r
+ solrFilters.add(Field.GROUP_ID + ":" + groupId);\r
+ } else if (ENTRolesConstants.hasGlobalVisibilityOnGroupOnItsSchool(user)) {\r
+ String filterQuery = new String();\r
+ String listGroupId = IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.DONT_INCLUDE_USER_GROUP);\r
+ if (!listGroupId.equals("")) {\r
+ filterQuery += "(" + Field.GROUP_ID + ":" + IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.DONT_INCLUDE_USER_GROUP) + ") OR ";\r
+ }\r
+ filterQuery += "(" + Field.ETAB_ID + ":" + IndexerUtil.getEtabVisibility(user) + ")";\r
+ solrFilters.add(filterQuery);\r
+ } else {\r
+ String listGroupId = IndexerUtil.getSearchGroupsQuery(user,\r
+ IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.INCLUDE_GLOBAL_ORG, IndexerUtil.DONT_INCLUDE_USER_GROUP);\r
+ solrFilters.add(Field.GROUP_ID + ":" + listGroupId);\r
+ }\r
+ \r
+ // Manage search tolerance\r
+ String query = SolrQueryUtil.getQueryFromKeywords(keywords, true);\r
+ String queryWithoutFuzzySearch = SolrQueryUtil.getQueryFromKeywords(keywords, false);\r
+ \r
+ solrFilters.add("(" + Field.TITLE + ":" + query + ") "\r
+ + "OR (" + Field.CONTENT + ":" + queryWithoutFuzzySearch + ")");\r
+\r
+ BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);\r
+ fullQuery.add(contextQuery, BooleanClauseOccur.MUST);\r
+\r
+ //userId a 0 car on gere nous meme les permissions\r
+ return SearchEngineUtil.search(\r
+ searchEngineId, companyId, fullQuery, solrFilters, start, end);\r
+ }\r
+ catch (Exception e) {\r
+ throw new SystemException(e);\r
+ }\r
+ }\r
+\r
+}
\ No newline at end of file