List of usage examples for com.liferay.portal.kernel.search BooleanQuery addTerms
public Map<String, Query> addTerms(String[] fields, String values) throws ParseException;
From source file:com.idetronic.eprint.service.impl.EprintLocalServiceImpl.java
License:Open Source License
public Hits getHits(String keyword, long companyId, long groupId) { // 1. Preparing a Search Context SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); String[] CLASS_NAMES = { Eprint.class.getName() }; searchContext.setEntryClassNames(CLASS_NAMES); long[] groupIds = { groupId }; searchContext.setGroupIds(groupIds); // 2. Preparing a Query to search BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext); String[] terms = { Field.DESCRIPTION, Field.TITLE }; try {/*w ww .java2s . c o m*/ searchQuery.addTerms(terms, keyword); } catch (ParseException e) { e.printStackTrace(); } // 3. Firing the query to get hits Hits hits = null; try { hits = SearchEngineUtil.search(searchContext, searchQuery); } catch (SearchException e) { e.printStackTrace(); } return hits; }
From source file:com.library.slayer.service.impl.LMSBookLocalServiceImpl.java
License:Open Source License
public List<LMSBook> AdvanceSearchAny(long companyId, long groupId, String title, String author, String desc) { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); searchContext.setEntryClassNames(CLASS_NAMES); BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext); Hits hits = null;/*from www. jav a2 s. c o m*/ try { String[] terms = { Field.TITLE, Field.DESCRIPTION, Field.NAME }; searchQuery.addTerms(terms, getModelClassName()); searchQuery = createQuery(getModelClassName(), getModelClassName(), searchContext, searchQuery); 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(); } List<LMSBook> books = null; if (hits != null && hits.getLength() > 0) { books = new ArrayList<LMSBook>(); for (Document document : hits.getDocs()) { long bookId = Long.parseLong(document.get(Field.ENTRY_CLASS_PK)); try { LMSBook book = LMSBookLocalServiceUtil.getLMSBook(bookId); books.add(book); } catch (PortalException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return books; }
From source file:com.library.slayer.service.impl.LMSBookLocalServiceImpl.java
License:Open Source License
public List<LMSBook> searchBooks(long companyId, String keywords) { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); searchContext.setEntryClassNames(CLASS_NAMES); BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext); Hits hits = null;//from w w w .ja v a 2 s . c om try { String[] terms = { Field.TITLE, Field.DESCRIPTION }; searchQuery.addTerms(terms, 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(); } List<LMSBook> books = null; if (hits != null && hits.getLength() > 0) { books = new ArrayList<LMSBook>(); for (Document document : hits.getDocs()) { long bookId = Long.parseLong(document.get(Field.ENTRY_CLASS_PK)); try { LMSBook book = LMSBookLocalServiceUtil.getLMSBook(bookId); books.add(book); } catch (PortalException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return books; }
From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java
License:Open Source License
public Hits search(long companyId, long userId, String portletId, long groupId, long[] repositoryIds, String keywords, int start, int end) throws SystemException { try {//w ww .j a v a 2 s . com SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); searchContext.setEnd(end); searchContext.setEntryClassNames(new String[] { DLFileEntryConstants.getClassName() }); searchContext.setGroupIds(new long[] { groupId }); Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName()); searchContext.setSearchEngineId(indexer.getSearchEngineId()); searchContext.setStart(start); searchContext.setUserId(userId); BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext); contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId); if (groupId > 0) { Group group = groupLocalService.getGroup(groupId); if (group.isLayout()) { contextQuery.addRequiredTerm(Field.SCOPE_GROUP_ID, groupId); groupId = group.getParentGroupId(); } contextQuery.addRequiredTerm(Field.GROUP_ID, groupId); } if ((repositoryIds != null) && (repositoryIds.length > 0)) { BooleanQuery repositoryIdsQuery = BooleanQueryFactoryUtil.create(searchContext); for (long repositoryId : repositoryIds) { try { if (userId > 0) { PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker(); DLFolderPermission.check(permissionChecker, groupId, repositoryId, ActionKeys.VIEW); } if (repositoryId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { repositoryId = groupId; } TermQuery termQuery = TermQueryFactoryUtil.create(searchContext, "repositoryId", repositoryId); repositoryIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD); } catch (Exception e) { } } contextQuery.add(repositoryIdsQuery, BooleanClauseOccur.MUST); } BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext); searchQuery.addTerms(_KEYWORDS_FIELDS, keywords); BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext); fullQuery.add(contextQuery, BooleanClauseOccur.MUST); if (searchQuery.clauses().size() > 0) { fullQuery.add(searchQuery, BooleanClauseOccur.MUST); } return SearchEngineUtil.search(searchContext, fullQuery); } catch (Exception e) { throw new SystemException(e); } }
From source file:com.slayer.service.impl.LMSBookLocalServiceImpl.java
License:Open Source License
public Hits getHits(String keyword, long companyId, long groupId) { // 1. Preparing a Search Context SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); String[] CLASS_NAMES = { LMSBook.class.getName() }; searchContext.setEntryClassNames(CLASS_NAMES); long[] groupIds = { groupId }; searchContext.setGroupIds(groupIds); // 2. Preparing a Query to search BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext); String[] terms = { Field.TITLE, "author" }; try {// ww w . jav a2s .c o m searchQuery.addTerms(terms, keyword); } catch (ParseException e) { e.printStackTrace(); } // 3. Firing the query to get hits Hits hits = null; try { hits = SearchEngineUtil.search(searchContext, searchQuery); } catch (SearchException e) { e.printStackTrace(); } return hits; }