List of usage examples for com.liferay.portal.kernel.search SearchContext setEntryClassNames
public void setEntryClassNames(String[] entryClassNames)
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 {/* www . j a v a 2s . 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 w w w . j a v a2 s .co 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> advanceSearchAll(long companyId, long groupId, String title, String author, String desc, String type) {// w w w. j ava2s .c o m SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); searchContext.setEntryClassNames(CLASS_NAMES); BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext); contextQuery.addRequiredTerm(Field.COMPANY_ID, companyId); contextQuery.addRequiredTerm(Field.PORTLET_ID, Long.toString(ClassNameLocalServiceUtil.getClassNameId(LMSBook.class))); BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext); fullQuery.setQueryConfig(searchContext.getQueryConfig()); try { fullQuery.add(contextQuery, BooleanClauseOccur.MUST); } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext); Hits hits = null; if (Validator.isNotNull(title)) { Sort sort = new Sort(Field.TITLE, true); searchContext.setSorts(new Sort[] { sort }); fullQuery = createQuery(Field.TITLE, title, searchContext, fullQuery); } if (Validator.isNotNull(author)) { fullQuery = createQuery(Field.NAME, author, searchContext, fullQuery); } if (Validator.isNotNull(desc)) { fullQuery = createQuery(Field.DESCRIPTION, desc, searchContext, fullQuery); } if (searchQuery.clauses().size() > 0) { try { fullQuery.add(searchQuery, BooleanClauseOccur.MUST); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { hits = SearchEngineUtil.search(searchContext, fullQuery); } catch (SearchException e) { // TODO Auto-generated catch block e.printStackTrace(); } List<LMSBook> books = new ArrayList<LMSBook>(); if (hits != null && hits.getLength() > 0) { 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 ww w . j a v a 2 s . c o m 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.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;// w w w . j a v a 2s . 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.portlet.asset.service.impl.AssetEntryLocalServiceImpl.java
License:Open Source License
@Override public Hits search(long companyId, long[] groupIds, long userId, String className, String keywords, int status, int start, int end) throws SystemException { try {/* w w w.j a va 2 s . co m*/ SearchContext searchContext = new SearchContext(); Facet assetEntriesFacet = new AssetEntriesFacet(searchContext); assetEntriesFacet.setStatic(true); searchContext.addFacet(assetEntriesFacet); Facet scopeFacet = new ScopeFacet(searchContext); scopeFacet.setStatic(true); searchContext.addFacet(scopeFacet); searchContext.setAttribute("paginationType", "regular"); searchContext.setAttribute("status", status); searchContext.setCompanyId(companyId); searchContext.setEnd(end); searchContext.setEntryClassNames(getClassNames(companyId, className)); searchContext.setGroupIds(groupIds); searchContext.setKeywords(keywords); QueryConfig queryConfig = new QueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false); searchContext.setQueryConfig(queryConfig); searchContext.setStart(start); searchContext.setUserId(userId); Indexer indexer = FacetedSearcher.getInstance(); return indexer.search(searchContext); } catch (Exception e) { throw new SystemException(e); } }
From source file:com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.java
License:Open Source License
@Override public Hits search(long companyId, long[] groupIds, long userId, String className, String userName, String title, String description, String assetCategoryIds, String assetTagNames, int status, boolean andSearch, int start, int end) throws SystemException { try {/* w w w . java 2 s .co m*/ SearchContext searchContext = new SearchContext(); Facet assetEntriesFacet = new AssetEntriesFacet(searchContext); assetEntriesFacet.setStatic(true); searchContext.addFacet(assetEntriesFacet); Facet scopeFacet = new ScopeFacet(searchContext); scopeFacet.setStatic(true); searchContext.addFacet(scopeFacet); searchContext.setAndSearch(andSearch); searchContext.setAssetCategoryIds(StringUtil.split(assetCategoryIds, 0L)); searchContext.setAssetTagNames(StringUtil.split(assetTagNames)); searchContext.setAttribute(Field.DESCRIPTION, description); searchContext.setAttribute(Field.TITLE, title); searchContext.setAttribute(Field.USER_NAME, userName); searchContext.setAttribute("paginationType", "regular"); searchContext.setAttribute("status", status); searchContext.setCompanyId(companyId); searchContext.setEnd(end); searchContext.setEntryClassNames(getClassNames(companyId, className)); searchContext.setGroupIds(groupIds); QueryConfig queryConfig = new QueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false); searchContext.setQueryConfig(queryConfig); searchContext.setStart(start); searchContext.setUserId(userId); Indexer indexer = FacetedSearcher.getInstance(); return indexer.search(searchContext); } catch (Exception e) { throw new SystemException(e); } }
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 {/*from w w w .j av a 2 s . c o m*/ 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.liferay.users.admin.indexer.test.OrganizationIndexerTest.java
License:Open Source License
protected Hits search(String keywords) throws Exception { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(TestPropsValues.getCompanyId()); searchContext.setEntryClassNames(new String[] { Organization.class.getName() }); searchContext.setKeywords(keywords); QueryConfig queryConfig = searchContext.getQueryConfig(); queryConfig.setSelectedFieldNames(Field.NAME); return _indexer.search(searchContext); }
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 {/*from w ww . j av a2 s.c om*/ 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; }