Search in sources :

Example 41 with QueryMetadata

use of com.querydsl.core.QueryMetadata 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)

Example 42 with QueryMetadata

use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.

the class TermElementTest method test.

@Test
public void test() {
    StringPath title = Expressions.stringPath("title");
    LuceneSerializer serializer = new LuceneSerializer(false, true);
    QueryMetadata metadata = new DefaultQueryMetadata();
    assertEquals("title:\"Hello World\"", serializer.toQuery(title.eq("Hello World"), metadata).toString());
    assertEquals("title:Hello World", serializer.toQuery(title.eq(new TermElement("Hello World")), metadata).toString());
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) TermElement(com.querydsl.lucene5.TermElement) StringPath(com.querydsl.core.types.dsl.StringPath) LuceneSerializer(com.querydsl.lucene5.LuceneSerializer) Test(org.junit.Test)

Example 43 with QueryMetadata

use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.

the class PhraseElementTest method test.

@Test
public void test() {
    StringPath title = Expressions.stringPath("title");
    LuceneSerializer serializer = new LuceneSerializer(false, false);
    QueryMetadata metadata = new DefaultQueryMetadata();
    assertEquals("title:Hello World", serializer.toQuery(title.eq("Hello World"), metadata).toString());
    assertEquals("title:\"Hello World\"", serializer.toQuery(title.eq(new PhraseElement("Hello World")), metadata).toString());
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) StringPath(com.querydsl.core.types.dsl.StringPath) PhraseElement(com.querydsl.lucene5.PhraseElement) LuceneSerializer(com.querydsl.lucene5.LuceneSerializer) Test(org.junit.Test)

Example 44 with QueryMetadata

use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.

the class TermElementTest method test.

@Test
public void test() {
    StringPath title = Expressions.stringPath("title");
    LuceneSerializer serializer = new LuceneSerializer(false, true);
    QueryMetadata metadata = new DefaultQueryMetadata();
    assertEquals("title:\"Hello World\"", serializer.toQuery(title.eq("Hello World"), metadata).toString());
    assertEquals("title:Hello World", serializer.toQuery(title.eq(new TermElement("Hello World")), metadata).toString());
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) StringPath(com.querydsl.core.types.dsl.StringPath) Test(org.junit.Test)

Aggregations

QueryMetadata (com.querydsl.core.QueryMetadata)44 Test (org.junit.Test)35 DefaultQueryMetadata (com.querydsl.core.DefaultQueryMetadata)24 JoinExpression (com.querydsl.core.JoinExpression)16 QCat (com.querydsl.core.domain.QCat)8 QCat (com.querydsl.jpa.domain.QCat)8 StringPath (com.querydsl.core.types.dsl.StringPath)6 OrderSpecifier (com.querydsl.core.types.OrderSpecifier)4 EmptyCloseableIterator (com.mysema.commons.lang.EmptyCloseableIterator)3 QueryException (com.querydsl.core.QueryException)3 IOException (java.io.IOException)3 ScoreDoc (org.apache.lucene.search.ScoreDoc)3 Sort (org.apache.lucene.search.Sort)3 Tuple (com.querydsl.core.Tuple)2 Path (com.querydsl.core.types.Path)2 QEmployee (com.querydsl.jpa.domain.QEmployee)2 QBookVersion (com.querydsl.jpa.domain4.QBookVersion)2 LuceneSerializer (com.querydsl.lucene5.LuceneSerializer)2 QEmployee (com.querydsl.sql.domain.QEmployee)2 ArrayList (java.util.ArrayList)2