@@ -47,8 +47,8 @@ public class TextSearchRepositoryTests {
|
||||
@Test
|
||||
public void findAllBlogPostsWithRelease() {
|
||||
|
||||
TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingAny("release");
|
||||
List<BlogPost> blogPosts = repo.findAllBy(criteria);
|
||||
var criteria = TextCriteria.forDefaultLanguage().matchingAny("release");
|
||||
var blogPosts = repo.findAllBy(criteria);
|
||||
|
||||
printResult(blogPosts, criteria);
|
||||
}
|
||||
@@ -59,8 +59,8 @@ public class TextSearchRepositoryTests {
|
||||
@Test
|
||||
public void findAllBlogPostsWithReleaseButHeyIDoWantTheEngineeringStuff() {
|
||||
|
||||
TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingAny("release").notMatching("engineering");
|
||||
List<BlogPost> blogPosts = repo.findAllBy(criteria);
|
||||
var criteria = TextCriteria.forDefaultLanguage().matchingAny("release").notMatching("engineering");
|
||||
var blogPosts = repo.findAllBy(criteria);
|
||||
|
||||
printResult(blogPosts, criteria);
|
||||
}
|
||||
@@ -71,8 +71,8 @@ public class TextSearchRepositoryTests {
|
||||
@Test
|
||||
public void findAllBlogPostsByPhrase() {
|
||||
|
||||
TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingPhrase("release candidate");
|
||||
List<BlogPost> blogPosts = repo.findAllBy(criteria);
|
||||
var criteria = TextCriteria.forDefaultLanguage().matchingPhrase("release candidate");
|
||||
var blogPosts = repo.findAllBy(criteria);
|
||||
|
||||
printResult(blogPosts, criteria);
|
||||
}
|
||||
@@ -83,8 +83,8 @@ public class TextSearchRepositoryTests {
|
||||
@Test
|
||||
public void findAllBlogPostsByPhraseSortByScore() {
|
||||
|
||||
TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingPhrase("release candidate");
|
||||
List<BlogPost> blogPosts = repo.findAllByOrderByScoreDesc(criteria);
|
||||
var criteria = TextCriteria.forDefaultLanguage().matchingPhrase("release candidate");
|
||||
var blogPosts = repo.findAllByOrderByScoreDesc(criteria);
|
||||
|
||||
printResult(blogPosts, criteria);
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ public class TextSearchTemplateTests {
|
||||
@Test
|
||||
public void findAllBlogPostsWithRelease() {
|
||||
|
||||
TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingAny("release");
|
||||
List<BlogPost> blogPosts = operations.find(query(criteria), BlogPost.class);
|
||||
var criteria = TextCriteria.forDefaultLanguage().matchingAny("release");
|
||||
var blogPosts = operations.find(query(criteria), BlogPost.class);
|
||||
|
||||
printResult(blogPosts, criteria);
|
||||
}
|
||||
@@ -71,13 +71,13 @@ public class TextSearchTemplateTests {
|
||||
@Test
|
||||
public void findAllBlogPostsByPhraseSortByScore() {
|
||||
|
||||
TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingPhrase("release");
|
||||
var criteria = TextCriteria.forDefaultLanguage().matchingPhrase("release");
|
||||
|
||||
TextQuery query = new TextQuery(criteria);
|
||||
var query = new TextQuery(criteria);
|
||||
query.setScoreFieldName("score");
|
||||
query.sortByScore();
|
||||
|
||||
List<BlogPost> blogPosts = operations.find(query, BlogPost.class);
|
||||
var blogPosts = operations.find(query, BlogPost.class);
|
||||
|
||||
printResult(blogPosts, criteria);
|
||||
}
|
||||
|
||||
@@ -50,12 +50,12 @@ public enum BlogPostInitializer {
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private void loadFromClasspathSource(MongoOperations operations) throws Exception {
|
||||
|
||||
Jackson2ResourceReader reader = new Jackson2ResourceReader();
|
||||
var reader = new Jackson2ResourceReader();
|
||||
|
||||
Object source = reader.readFrom(new ClassPathResource("spring-blog.atom.json"), this.getClass().getClassLoader());
|
||||
var source = reader.readFrom(new ClassPathResource("spring-blog.atom.json"), this.getClass().getClassLoader());
|
||||
|
||||
if (source instanceof Iterable) {
|
||||
((Iterable) source).forEach(element -> operations.save(element));
|
||||
((Iterable) source).forEach(operations::save);
|
||||
} else {
|
||||
operations.save(source);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ConsoleResultPrinter {
|
||||
System.out.println(String.format("XXXXXXXXXXXX -- Found %s blogPosts matching '%s' --XXXXXXXXXXXX",
|
||||
blogPosts.size(), criteria != null ? criteria.getCriteriaObject() : ""));
|
||||
|
||||
for (BlogPost blogPost : blogPosts) {
|
||||
for (var blogPost : blogPosts) {
|
||||
System.out.println(blogPost);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user