List of usage examples for com.liferay.portal.kernel.search BooleanQuery addTerm
public Query addTerm(String field, String value) throws ParseException;
From source file:com.library.slayer.service.impl.LMSBookLocalServiceImpl.java
License:Open Source License
/** * @param fieldName//from w w w .j a v a 2s . c om * @param value * @param searchContext * @param fullQuery * @return */ private BooleanQuery createQuery(String fieldName, String value, SearchContext searchContext, BooleanQuery fullQuery) { BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext); String[] splitValue = value.split(","); for (String splitVal : splitValue) { try { searchQuery.addTerm(fieldName, splitVal.replace(" ", ",")); } catch (ParseException e) { } } try { fullQuery.add(searchQuery, BooleanClauseOccur.MUST); } catch (ParseException e) { } return fullQuery; }
From source file:com.library.slayer.service.impl.LMSBookLocalServiceImpl.java
License:Open Source License
public Hits search(long companyId, String keywords) { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); searchContext.setEntryClassNames(CLASS_NAMES); BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext); Hits hits = null;/* ww w.ja v a 2 s . co m*/ try { searchQuery.addTerm(Field.TITLE, keywords); hits = SearchEngineUtil.search(searchContext, searchQuery); } catch (SearchException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return hits; }
From source file:com.liferay.journal.search.test.JournalArticleSearchTest.java
License:Open Source License
@Test public void testMatchNotOnlyCompanyIdButAlsoQueryTerms() throws Exception { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(TestPropsValues.getCompanyId()); BooleanQuery query = new BooleanQueryImpl(); query.addTerm("title", RandomTestUtil.randomString()); assertEquals(0, query, searchContext); }
From source file:com.liferay.portlet.bookmarks.util.BookmarksIndexer.java
License:Open Source License
@Override public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception { long[] folderIds = searchContext.getFolderIds(); if ((folderIds != null) && (folderIds.length > 0)) { if (folderIds[0] == BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) { return; }/* www .j a v a 2s. c om*/ BooleanQuery folderIdsQuery = BooleanQueryFactoryUtil.create(searchContext); for (long folderId : folderIds) { try { BookmarksFolderServiceUtil.getFolder(folderId); } catch (Exception e) { continue; } folderIdsQuery.addTerm(Field.FOLDER_ID, folderId); } contextQuery.add(folderIdsQuery, BooleanClauseOccur.MUST); } }
From source file:com.liferay.portlet.documentlibrary.util.DLFileEntryIndexer.java
License:Open Source License
@Override public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception { addStatus(contextQuery, searchContext); if (searchContext.isIncludeAttachments()) { addRelatedClassNames(contextQuery, searchContext); }/*w w w . j a v a 2 s . c o m*/ contextQuery.addRequiredTerm(Field.HIDDEN, searchContext.isIncludeAttachments()); addSearchClassTypeIds(contextQuery, searchContext); String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName"); Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue"); if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) { String[] ddmStructureFieldNameParts = StringUtil.split(ddmStructureFieldName, StringPool.SLASH); DDMStructure structure = DDMStructureLocalServiceUtil .getStructure(GetterUtil.getLong(ddmStructureFieldNameParts[1])); String fieldName = StringUtil.replaceLast(ddmStructureFieldNameParts[2], StringPool.UNDERLINE.concat(LocaleUtil.toLanguageId(searchContext.getLocale())), StringPool.BLANK); try { ddmStructureFieldValue = DDMUtil.getIndexedFieldValue(ddmStructureFieldValue, structure.getFieldType(fieldName)); } catch (StructureFieldException sfe) { } contextQuery.addRequiredTerm(ddmStructureFieldName, StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE); } String[] mimeTypes = (String[]) searchContext.getAttribute("mimeTypes"); if (ArrayUtil.isNotEmpty(mimeTypes)) { BooleanQuery mimeTypesQuery = BooleanQueryFactoryUtil.create(searchContext); for (String mimeType : mimeTypes) { mimeTypesQuery.addTerm("mimeType", StringUtil.replace(mimeType, CharPool.FORWARD_SLASH, CharPool.UNDERLINE)); } contextQuery.add(mimeTypesQuery, BooleanClauseOccur.MUST); } }
From source file:com.liferay.portlet.documentlibrary.util.DLIndexer.java
License:Open Source License
@Override public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception { int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_APPROVED); if (status != WorkflowConstants.STATUS_ANY) { contextQuery.addRequiredTerm(Field.STATUS, status); }//from w w w . j av a 2 s . c o m long[] folderIds = searchContext.getFolderIds(); if ((folderIds != null) && (folderIds.length > 0)) { if (folderIds[0] == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { return; } BooleanQuery folderIdsQuery = BooleanQueryFactoryUtil.create(searchContext); for (long folderId : folderIds) { try { DLFolderServiceUtil.getFolder(folderId); } catch (Exception e) { continue; } folderIdsQuery.addTerm(Field.FOLDER_ID, folderId); } contextQuery.add(folderIdsQuery, BooleanClauseOccur.MUST); } }
From source file:com.liferay.portlet.messageboards.util.MBIndexer.java
License:Open Source License
@Override public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception { int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_ANY); if (status != WorkflowConstants.STATUS_ANY) { contextQuery.addRequiredTerm(Field.STATUS, status); }/*from w ww. j av a 2s. co m*/ boolean discussion = GetterUtil.getBoolean(searchContext.getAttribute("discussion"), false); contextQuery.addRequiredTerm("discussion", discussion); long threadId = GetterUtil.getLong((String) searchContext.getAttribute("threadId")); if (threadId > 0) { contextQuery.addRequiredTerm("threadId", threadId); } long[] categoryIds = searchContext.getCategoryIds(); if ((categoryIds != null) && (categoryIds.length > 0)) { if (categoryIds[0] == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) { return; } BooleanQuery categoriesQuery = BooleanQueryFactoryUtil.create(searchContext); for (long categoryId : categoryIds) { try { MBCategoryServiceUtil.getCategory(categoryId); } catch (Exception e) { continue; } categoriesQuery.addTerm(Field.CATEGORY_ID, categoryId); } contextQuery.add(categoriesQuery, BooleanClauseOccur.MUST); } }
From source file:com.liferay.portlet.tags.service.impl.TagsAssetLocalServiceImpl.java
License:Open Source License
public Hits search(long companyId, String portletId, String keywords, int start, int end) throws SystemException { try {// ww w . j av a 2s.c o m BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(); if (Validator.isNotNull(portletId)) { contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId); } else { BooleanQuery portletIdsQuery = BooleanQueryFactoryUtil.create(); for (String assetTypePortletId : TagsUtil.ASSET_TYPE_PORTLET_IDS) { TermQuery termQuery = TermQueryFactoryUtil.create(Field.PORTLET_ID, assetTypePortletId); portletIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD); } contextQuery.add(portletIdsQuery, BooleanClauseOccur.MUST); } BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(); if (Validator.isNotNull(keywords)) { searchQuery.addTerm(Field.TITLE, keywords); searchQuery.addTerm(Field.CONTENT, keywords); searchQuery.addTerm(Field.DESCRIPTION, keywords); searchQuery.addTerm(Field.PROPERTIES, keywords); searchQuery.addTerm(Field.TAGS_ENTRIES, keywords); } BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(); fullQuery.add(contextQuery, BooleanClauseOccur.MUST); if (searchQuery.clauses().size() > 0) { fullQuery.add(searchQuery, BooleanClauseOccur.MUST); } return SearchEngineUtil.search(companyId, fullQuery, start, end); } catch (Exception e) { throw new SystemException(e); } }
From source file:com.liferay.portlet.usersadmin.util.UserIndexer.java
License:Open Source License
protected void addContextQueryParams(BooleanQuery contextQuery, SearchContext searchContext, String key, Object value) throws Exception { if (key.equals("usersOrgs")) { if (value instanceof Long[]) { Long[] values = (Long[]) value; BooleanQuery usersOrgsQuery = BooleanQueryFactoryUtil.create(searchContext); for (long organizationId : values) { usersOrgsQuery.addTerm("organizationIds", organizationId); usersOrgsQuery.addTerm("ancestorOrganizationIds", organizationId); }/* w ww . ja v a 2s .c om*/ contextQuery.add(usersOrgsQuery, BooleanClauseOccur.MUST); } else { contextQuery.addRequiredTerm("organizationIds", String.valueOf(value)); } } else if (key.equals("usersOrgsCount")) { contextQuery.addRequiredTerm("organizationCount", String.valueOf(value)); } else if (key.equals("usersRoles")) { contextQuery.addRequiredTerm("roleIds", String.valueOf(value)); } else if (key.equals("usersTeams")) { contextQuery.addRequiredTerm("teamIds", String.valueOf(value)); } else if (key.equals("usersUserGroups")) { contextQuery.addRequiredTerm("userGroupIds", String.valueOf(value)); } }
From source file:com.liferay.portlet.wiki.util.WikiIndexer.java
License:Open Source License
@Override public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception { int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_ANY); if (status != WorkflowConstants.STATUS_ANY) { contextQuery.addRequiredTerm(Field.STATUS, status); }/*from w w w . j av a2 s. c o m*/ long[] nodeIds = searchContext.getNodeIds(); if ((nodeIds != null) && (nodeIds.length > 0)) { BooleanQuery nodeIdsQuery = BooleanQueryFactoryUtil.create(searchContext); for (long nodeId : nodeIds) { try { WikiNodeServiceUtil.getNode(nodeId); } catch (Exception e) { continue; } nodeIdsQuery.addTerm(Field.NODE_ID, nodeId); } contextQuery.add(nodeIdsQuery, BooleanClauseOccur.MUST); } }