Search in sources :

Example 1 with LuceneSearchException

use of com.celements.search.lucene.LuceneSearchException in project celements-blog by celements.

the class ArticleEngineLucene method getArticles.

@Override
public List<Article> getArticles(ArticleLoadParameter param) throws ArticleLoadException {
    try {
        List<Article> articles = new ArrayList<>();
        LuceneQuery query = queryBuilder.build(param);
        if (query != null) {
            LuceneSearchResult result = searchService.searchWithoutChecks(query, param.getSortFields(), Arrays.asList("default", param.getLanguage()));
            result.setOffset(param.getOffset()).setLimit(param.getLimit());
            for (EntityReference ref : result.getResults()) {
                if (ref instanceof DocumentReference) {
                    XWikiDocument doc = getContext().getWiki().getDocument((DocumentReference) ref, getContext());
                    try {
                        articles.add(new Article(doc, getContext()));
                    } catch (EmptyArticleException exc) {
                        LOGGER.warn("getArticles: empty article '{}'", exc, doc);
                    }
                } else {
                    LOGGER.warn("getArticles: not expecting Attachment as search result '{}' " + "for search '{}'", ref, param);
                }
            }
        } else {
            LOGGER.warn("got null from query builder for '" + param + "'");
        }
        return articles;
    } catch (LuceneSearchException lse) {
        throw new ArticleLoadException(lse);
    } catch (XWikiException xwe) {
        throw new ArticleLoadException(xwe);
    }
}
Also used : LuceneQuery(com.celements.search.lucene.query.LuceneQuery) EmptyArticleException(com.celements.blog.plugin.EmptyArticleException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) EntityReference(org.xwiki.model.reference.EntityReference) LuceneSearchException(com.celements.search.lucene.LuceneSearchException) LuceneSearchResult(com.celements.search.lucene.LuceneSearchResult) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

EmptyArticleException (com.celements.blog.plugin.EmptyArticleException)1 LuceneSearchException (com.celements.search.lucene.LuceneSearchException)1 LuceneSearchResult (com.celements.search.lucene.LuceneSearchResult)1 LuceneQuery (com.celements.search.lucene.query.LuceneQuery)1 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 ArrayList (java.util.ArrayList)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 EntityReference (org.xwiki.model.reference.EntityReference)1