Skip to content

Commit 403bd08

Browse files
fax4everyrodiere
authored andcommitted
HSEARCH-3947 Add no limit search test
1 parent f9df723 commit 403bd08

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Hibernate Search, full-text search for your domain model
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.search.integrationtest.backend.lucene.search;
8+
9+
import static org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThat;
10+
import static org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMapperUtils.documentProvider;
11+
12+
import java.util.List;
13+
14+
import org.hibernate.search.engine.backend.common.DocumentReference;
15+
import org.hibernate.search.engine.backend.document.IndexFieldReference;
16+
import org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement;
17+
import org.hibernate.search.engine.search.query.SearchQuery;
18+
import org.hibernate.search.engine.search.query.SearchResult;
19+
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper;
20+
import org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex;
21+
import org.hibernate.search.util.impl.test.annotation.TestForIssue;
22+
23+
import org.junit.BeforeClass;
24+
import org.junit.ClassRule;
25+
import org.junit.Test;
26+
27+
@TestForIssue(jiraKey = "HSEARCH-3947")
28+
public class LuceneNoLimitSearchIT {
29+
30+
public static final int INDEX_SIZE = 100_000;
31+
32+
@ClassRule
33+
public static final SearchSetupHelper setupHelper = new SearchSetupHelper();
34+
35+
private static final SimpleMappedIndex<IndexBinding> index = SimpleMappedIndex.of( IndexBinding::new );
36+
37+
@BeforeClass
38+
public static void setup() {
39+
setupHelper.start().withIndex( index ).setup();
40+
initData();
41+
}
42+
43+
@Test
44+
public void fetchAll() {
45+
SearchQuery<DocumentReference> query = index.createScope().query()
46+
.where( f -> f.match().field( "field" ).matching( "739" ) )
47+
.toQuery();
48+
49+
SearchResult<DocumentReference> documentReferences = query.fetchAll();
50+
51+
assertThat( documentReferences )
52+
.hasDocRefHitsAnyOrder( index.typeName(), "739" )
53+
.hasTotalHitCount( 1L );
54+
}
55+
56+
@Test
57+
public void fetchAll_totalHitCountThreshold() {
58+
SearchQuery<DocumentReference> query = index.createScope().query()
59+
.where( f -> f.match().field( "field" ).matching( "739" ) )
60+
.totalHitCountThreshold( 5 )
61+
.toQuery();
62+
63+
SearchResult<DocumentReference> documentReferences = query.fetchAll();
64+
65+
assertThat( documentReferences )
66+
.hasDocRefHitsAnyOrder( index.typeName(), "739" )
67+
.hasTotalHitCount( 1L );
68+
}
69+
70+
@Test
71+
public void fetchAllHits() {
72+
SearchQuery<DocumentReference> query = index.createScope().query()
73+
.where( f -> f.match().field( "field" ).matching( "739" ) )
74+
.toQuery();
75+
76+
List<DocumentReference> documentReferences = query.fetchAllHits();
77+
78+
assertThat( documentReferences ).hasDocRefHitsAnyOrder( index.typeName(), "739" );
79+
}
80+
81+
private static void initData() {
82+
index.bulkIndexer()
83+
.add( INDEX_SIZE, i -> documentProvider(
84+
String.valueOf( i ),
85+
document -> document.addValue( index.binding().field, String.valueOf( i ) )
86+
) )
87+
.join();
88+
}
89+
90+
private static class IndexBinding {
91+
final IndexFieldReference<String> field;
92+
93+
IndexBinding(IndexSchemaElement root) {
94+
field = root.field( "field", c -> c.asString() ).toReference();
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)