org.springframework.data.mongodb.core.query.TextCriteria Java Examples
The following examples show how to use
org.springframework.data.mongodb.core.query.TextCriteria.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestMongoXMLConfig.java From Spring with Apache License 2.0 | 5 votes |
@Test public void testFullSearch(){ final TextCriteria textCriteria = TextCriteria.forDefaultLanguage().matching("Gatsby"); final List<Book> books = bookRepository.findAllBy(textCriteria); //find using query: { "$text" : { "$search" : "Gatsby"}} fields: { "score" : { "$meta" : "textScore"}} for class: class com.oreilly.sdata.Book in collection: book books.forEach(b -> log.info(b.toString())); // Book(bookId=5ba144447c04cb2d09cf1109, title=The Great Gatsby, publishDate=Mon Dec 29 23:46:40 EET 2014, pageCount=220, price=7.4, author=Author(authorId=null, firstName=F.Scoot, lastName=Fitzgerald, country=United States), tags=[Best Seller], location=Library(libraryId=null, name=San Francisco Public Library, coords=Point [x=-122.413964, y=37.787228]), description=null, score=3.75) // Book(bookId=5ba146677c045727399d9969, title=The Great Gatsby, publishDate=Mon Dec 29 23:46:40 EET 2014, pageCount=220, price=7.4, author=Author(authorId=null, firstName=F.Scoot, lastName=Fitzgerald, country=United States), tags=[Best Seller], location=Library(libraryId=null, name=San Francisco Public Library, coords=Point [x=-122.413964, y=37.787228]), description=null, score=3.75) // Book(bookId=5ba146c27c045368b51c69d1, title=The Great Gatsby, publishDate=Mon Dec 29 23:46:40 EET 2014, pageCount=220, price=7.4, author=Author(authorId=null, firstName=F.Scoot, lastName=Fitzgerald, country=United States), tags=[Best Seller], location=Library(libraryId=null, name=San Francisco Public Library, coords=Point [x=-122.413964, y=37.787228]), description=null, score=3.75) }
Example #2
Source File: RecommenderManager.java From scava with Eclipse Public License 2.0 | 5 votes |
@Override public List<Artifact> getArtifactsByQuery(String projectQuery) { TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingAny(projectQuery); org.springframework.data.mongodb.core.query.Query query = TextQuery.queryText(criteria).sortByScore() .with(new PageRequest(0, 5)); List<Artifact> recipes = template.find(query, Artifact.class); return recipes; }
Example #3
Source File: RecommenderManager.java From scava with Eclipse Public License 2.0 | 5 votes |
@Override public List<Artifact> getArtifactsByQuery(String projectQuery, Pageable page) { TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingAny(projectQuery); org.springframework.data.mongodb.core.query.Query query = TextQuery.queryText(criteria).sortByScore() .with(page); query.addCriteria(Criteria.where("type.name").ne("FOCUS")); List<Artifact> recipes = template.find(query, Artifact.class); if (page.getSort().getOrderFor("temp").getDirection() == Direction.ASC) return Lists.reverse(recipes); return recipes; }
Example #4
Source File: TextSearchRepositoryTests.java From spring-data-examples with Apache License 2.0 | 5 votes |
/** * Show how to do simple matching. <br /> * Note that text search is case insensitive and will also find entries like {@literal releases}. */ @Test public void findAllBlogPostsWithRelease() { TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingAny("release"); List<BlogPost> blogPosts = repo.findAllBy(criteria); printResult(blogPosts, criteria); }
Example #5
Source File: TextSearchRepositoryTests.java From spring-data-examples with Apache License 2.0 | 5 votes |
/** * Simple matching using negation. */ @Test public void findAllBlogPostsWithReleaseButHeyIDoWantTheEngineeringStuff() { TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingAny("release").notMatching("engineering"); List<BlogPost> blogPosts = repo.findAllBy(criteria); printResult(blogPosts, criteria); }
Example #6
Source File: TextSearchRepositoryTests.java From spring-data-examples with Apache License 2.0 | 5 votes |
/** * Phrase matching looks for the whole phrase as one. */ @Test public void findAllBlogPostsByPhrase() { TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingPhrase("release candidate"); List<BlogPost> blogPosts = repo.findAllBy(criteria); printResult(blogPosts, criteria); }
Example #7
Source File: TextSearchRepositoryTests.java From spring-data-examples with Apache License 2.0 | 5 votes |
/** * Sort by relevance relying on the value marked with {@link TextScore}. */ @Test public void findAllBlogPostsByPhraseSortByScore() { TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingPhrase("release candidate"); List<BlogPost> blogPosts = repo.findAllByOrderByScoreDesc(criteria); printResult(blogPosts, criteria); }
Example #8
Source File: TextSearchTemplateTests.java From spring-data-examples with Apache License 2.0 | 5 votes |
/** * Show how to do simple matching. Note that text search is case insensitive and will also find entries like * {@literal releases}. */ @Test public void findAllBlogPostsWithRelease() { TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingAny("release"); List<BlogPost> blogPosts = operations.find(query(criteria), BlogPost.class); printResult(blogPosts, criteria); }
Example #9
Source File: TextSearchTemplateTests.java From spring-data-examples with Apache License 2.0 | 5 votes |
/** * Sort by relevance relying on the value marked with {@link org.springframework.data.mongodb.core.mapping.TextScore}. */ @Test public void findAllBlogPostsByPhraseSortByScore() { TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingPhrase("release"); TextQuery query = new TextQuery(criteria); query.setScoreFieldName("score"); query.sortByScore(); List<BlogPost> blogPosts = operations.find(query, BlogPost.class); printResult(blogPosts, criteria); }
Example #10
Source File: BookRepository.java From Spring with Apache License 2.0 | votes |
List<Book> findAllBy(TextCriteria textCriteria);
Example #11
Source File: BlogPostRepository.java From spring-data-examples with Apache License 2.0 | votes |
List<BlogPost> findAllBy(TextCriteria criteria);
Example #12
Source File: BlogPostRepository.java From spring-data-examples with Apache License 2.0 | votes |
List<BlogPost> findAllByOrderByScoreDesc(TextCriteria criteria);