Example usage for com.liferay.portal.kernel.search Hits getLength

List of usage examples for com.liferay.portal.kernel.search Hits getLength

Introduction

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

Prototype

public int getLength();

Source Link

Usage

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

License:Open Source License

public void match(Reference reference) throws PortalException {

    _log.info("match");

    long defaultGroupId = GetterUtil.getLong(PropsUtil.get("default.group.id"));

    Hits hits = search(reference.getUserId(), defaultGroupId, -1, null, reference.getTitle(), null,
            WorkflowConstants.STATUS_ANY, null, false, 0, 20, null);

    _log.info("hits.getLength() = " + hits.getLength());

    if (hits.getLength() == 0) {

        // not yet in the pool of common references

        _log.info("not yet in the global references ");

        // TODO: strip the private fields from the reference
        String bibTeX = reference.getBibTeX();

        ServiceContext serviceContext = new ServiceContext();
        serviceContext.setScopeGroupId(defaultGroupId);

        Reference globalReference = addReference(reference.getUserId(), bibTeX, serviceContext);

        refRefRelationLocalService.addRefRefRelation(reference.getUserId(), globalReference.getReferenceId(),
                reference.getReferenceId(), new ServiceContext());
    }//w  w w.java2s .c o  m
}

From source file:com.ext.portlet.Activity.ActivityUtil.java

License:Open Source License

private static List<SocialActivity> retrieveAggregatedSocialActivities(Hits hits) {
    List<SocialActivity> aggregatedSocialActivities = new ArrayList<>(hits.getLength());

    for (Document activityDoc : hits.getDocs()) {
        try {/*from  w  ww . j  av  a2s .  com*/
            SocialActivity sa = SocialActivityLocalServiceUtil
                    .getSocialActivity(GetterUtil.getLong(activityDoc.getField("activityId").getValue()));
            aggregatedSocialActivities.add(sa);
        } catch (Exception e) {
            _log.error(e);
        }
    }

    return aggregatedSocialActivities;
}

From source file:com.idetronic.eprint.service.impl.EprintLocalServiceImpl.java

License:Open Source License

public List<Eprint> searchIndex(String keyword, long companyId, long groupId) throws SystemException {

    Hits hits = getHits(keyword, companyId, groupId);
    // 1. return null if no results
    if (Validator.isNull(hits) || hits.getLength() == 0)
        return null;

    List<Eprint> eprints = new ArrayList<Eprint>();
    for (Document document : hits.getDocs()) {
        long eprintId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));
        Eprint eprint = fetchEprint(eprintId);
        eprints.add(eprint);/*from   w  w  w.ja  va 2 s  . c  o m*/
    }
    return eprints;
}

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;
    try {//from  w w  w . ja  v  a2s . c o m
        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) {//from w w w .  j  a  va2s. 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;

    try {//from   w  ww  .ja va 2s. c  om
        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.asset.internal.util.AssetHelperImpl.java

License:Open Source License

@Override
public BaseModelSearchResult<AssetEntry> searchAssetEntries(SearchContext searchContext,
        AssetEntryQuery assetEntryQuery, int start, int end) throws Exception {

    AssetSearcher assetSearcher = _getAssetSearcher(searchContext, assetEntryQuery, start, end);

    Hits hits = assetSearcher.search(searchContext);

    List<AssetEntry> assetEntries = getAssetEntries(hits);

    return new BaseModelSearchResult<>(assetEntries, hits.getLength());
}

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.asset.test.util.BaseAssetSearchTestCase.java

License:Open Source License

protected int searchCount(AssetEntryQuery assetEntryQuery, SearchContext searchContext, int start, int end)
        throws Exception {

    Hits results = _assetHelper.search(searchContext, assetEntryQuery, start, end);

    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();
}