Skip to content

Commit 00034d8

Browse files
committed
DATAMONGO-2516 - Polishing.
Reflect nullability change in TextScore Javadoc. Update documentation. Original pull request: spring-projects#856.
1 parent fba6d7d commit 00034d8

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/TextScore.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
/**
2727
* {@link TextScore} marks the property to be considered as the on server calculated {@literal textScore} when doing
2828
* full text search. <br />
29-
* <b>NOTE</b> Property will not be written when saving entity.
29+
* <b>NOTE</b> Property will not be written when saving entity and may be {@literal null} if the document is retrieved
30+
* by a regular (i.e. {@literal $text}) query.
3031
*
3132
* @author Christoph Strobl
33+
* @author Mark Paluch
3234
* @since 1.6
3335
*/
3436
@ReadOnlyProperty

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/MongoRepositoryTextSearchIntegrationTests.java

+14-13
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* @author Mark Paluch
4949
*/
5050
@ExtendWith(MongoTemplateExtension.class)
51-
public class MongoRepositoryTextSearchIntegrationTests {
51+
class MongoRepositoryTextSearchIntegrationTests {
5252

5353
private static final FullTextDocument PASSENGER_57 = new FullTextDocument("1", "Passenger 57",
5454
"Passenger 57 is an action film that stars Wesley Snipes and Bruce Payne.");
@@ -58,24 +58,24 @@ public class MongoRepositoryTextSearchIntegrationTests {
5858
"Drop Zone is an action film featuring Wesley Snipes and Gary Busey.");
5959

6060
@Template(initialEntitySet = FullTextDocument.class) //
61-
static MongoTestTemplate template;
61+
private static MongoTestTemplate template;
6262

63-
FullTextRepository repo = new MongoRepositoryFactory(this.template).getRepository(FullTextRepository.class);
63+
private FullTextRepository repo = new MongoRepositoryFactory(this.template).getRepository(FullTextRepository.class);
6464

6565
@BeforeEach
66-
public void setUp() {
66+
void setUp() {
6767

6868
template.indexOps(FullTextDocument.class)
6969
.ensureIndex(new TextIndexDefinitionBuilder().onField("title").onField("content").build());
7070
}
7171

7272
@AfterEach
73-
public void tearDown() {
73+
void tearDown() {
7474
template.flush();
7575
}
7676

7777
@Test // DATAMONGO-973
78-
public void findAllByTextCriteriaShouldReturnMatchingDocuments() {
78+
void findAllByTextCriteriaShouldReturnMatchingDocuments() {
7979

8080
initRepoWithDefaultDocuments();
8181

@@ -86,7 +86,7 @@ public void findAllByTextCriteriaShouldReturnMatchingDocuments() {
8686
}
8787

8888
@Test // DATAMONGO-973
89-
public void derivedFinderWithTextCriteriaReturnsCorrectResult() {
89+
void derivedFinderWithTextCriteriaReturnsCorrectResult() {
9090

9191
initRepoWithDefaultDocuments();
9292
FullTextDocument blade = new FullTextDocument("4", "Blade",
@@ -102,7 +102,7 @@ public void derivedFinderWithTextCriteriaReturnsCorrectResult() {
102102
}
103103

104104
@Test // DATAMONGO-973
105-
public void findByWithPaginationWorksCorrectlyWhenUsingTextCriteria() {
105+
void findByWithPaginationWorksCorrectlyWhenUsingTextCriteria() {
106106

107107
initRepoWithDefaultDocuments();
108108

@@ -116,7 +116,7 @@ public void findByWithPaginationWorksCorrectlyWhenUsingTextCriteria() {
116116
}
117117

118118
@Test // DATAMONGO-973
119-
public void findAllByTextCriteriaWithSortWorksCorrectly() {
119+
void findAllByTextCriteriaWithSortWorksCorrectly() {
120120

121121
initRepoWithDefaultDocuments();
122122
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
@@ -130,7 +130,7 @@ public void findAllByTextCriteriaWithSortWorksCorrectly() {
130130
}
131131

132132
@Test // DATAMONGO-973
133-
public void findByWithSortByScoreViaPageRequestTriggersSortingCorrectly() {
133+
void findByWithSortByScoreViaPageRequestTriggersSortingCorrectly() {
134134

135135
initRepoWithDefaultDocuments();
136136
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
@@ -144,7 +144,7 @@ public void findByWithSortByScoreViaPageRequestTriggersSortingCorrectly() {
144144
}
145145

146146
@Test // DATAMONGO-973
147-
public void findByWithSortViaPageRequestIgnoresTextScoreWhenSortedByOtherProperty() {
147+
void findByWithSortViaPageRequestIgnoresTextScoreWhenSortedByOtherProperty() {
148148

149149
initRepoWithDefaultDocuments();
150150
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
@@ -158,7 +158,7 @@ public void findByWithSortViaPageRequestIgnoresTextScoreWhenSortedByOtherPropert
158158
}
159159

160160
@Test // DATAMONGO-973
161-
public void derivedSortForTextScorePropertyWorksCorrectly() {
161+
void derivedSortForTextScorePropertyWorksCorrectly() {
162162

163163
initRepoWithDefaultDocuments();
164164
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
@@ -170,10 +170,11 @@ public void derivedSortForTextScorePropertyWorksCorrectly() {
170170
}
171171

172172
@Test // DATAMONGO-973, DATAMONGO-2516
173-
public void derivedFinderMethodWithoutFullTextShouldNoCauseTroubleWhenHavingEntityWithTextScoreProperty() {
173+
void derivedFinderMethodWithoutFullTextShouldNoCauseTroubleWhenHavingEntityWithTextScoreProperty() {
174174

175175
initRepoWithDefaultDocuments();
176176
List<FullTextDocument> result = repo.findByTitle(DROP_ZONE.getTitle());
177+
177178
assertThat(result.get(0)).isEqualTo(DROP_ZONE);
178179
assertThat(result.get(0).score).isNull();
179180
}

src/main/asciidoc/new-features.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Apply pagination when using GridFS `find(Query)`.
1212
* <<sharding,Sharding key derivation>> via `@Sharded`.
1313
* `$merge` and `$addFields` aggregation pipeline stages.
14+
* `@TextScore` is `null` for entities retrieved through non-fulltext queries.
1415

1516
[[new-features.2-2-0]]
1617
== What's New in Spring Data MongoDB 2.2

0 commit comments

Comments
 (0)