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