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

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

Introduction

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

Prototype

public static Hits search(SearchContext searchContext, Query query) throws SearchException 

Source Link

Usage

From source file:com.liferay.journal.search.test.JournalArticleSearchTest.java

License:Open Source License

protected void assertEquals(long length, BooleanQuery query, SearchContext searchContext) throws Exception {

    Hits hits = IndexSearcherHelperUtil.search(searchContext, query);

    Assert.assertEquals(hits.toString(), length, hits.getLength());
}

From source file:com.liferay.mail.util.AccountIndexer.java

License:Open Source License

@Override
protected void doDelete(Account account) throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(account.getCompanyId());
    searchContext.setEnd(QueryUtil.ALL_POS);
    searchContext.setSearchEngineId(getSearchEngineId());
    searchContext.setSorts(SortFactoryUtil.getDefaultSorts());
    searchContext.setStart(QueryUtil.ALL_POS);

    BooleanQuery booleanQuery = new BooleanQueryImpl();

    booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, CLASS_NAME);

    booleanQuery.addRequiredTerm("accountId", account.getAccountId());

    Hits hits = IndexSearcherHelperUtil.search(searchContext, booleanQuery);

    List<String> uids = new ArrayList<>(hits.getLength());

    for (int i = 0; i < hits.getLength(); i++) {
        Document document = hits.doc(i);

        uids.add(document.get(Field.UID));
    }/*from   ww w  .  j  a  va  2  s.c  o  m*/

    IndexWriterHelperUtil.deleteDocuments(getSearchEngineId(), account.getCompanyId(), uids,
            isCommitImmediately());
}

From source file:com.liferay.mail.util.FolderIndexer.java

License:Open Source License

@Override
protected void doDelete(Folder folder) throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(folder.getCompanyId());
    searchContext.setEnd(QueryUtil.ALL_POS);
    searchContext.setSearchEngineId(getSearchEngineId());
    searchContext.setSorts(SortFactoryUtil.getDefaultSorts());
    searchContext.setStart(QueryUtil.ALL_POS);

    BooleanQuery booleanQuery = new BooleanQueryImpl();

    booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, CLASS_NAME);

    booleanQuery.addRequiredTerm("folderId", folder.getFolderId());

    Hits hits = IndexSearcherHelperUtil.search(searchContext, booleanQuery);

    List<String> uids = new ArrayList<>(hits.getLength());

    for (int i = 0; i < hits.getLength(); i++) {
        Document document = hits.doc(i);

        uids.add(document.get(Field.UID));
    }//  w ww .  ja va 2s .  c o m

    IndexWriterHelperUtil.deleteDocuments(getSearchEngineId(), folder.getCompanyId(), uids,
            isCommitImmediately());
}