diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/TextScore.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/TextScore.java
index a21a976eb..5f1af082a 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/TextScore.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/TextScore.java
@@ -26,9 +26,11 @@ import org.springframework.data.annotation.ReadOnlyProperty;
/**
* {@link TextScore} marks the property to be considered as the on server calculated {@literal textScore} when doing
* full text search.
- * NOTE Property will not be written when saving entity.
+ * NOTE Property will not be written when saving entity and may be {@literal null} if the document is retrieved
+ * by a regular (i.e. {@literal $text}) query.
*
* @author Christoph Strobl
+ * @author Mark Paluch
* @since 1.6
*/
@ReadOnlyProperty
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/MongoRepositoryTextSearchIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/MongoRepositoryTextSearchIntegrationTests.java
index 7e7f3c1ed..87488703a 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/MongoRepositoryTextSearchIntegrationTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/MongoRepositoryTextSearchIntegrationTests.java
@@ -48,7 +48,7 @@ import org.springframework.util.ObjectUtils;
* @author Mark Paluch
*/
@ExtendWith(MongoTemplateExtension.class)
-public class MongoRepositoryTextSearchIntegrationTests {
+class MongoRepositoryTextSearchIntegrationTests {
private static final FullTextDocument PASSENGER_57 = new FullTextDocument("1", "Passenger 57",
"Passenger 57 is an action film that stars Wesley Snipes and Bruce Payne.");
@@ -58,24 +58,24 @@ public class MongoRepositoryTextSearchIntegrationTests {
"Drop Zone is an action film featuring Wesley Snipes and Gary Busey.");
@Template(initialEntitySet = FullTextDocument.class) //
- static MongoTestTemplate template;
+ private static MongoTestTemplate template;
- FullTextRepository repo = new MongoRepositoryFactory(this.template).getRepository(FullTextRepository.class);
+ private FullTextRepository repo = new MongoRepositoryFactory(this.template).getRepository(FullTextRepository.class);
@BeforeEach
- public void setUp() {
+ void setUp() {
template.indexOps(FullTextDocument.class)
.ensureIndex(new TextIndexDefinitionBuilder().onField("title").onField("content").build());
}
@AfterEach
- public void tearDown() {
+ void tearDown() {
template.flush();
}
@Test // DATAMONGO-973
- public void findAllByTextCriteriaShouldReturnMatchingDocuments() {
+ void findAllByTextCriteriaShouldReturnMatchingDocuments() {
initRepoWithDefaultDocuments();
@@ -86,7 +86,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
}
@Test // DATAMONGO-973
- public void derivedFinderWithTextCriteriaReturnsCorrectResult() {
+ void derivedFinderWithTextCriteriaReturnsCorrectResult() {
initRepoWithDefaultDocuments();
FullTextDocument blade = new FullTextDocument("4", "Blade",
@@ -102,7 +102,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
}
@Test // DATAMONGO-973
- public void findByWithPaginationWorksCorrectlyWhenUsingTextCriteria() {
+ void findByWithPaginationWorksCorrectlyWhenUsingTextCriteria() {
initRepoWithDefaultDocuments();
@@ -116,7 +116,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
}
@Test // DATAMONGO-973
- public void findAllByTextCriteriaWithSortWorksCorrectly() {
+ void findAllByTextCriteriaWithSortWorksCorrectly() {
initRepoWithDefaultDocuments();
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
@@ -130,7 +130,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
}
@Test // DATAMONGO-973
- public void findByWithSortByScoreViaPageRequestTriggersSortingCorrectly() {
+ void findByWithSortByScoreViaPageRequestTriggersSortingCorrectly() {
initRepoWithDefaultDocuments();
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
@@ -144,7 +144,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
}
@Test // DATAMONGO-973
- public void findByWithSortViaPageRequestIgnoresTextScoreWhenSortedByOtherProperty() {
+ void findByWithSortViaPageRequestIgnoresTextScoreWhenSortedByOtherProperty() {
initRepoWithDefaultDocuments();
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
@@ -158,7 +158,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
}
@Test // DATAMONGO-973
- public void derivedSortForTextScorePropertyWorksCorrectly() {
+ void derivedSortForTextScorePropertyWorksCorrectly() {
initRepoWithDefaultDocuments();
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
@@ -170,10 +170,11 @@ public class MongoRepositoryTextSearchIntegrationTests {
}
@Test // DATAMONGO-973, DATAMONGO-2516
- public void derivedFinderMethodWithoutFullTextShouldNoCauseTroubleWhenHavingEntityWithTextScoreProperty() {
+ void derivedFinderMethodWithoutFullTextShouldNoCauseTroubleWhenHavingEntityWithTextScoreProperty() {
initRepoWithDefaultDocuments();
List result = repo.findByTitle(DROP_ZONE.getTitle());
+
assertThat(result.get(0)).isEqualTo(DROP_ZONE);
assertThat(result.get(0).score).isNull();
}
diff --git a/src/main/asciidoc/new-features.adoc b/src/main/asciidoc/new-features.adoc
index e6f2a3873..46f953d76 100644
--- a/src/main/asciidoc/new-features.adoc
+++ b/src/main/asciidoc/new-features.adoc
@@ -11,6 +11,7 @@
* Apply pagination when using GridFS `find(Query)`.
* <> via `@Sharded`.
* `$merge` and `$addFields` aggregation pipeline stages.
+* `@TextScore` is `null` for entities retrieved through non-fulltext queries.
[[new-features.2-2-0]]
== What's New in Spring Data MongoDB 2.2