@@ -1116,6 +1116,49 @@ public void shouldReturnSimilarResultsGivenMoreLikeThisQuery() {
11161116 assertThat (content ).contains (sampleEntity );
11171117 }
11181118
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+
11191162 @ Test // DATAES-167
11201163 public void shouldReturnResultsWithScanAndScrollForGivenCriteriaQuery () {
11211164
@@ -3751,6 +3794,7 @@ void shouldReturnExplanationWhenRequested() {
37513794 assertThat (explanation ).isNotNull ();
37523795 }
37533796
3797+ // region entities
37543798 @ Document (indexName = INDEX_NAME_SAMPLE_ENTITY )
37553799 @ Setting (shards = 1 , replicas = 0 , refreshInterval = "-1" )
37563800 static class SampleEntity {
@@ -4528,4 +4572,5 @@ public void setText(@Nullable String text) {
45284572 this .text = text ;
45294573 }
45304574 }
4575+ //endregion
45314576}
0 commit comments