@Test
public void testHighlightWithFields() {
ProductBean beanWithText = createProductBean("withName", 5, true);
beanWithText.setDescription("some text with name in it");
repo.save(beanWithText);
HighlightPage<ProductBean> page = repo.findByNameHighlightAllLimitToFields("na", new PageRequest(0, 10));
Assert.assertEquals(4, page.getNumberOfElements());
for (ProductBean product : page) {
List<Highlight> highlights = page.getHighlights(product);
if (!product.getId().equals(beanWithText.getId())) {
Assert.assertThat(highlights, IsEmptyCollection.empty());
} else {
Assert.assertThat(highlights, IsNot.not(IsEmptyCollection.empty()));
for (Highlight highlight : highlights) {
Assert.assertEquals("description", highlight.getField().getName());
Assert.assertThat(highlight.getSnipplets(), IsNot.not(IsEmptyCollection.empty()));
for (String s : highlight.getSnipplets()) {
Assert.assertTrue("expected to find <em>name</em> but was \"" + s + "\"", s.contains("<em>name</em>"));
}
}
}
}
}
ITestSolrRepositoryOperations.java 文件源码
java
阅读 24
收藏 0
点赞 0
评论 0
项目:spring-data-solr
作者:
评论列表
文章目录