Search in sources :

Example 1 with EmptyCloseableIterator

use of com.mysema.commons.lang.EmptyCloseableIterator in project querydsl by querydsl.

the class AbstractLuceneQuery method iterate.

@Override
public CloseableIterator<T> iterate() {
    final QueryMetadata metadata = queryMixin.getMetadata();
    final List<OrderSpecifier<?>> orderBys = metadata.getOrderBy();
    final Integer queryLimit = metadata.getModifiers().getLimitAsInteger();
    final Integer queryOffset = metadata.getModifiers().getOffsetAsInteger();
    Sort sort = querySort;
    int limit;
    final int offset = queryOffset != null ? queryOffset : 0;
    try {
        limit = maxDoc();
        if (limit == 0) {
            return new EmptyCloseableIterator<T>();
        }
    } catch (IOException | IllegalArgumentException e) {
        throw new QueryException(e);
    }
    if (queryLimit != null && queryLimit < limit) {
        limit = queryLimit;
    }
    if (sort == null && !orderBys.isEmpty()) {
        sort = serializer.toSort(orderBys);
    }
    try {
        ScoreDoc[] scoreDocs;
        int sumOfLimitAndOffset = limit + offset;
        if (sumOfLimitAndOffset < 1) {
            throw new QueryException("The given limit (" + limit + ") and offset (" + offset + ") cause an integer overflow.");
        }
        if (sort != null) {
            scoreDocs = searcher.search(createQuery(), getFilter(), sumOfLimitAndOffset, sort).scoreDocs;
        } else {
            scoreDocs = searcher.search(createQuery(), getFilter(), sumOfLimitAndOffset).scoreDocs;
        }
        if (offset < scoreDocs.length) {
            return new ResultIterator<T>(scoreDocs, offset, searcher, fieldSelector, transformer);
        }
        return new EmptyCloseableIterator<T>();
    } catch (final IOException e) {
        throw new QueryException(e);
    }
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) IOException(java.io.IOException) ScoreDoc(org.apache.lucene.search.ScoreDoc) QueryException(com.querydsl.core.QueryException) EmptyCloseableIterator(com.mysema.commons.lang.EmptyCloseableIterator) Sort(org.apache.lucene.search.Sort) OrderSpecifier(com.querydsl.core.types.OrderSpecifier)

Example 2 with EmptyCloseableIterator

use of com.mysema.commons.lang.EmptyCloseableIterator in project querydsl by querydsl.

the class AbstractLuceneQuery method iterate.

@Override
public CloseableIterator<T> iterate() {
    final QueryMetadata metadata = queryMixin.getMetadata();
    final List<OrderSpecifier<?>> orderBys = metadata.getOrderBy();
    final Integer queryLimit = metadata.getModifiers().getLimitAsInteger();
    final Integer queryOffset = metadata.getModifiers().getOffsetAsInteger();
    Sort sort = querySort;
    int limit;
    final int offset = queryOffset != null ? queryOffset : 0;
    try {
        limit = maxDoc();
        if (limit == 0) {
            return new EmptyCloseableIterator<T>();
        }
    } catch (IOException | IllegalArgumentException e) {
        throw new QueryException(e);
    }
    if (queryLimit != null && queryLimit < limit) {
        limit = queryLimit;
    }
    if (sort == null && !orderBys.isEmpty()) {
        sort = serializer.toSort(orderBys);
    }
    try {
        ScoreDoc[] scoreDocs;
        int sumOfLimitAndOffset = limit + offset;
        if (sumOfLimitAndOffset < 1) {
            throw new QueryException("The given limit (" + limit + ") and offset (" + offset + ") cause an integer overflow.");
        }
        if (sort != null) {
            scoreDocs = searcher.search(createQuery(), getFilter(), sumOfLimitAndOffset, sort, false, false).scoreDocs;
        } else {
            scoreDocs = searcher.search(createQuery(), getFilter(), sumOfLimitAndOffset, Sort.INDEXORDER, false, false).scoreDocs;
        }
        if (offset < scoreDocs.length) {
            return new ResultIterator<T>(scoreDocs, offset, searcher, fieldsToLoad, transformer);
        }
        return new EmptyCloseableIterator<T>();
    } catch (final IOException e) {
        throw new QueryException(e);
    }
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) IOException(java.io.IOException) ScoreDoc(org.apache.lucene.search.ScoreDoc) QueryException(com.querydsl.core.QueryException) EmptyCloseableIterator(com.mysema.commons.lang.EmptyCloseableIterator) Sort(org.apache.lucene.search.Sort) OrderSpecifier(com.querydsl.core.types.OrderSpecifier)

Example 3 with EmptyCloseableIterator

use of com.mysema.commons.lang.EmptyCloseableIterator in project querydsl by querydsl.

the class AbstractLuceneQuery method iterate.

@Override
public CloseableIterator<T> iterate() {
    final QueryMetadata metadata = queryMixin.getMetadata();
    final List<OrderSpecifier<?>> orderBys = metadata.getOrderBy();
    final Integer queryLimit = metadata.getModifiers().getLimitAsInteger();
    final Integer queryOffset = metadata.getModifiers().getOffsetAsInteger();
    Sort sort = querySort;
    int limit;
    final int offset = queryOffset != null ? queryOffset : 0;
    try {
        limit = maxDoc();
        if (limit == 0) {
            return new EmptyCloseableIterator<T>();
        }
    } catch (IOException | IllegalArgumentException e) {
        throw new QueryException(e);
    }
    if (queryLimit != null && queryLimit < limit) {
        limit = queryLimit;
    }
    if (sort == null && !orderBys.isEmpty()) {
        sort = serializer.toSort(orderBys);
    }
    try {
        ScoreDoc[] scoreDocs;
        int sumOfLimitAndOffset = limit + offset;
        if (sumOfLimitAndOffset < 1) {
            throw new QueryException("The given limit (" + limit + ") and offset (" + offset + ") cause an integer overflow.");
        }
        if (sort != null) {
            scoreDocs = searcher.search(createQuery(), // sumOfLimitAndOffset).scoreDocs;
            sumOfLimitAndOffset, sort, false, false).scoreDocs;
        } else {
            scoreDocs = searcher.search(createQuery(), sumOfLimitAndOffset, Sort.INDEXORDER, false, false).scoreDocs;
        }
        if (offset < scoreDocs.length) {
            return new ResultIterator<T>(scoreDocs, offset, searcher, fieldsToLoad, transformer);
        }
        return new EmptyCloseableIterator<T>();
    } catch (final IOException e) {
        throw new QueryException(e);
    }
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) IOException(java.io.IOException) ScoreDoc(org.apache.lucene.search.ScoreDoc) QueryException(com.querydsl.core.QueryException) EmptyCloseableIterator(com.mysema.commons.lang.EmptyCloseableIterator) Sort(org.apache.lucene.search.Sort) OrderSpecifier(com.querydsl.core.types.OrderSpecifier)

Aggregations

EmptyCloseableIterator (com.mysema.commons.lang.EmptyCloseableIterator)3 DefaultQueryMetadata (com.querydsl.core.DefaultQueryMetadata)3 QueryException (com.querydsl.core.QueryException)3 QueryMetadata (com.querydsl.core.QueryMetadata)3 OrderSpecifier (com.querydsl.core.types.OrderSpecifier)3 IOException (java.io.IOException)3 ScoreDoc (org.apache.lucene.search.ScoreDoc)3 Sort (org.apache.lucene.search.Sort)3