Example usage for com.liferay.portal.kernel.search Indexer search

List of usage examples for com.liferay.portal.kernel.search Indexer search

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.search Indexer search.

Prototype

public Hits search(SearchContext searchContext) throws SearchException;

Source Link

Usage

From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java

License:Open Source License

@Override
public Hits search(long userId, long groupId, long ownerUserId, String company, String fullName, int status,
        LinkedHashMap<String, Object> params, boolean andSearch, int start, int end, Sort sort)
        throws PortalException {

    if (sort == null) {
        sort = new Sort(Field.MODIFIED_DATE, true);
    }/*from w  w w  .  j  a  va  2s.c om*/

    Indexer<Contact> indexer = IndexerRegistryUtil.getIndexer(Contact.class.getName());

    SearchContext searchContext = buildSearchContext(userId, groupId, ownerUserId, company, fullName, status,
            params, andSearch, start, end, sort);

    return indexer.search(searchContext);

}

From source file:ch.inofix.referencemanager.service.impl.BibliographyServiceImpl.java

License:Open Source License

/**
 * @param userId/*from  w ww .  java2 s  .  co m*/
 *            the userId of the current user
 * @param groupId
 *            the scopeGroupId of the bibliography. 0 means: any scope.
 * @param ownerUserId
 *            the userId of the bibliography owner. -1 means: ignore
 *            ownerUserId parameter.
 * @param keywords
 * @param start
 * @param end
 * @param sort
 * @return the hits for the given parameters
 * @since 1.0.0
 * @throws PortalException
 */
public Hits search(long userId, long groupId, long ownerUserId, String keywords, int start, int end, Sort sort)
        throws PortalException {

    if (sort == null) {
        sort = new Sort(Field.MODIFIED_DATE, true);
    }

    Indexer<Bibliography> indexer = IndexerRegistryUtil.getIndexer(Bibliography.class.getName());

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, WorkflowConstants.STATUS_ANY);

    searchContext.setAttribute("paginationType", "more");

    User user = UserLocalServiceUtil.getUser(userId);

    searchContext.setCompanyId(user.getCompanyId());

    searchContext.setEnd(end);

    if (groupId > 0) {
        searchContext.setGroupIds(new long[] { groupId });
    }
    searchContext.setSorts(sort);
    searchContext.setStart(start);
    searchContext.setUserId(userId);
    searchContext.setOwnerUserId(ownerUserId);

    return indexer.search(searchContext);

}

From source file:ch.inofix.referencemanager.service.impl.ReferenceLocalServiceImpl.java

License:Open Source License

@Override
public Hits search(long userId, long groupId, long bibliographyId, String author, String title, String year,
        int status, LinkedHashMap<String, Object> params, boolean andSearch, int start, int end, Sort sort)
        throws PortalException {

    if (sort == null) {
        sort = new Sort(Field.MODIFIED_DATE, true);
    }//from   w w w  . ja  v a  2s .  c  o m

    Indexer<Reference> indexer = IndexerRegistryUtil.getIndexer(Reference.class.getName());

    SearchContext searchContext = buildSearchContext(userId, groupId, bibliographyId, author, title, year,
            status, params, andSearch, start, end, sort);

    return indexer.search(searchContext);
}

From source file:ch.inofix.timetracker.service.impl.TaskRecordLocalServiceImpl.java

License:Open Source License

@Override
public Hits search(long userId, long groupId, String keywords, int start, int end, Sort sort)
        throws PortalException {

    if (sort == null) {
        sort = new Sort(Field.MODIFIED_DATE, true);
    }/*from  w ww.  jav a 2  s. com*/

    Indexer<TaskRecord> indexer = IndexerRegistryUtil.getIndexer(TaskRecord.class.getName());

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, WorkflowConstants.STATUS_ANY);

    searchContext.setAttribute("paginationType", "more");

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    searchContext.setEnd(end);
    if (groupId > 0) {
        searchContext.setGroupIds(new long[] { groupId });
    }
    searchContext.setSorts(sort);
    searchContext.setStart(start);
    searchContext.setUserId(userId);

    searchContext.setKeywords(keywords);

    return indexer.search(searchContext);

}

From source file:com.liferay.alloy.mvc.BaseAlloyControllerImpl.java

License:Open Source License

protected AlloySearchResult search(Indexer indexer, AlloyServiceInvoker alloyServiceInvoker,
        HttpServletRequest request, PortletRequest portletRequest,
        SearchContainer<? extends BaseModel<?>> searchContainer, Map<String, Serializable> attributes,
        String keywords, Sort[] sorts) throws Exception {

    if (indexer == null) {
        throw new Exception("No indexer found for " + controllerPath);
    }/*from   w w  w  .  j a  v a  2 s .  c  o m*/

    AlloySearchResult alloySearchResult = new AlloySearchResult();

    alloySearchResult.setAlloyServiceInvoker(alloyServiceInvoker);

    if (searchContainer == null) {
        searchContainer = new SearchContainer<BaseModel<?>>(portletRequest, portletURL, null, null);
    }

    SearchContext searchContext = SearchContextFactory.getInstance(request);

    boolean andOperator = ParamUtil.getBoolean(request, "andOperator");

    searchContext.setAndSearch(andOperator);

    if ((attributes != null) && !attributes.isEmpty()) {
        searchContext.setAttributes(attributes);
    }

    searchContext.setEnd(searchContainer.getEnd());

    Class<?> indexerClass = Class.forName(indexer.getClassNames()[0]);

    if (!GroupedModel.class.isAssignableFrom(indexerClass)) {
        searchContext.setGroupIds(null);
    } else if (searchContext.getAttribute(Field.GROUP_ID) != null) {
        long groupId = GetterUtil.getLong(searchContext.getAttribute(Field.GROUP_ID));

        searchContext.setGroupIds(new long[] { groupId });
    }

    if (Validator.isNotNull(keywords)) {
        searchContext.setKeywords(keywords);
    }

    if (ArrayUtil.isNotEmpty(sorts)) {
        searchContext.setSorts(sorts);
    }

    searchContext.setStart(searchContainer.getStart());

    Hits hits = indexer.search(searchContext);

    alloySearchResult.setHits(hits);

    alloySearchResult.setPortletURL(portletURL, searchContext.getAttributes());

    alloySearchResult.afterPropertiesSet();

    return alloySearchResult;
}

From source file:com.liferay.asset.service.test.AssetVocabularyServiceTest.java

License:Open Source License

protected int searchCount() throws Exception {
    Indexer<AssetCategory> indexer = IndexerRegistryUtil.getIndexer(AssetCategory.class);

    SearchContext searchContext = SearchContextTestUtil.getSearchContext();

    searchContext.setGroupIds(new long[] { _group.getGroupId() });

    Hits results = indexer.search(searchContext);

    return results.getLength();
}

From source file:com.liferay.blogs.service.test.BlogsEntryStatusTransitionTest.java

License:Open Source License

protected int searchBlogsEntriesCount(long groupId) throws Exception {
    Indexer<BlogsEntry> indexer = IndexerRegistryUtil.getIndexer(BlogsEntry.class);

    SearchContext searchContext = SearchContextTestUtil.getSearchContext();

    searchContext.setGroupIds(new long[] { groupId });

    Hits results = indexer.search(searchContext);

    return results.getLength();
}

From source file:com.liferay.bookmarks.service.impl.BookmarksEntryLocalServiceImpl.java

License:Open Source License

@Override
public Hits search(long groupId, long userId, long creatorUserId, int status, int start, int end)
        throws PortalException {

    Indexer<BookmarksEntry> indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class.getName());

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, status);

    if (creatorUserId > 0) {
        searchContext.setAttribute(Field.USER_ID, String.valueOf(creatorUserId));
    }//  w  w  w .j a va 2 s .c  om

    searchContext.setAttribute("paginationType", "none");

    Group group = groupLocalService.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    searchContext.setEnd(end);
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setSorts(new Sort(Field.MODIFIED_DATE, true));
    searchContext.setStart(start);
    searchContext.setUserId(userId);

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setHighlightEnabled(false);
    queryConfig.setScoreEnabled(false);

    return indexer.search(searchContext);
}

From source file:com.liferay.bookmarks.service.test.BookmarksFolderServiceTest.java

License:Open Source License

@Test
public void testSearch() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    BookmarksFolder folder = BookmarksTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString());

    BookmarksEntry entry = BookmarksTestUtil.addEntry(folder.getFolderId(), true, serviceContext);

    SearchContext searchContext = BookmarksTestUtil.getSearchContext(entry.getCompanyId(), entry.getGroupId(),
            entry.getFolderId(), "test");

    Indexer<BookmarksEntry> indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class);

    Hits hits = indexer.search(searchContext);

    Assert.assertEquals(1, hits.getLength());
}

From source file:com.liferay.bookmarks.service.test.BookmarksFolderServiceTest.java

License:Open Source License

@Test
public void testSearchAndDeleteFolderAndSearch() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    BookmarksFolder folder = BookmarksTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString());

    BookmarksEntry entry = BookmarksTestUtil.addEntry(folder.getFolderId(), true, serviceContext);

    long companyId = entry.getCompanyId();
    long groupId = entry.getFolder().getGroupId();
    long folderId = entry.getFolderId();
    String keywords = "test";

    SearchContext searchContext = BookmarksTestUtil.getSearchContext(companyId, groupId, folderId, keywords);

    Indexer<BookmarksEntry> indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class);

    Hits hits = indexer.search(searchContext);

    Assert.assertEquals(1, hits.getLength());

    BookmarksFolderLocalServiceUtil.deleteFolder(folderId);

    hits = indexer.search(searchContext);

    Query query = hits.getQuery();

    Assert.assertEquals(query.toString(), 0, hits.getLength());
}