@@ -1696,16 +1696,25 @@ public void testMoreLikeThisIds() throws Exception {
1696
1696
Query parsedQuery = queryParser .parse (query ).query ();
1697
1697
assertThat (parsedQuery , instanceOf (BooleanQuery .class ));
1698
1698
BooleanQuery booleanQuery = (BooleanQuery ) parsedQuery ;
1699
- assertThat (booleanQuery .getClauses ().length , is (likeTexts .size ()));
1699
+ assertThat (booleanQuery .getClauses ().length , is (likeTexts .size () + 1 ));
1700
1700
1701
+ // check each clause is for each item
1702
+ BooleanClause [] boolClauses = booleanQuery .getClauses ();
1701
1703
for (int i =0 ; i <likeTexts .size (); i ++) {
1702
- BooleanClause booleanClause = booleanQuery .getClauses ()[i ];
1703
- assertThat (booleanClause .getOccur (), is (BooleanClause .Occur .SHOULD ));
1704
- assertThat (booleanClause .getQuery (), instanceOf (MoreLikeThisQuery .class ));
1705
- MoreLikeThisQuery mltQuery = (MoreLikeThisQuery ) booleanClause .getQuery ();
1704
+ assertThat (boolClauses [i ].getOccur (), is (BooleanClause .Occur .SHOULD ));
1705
+ assertThat (boolClauses [i ].getQuery (), instanceOf (MoreLikeThisQuery .class ));
1706
+ MoreLikeThisQuery mltQuery = (MoreLikeThisQuery ) boolClauses [i ].getQuery ();
1706
1707
assertThat (mltQuery .getLikeText (), is (likeTexts .get (i ).text ));
1707
1708
assertThat (mltQuery .getMoreLikeFields ()[0 ], equalTo (likeTexts .get (i ).field ));
1708
1709
}
1710
+
1711
+ // check last clause is for 'like_text'
1712
+ BooleanClause boolClause = boolClauses [boolClauses .length - 1 ];
1713
+ assertThat (boolClause .getOccur (), is (BooleanClause .Occur .SHOULD ));
1714
+ assertThat (boolClause .getQuery (), instanceOf (MoreLikeThisQuery .class ));
1715
+ MoreLikeThisQuery mltQuery = (MoreLikeThisQuery ) boolClause .getQuery ();
1716
+ assertArrayEquals ("Not the same more like this 'fields'" , new String [] {"name.first" , "name.last" }, mltQuery .getMoreLikeFields ());
1717
+ assertThat (mltQuery .getLikeText (), equalTo ("Apache Lucene" ));
1709
1718
}
1710
1719
1711
1720
private static class MockMoreLikeThisFetchService extends MoreLikeThisFetchService {
0 commit comments