@@ -1116,6 +1116,49 @@ public void shouldReturnSimilarResultsGivenMoreLikeThisQuery() {
1116
1116
assertThat (content ).contains (sampleEntity );
1117
1117
}
1118
1118
1119
+ @ Test // #1787
1120
+ @ DisplayName ("should use Pageable on MoreLikeThis queries" )
1121
+ void shouldUsePageableOnMoreLikeThisQueries () {
1122
+
1123
+ String sampleMessage = "So we build a web site or an application and want to add search to it, "
1124
+ + "and then it hits us: getting search working is hard. We want our search solution to be fast,"
1125
+ + " we want a painless setup and a completely free search schema, we want to be able to index data simply using JSON over HTTP, "
1126
+ + "we want our search server to be always available, we want to be able to start with one machine and scale to hundreds, "
1127
+ + "we want real-time search, we want simple multi-tenancy, and we want a solution that is built for the cloud." ;
1128
+ String referenceId = nextIdAsString ();
1129
+ Collection <String > ids = IntStream .rangeClosed (1 , 10 ).mapToObj (i -> nextIdAsString ()).collect (Collectors .toList ());
1130
+ ids .add (referenceId );
1131
+ ids .stream ()
1132
+ .map (id -> getIndexQuery (SampleEntity .builder ().id (id ).message (sampleMessage ).version (System .currentTimeMillis ()).build ()))
1133
+ .forEach (indexQuery -> operations .index (indexQuery , index ));
1134
+ indexOperations .refresh ();
1135
+
1136
+ MoreLikeThisQuery moreLikeThisQuery = new MoreLikeThisQuery ();
1137
+ moreLikeThisQuery .setId (referenceId );
1138
+ moreLikeThisQuery .addFields ("message" );
1139
+ moreLikeThisQuery .setMinDocFreq (1 );
1140
+ moreLikeThisQuery .setPageable (PageRequest .of (0 , 5 ));
1141
+
1142
+ SearchHits <SampleEntity > searchHits = operations .search (moreLikeThisQuery , SampleEntity .class , index );
1143
+
1144
+ assertThat (searchHits .getTotalHits ()).isEqualTo (10 );
1145
+ assertThat (searchHits .getSearchHits ()).hasSize (5 );
1146
+
1147
+ Collection <String > returnedIds = searchHits .getSearchHits ().stream ().map (SearchHit ::getId ).collect (Collectors .toList ());
1148
+
1149
+ moreLikeThisQuery .setPageable (PageRequest .of (1 , 5 ));
1150
+
1151
+ searchHits = operations .search (moreLikeThisQuery , SampleEntity .class , index );
1152
+
1153
+ assertThat (searchHits .getTotalHits ()).isEqualTo (10 );
1154
+ assertThat (searchHits .getSearchHits ()).hasSize (5 );
1155
+
1156
+ searchHits .getSearchHits ().stream ().map (SearchHit ::getId ).forEach (returnedIds ::add );
1157
+
1158
+ assertThat (returnedIds ).hasSize (10 );
1159
+ assertThat (ids ).containsAll (returnedIds );
1160
+ }
1161
+
1119
1162
@ Test // DATAES-167
1120
1163
public void shouldReturnResultsWithScanAndScrollForGivenCriteriaQuery () {
1121
1164
@@ -3751,6 +3794,7 @@ void shouldReturnExplanationWhenRequested() {
3751
3794
assertThat (explanation ).isNotNull ();
3752
3795
}
3753
3796
3797
+ // region entities
3754
3798
@ Document (indexName = INDEX_NAME_SAMPLE_ENTITY )
3755
3799
@ Setting (shards = 1 , replicas = 0 , refreshInterval = "-1" )
3756
3800
static class SampleEntity {
@@ -4528,4 +4572,5 @@ public void setText(@Nullable String text) {
4528
4572
this .text = text ;
4529
4573
}
4530
4574
}
4575
+ //endregion
4531
4576
}
0 commit comments