use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.
the class LuceneQueryTest method listDistinctResults.
@Test(expected = UnsupportedOperationException.class)
public void listDistinctResults() {
query.where(year.between(1800, 2000).or(title.eq("The Lord of the Rings")));
query.restrict(new QueryModifiers(1L, 1L));
query.orderBy(year.asc());
final QueryResults<Document> results = query.distinct().fetchResults();
assertFalse(results.isEmpty());
assertEquals("1954", results.getResults().get(0).get("year"));
assertEquals(1, results.getLimit());
assertEquals(1, results.getOffset());
assertEquals(4, results.getTotal());
}
use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.
the class LuceneQueryTest method listResults.
@Test
public void listResults() {
query.where(year.between(1800, 2000));
query.restrict(new QueryModifiers(2L, 1L));
query.orderBy(year.asc());
final QueryResults<Document> results = query.fetchResults();
assertFalse(results.isEmpty());
assertEquals("1954", results.getResults().get(0).get("year"));
assertEquals("1990", results.getResults().get(1).get("year"));
assertEquals(2, results.getLimit());
assertEquals(1, results.getOffset());
assertEquals(4, results.getTotal());
}
use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.
the class AbstractLuceneQuery method oneResult.
@Nullable
private T oneResult(boolean unique) {
try {
int maxDoc = maxDoc();
if (maxDoc == 0) {
return null;
}
final ScoreDoc[] scoreDocs = searcher.search(createQuery(), getFilter(), maxDoc).scoreDocs;
int index = 0;
QueryModifiers modifiers = queryMixin.getMetadata().getModifiers();
Long offset = modifiers.getOffset();
if (offset != null) {
index = offset.intValue();
}
Long limit = modifiers.getLimit();
if (unique && (limit == null ? scoreDocs.length - index > 1 : limit > 1 && scoreDocs.length > 1)) {
throw new NonUniqueResultException("Unique result requested, but " + scoreDocs.length + " found.");
} else if (scoreDocs.length > index) {
Document document;
if (fieldSelector != null) {
document = searcher.doc(scoreDocs[index].doc, fieldSelector);
} else {
document = searcher.doc(scoreDocs[index].doc);
}
return transformer.apply(document);
} else {
return null;
}
} catch (IOException | IllegalArgumentException e) {
throw new QueryException(e);
}
}
use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.
the class AbstractLuceneQuery method oneResult.
@Nullable
private T oneResult(boolean unique) {
try {
int maxDoc = maxDoc();
if (maxDoc == 0) {
return null;
}
final ScoreDoc[] scoreDocs = searcher.search(createQuery(), getFilter(), maxDoc, Sort.INDEXORDER, false, false).scoreDocs;
int index = 0;
QueryModifiers modifiers = queryMixin.getMetadata().getModifiers();
Long offset = modifiers.getOffset();
if (offset != null) {
index = offset.intValue();
}
Long limit = modifiers.getLimit();
if (unique && (limit == null ? scoreDocs.length - index > 1 : limit > 1 && scoreDocs.length > 1)) {
throw new NonUniqueResultException("Unique result requested, but " + scoreDocs.length + " found.");
} else if (scoreDocs.length > index) {
Document document;
if (fieldsToLoad != null) {
document = searcher.doc(scoreDocs[index].doc, fieldsToLoad);
} else {
document = searcher.doc(scoreDocs[index].doc);
}
return transformer.apply(document);
} else {
return null;
}
} catch (IOException | IllegalArgumentException e) {
throw new QueryException(e);
}
}
use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.
the class LuceneQueryTest method listResults.
@Test
public void listResults() {
query.where(year.between(1800, 2000));
query.restrict(new QueryModifiers(2L, 1L));
query.orderBy(year.asc());
final QueryResults<Document> results = query.fetchResults();
assertFalse(results.isEmpty());
assertEquals("1954", results.getResults().get(0).get("year"));
assertEquals("1990", results.getResults().get(1).get("year"));
assertEquals(2, results.getLimit());
assertEquals(1, results.getOffset());
assertEquals(4, results.getTotal());
}
Aggregations