20
20
import static org .springframework .data .solr .core .query .Criteria .*;
21
21
import static org .springframework .data .solr .core .query .ExistsFunction .*;
22
22
23
- import java .util .ArrayList ;
24
23
import java .util .Arrays ;
25
- import java .util .List ;
26
24
27
25
import org .junit .ClassRule ;
28
26
import org .junit .Test ;
44
42
45
43
/**
46
44
* @author Christoph Strobl
45
+ * @author Oliver Gierke
47
46
*/
48
47
@ RunWith (SpringJUnit4ClassRunner .class )
49
48
@ ContextConfiguration
@@ -57,22 +56,18 @@ static class Config extends SolrTestConfiguration {
57
56
@ Override
58
57
protected void doInitTestData (CrudRepository <Product , String > repository ) {
59
58
60
- Product playstation = new ProductBuilder ().withId ("id-1" ).named ("Playstation" )
61
- .withDescription ("The Sony playstation was the top selling gaming system in 1994." ).withPopularity (5 ).build ();
62
-
63
- Product playstation2 = new ProductBuilder ().withId ("id-2" ).named ("Playstation Two" )
64
- .withDescription ("Playstation two is the successor of playstation in 2000." ).build ();
65
-
66
- Product superNES = new ProductBuilder ().withId ("id-3" ).named ("Super Nintendo" ).withPopularity (3 ).build ();
67
-
68
- Product nintendo64 = new ProductBuilder ().withId ("id-4" ).named ("N64" ).withDescription ("Nintendo 64" )
69
- .withPopularity (2 ).build ();
59
+ Product playstation = Product .builder ().id ("id-1" ).name ("Playstation" )
60
+ .description ("The Sony playstation was the top selling gaming system in 1994." ).popularity (5 ).build ();
61
+ Product playstation2 = Product .builder ().id ("id-2" ).name ("Playstation Two" )
62
+ .description ("Playstation two is the successor of playstation in 2000." ).build ();
63
+ Product superNES = Product .builder ().id ("id-3" ).name ("Super Nintendo" ).popularity (3 ).build ();
64
+ Product nintendo64 = Product .builder ().id ("id-4" ).name ("N64" ).description ("Nintendo 64" ).popularity (2 ).build ();
70
65
71
66
repository .save (Arrays .asList (playstation , playstation2 , superNES , nintendo64 ));
72
67
}
73
68
}
74
69
75
- @ Autowired ProductRepository repo ;
70
+ @ Autowired ProductRepository repository ;
76
71
@ Autowired SolrOperations operations ;
77
72
78
73
/**
@@ -82,7 +77,7 @@ protected void doInitTestData(CrudRepository<Product, String> repository) {
82
77
@ Test
83
78
public void annotationBasedHighlighting () {
84
79
85
- HighlightPage <Product > products = repo .findByDescriptionStartingWith ("play" , new PageRequest (0 , 10 ));
80
+ HighlightPage <Product > products = repository .findByDescriptionStartingWith ("play" , new PageRequest (0 , 10 ));
86
81
87
82
products .getHighlighted ().forEach (
88
83
entry -> entry .getHighlights ().forEach (
@@ -96,9 +91,7 @@ public void annotationBasedHighlighting() {
96
91
*/
97
92
@ Test
98
93
public void annotationBasedBoosting () {
99
-
100
- repo .findTop10ByNameOrDescription ("Nintendo" , "Nintendo" ) //
101
- .forEach (System .out ::println );
94
+ repository .findTop10ByNameOrDescription ("Nintendo" , "Nintendo" ).forEach (System .out ::println );
102
95
}
103
96
104
97
/**
@@ -109,9 +102,9 @@ public void annotationBasedBoosting() {
109
102
@ Test
110
103
public void influcenceScoreWithFunctions () {
111
104
112
- operations . queryForPage ( new SimpleQuery (where (exists ("popularity" ))).addProjectionOnFields ("*" , "score" ),
113
- Product . class ) //
114
- .forEach (System .out ::println );
105
+ Query query = new SimpleQuery (where (exists ("popularity" ))).addProjectionOnFields ("*" , "score" );
106
+
107
+ operations . queryForPage ( query , Product . class ) .forEach (System .out ::println );
115
108
}
116
109
117
110
/**
@@ -121,8 +114,7 @@ public void influcenceScoreWithFunctions() {
121
114
@ Test
122
115
public void useRealtimeGetToReadUncommitedDocuments () throws InterruptedException {
123
116
124
- Product xbox = new ProductBuilder ().withId ("id-5" ).named ("XBox" ).withDescription ("Microsift XBox" )
125
- .withPopularity (2 ).build ();
117
+ Product xbox = Product .builder ().id ("id-5" ).name ("XBox" ).description ("Microsift XBox" ).popularity (2 ).build ();
126
118
Query query = new SimpleQuery (where ("id" ).is (xbox .getId ()));
127
119
128
120
// add document but delay commit for 3 seconds
@@ -138,52 +130,4 @@ public void useRealtimeGetToReadUncommitedDocuments() throws InterruptedExceptio
138
130
Thread .sleep (3010 );
139
131
assertThat (operations .queryForObject (query , Product .class ), notNullValue ());
140
132
}
141
-
142
- static class ProductBuilder {
143
-
144
- private Product product ;
145
-
146
- public ProductBuilder () {
147
- this .product = new Product ();
148
- }
149
-
150
- public ProductBuilder withId (String id ) {
151
- this .product .setId (id );
152
- return this ;
153
- }
154
-
155
- public ProductBuilder named (String name ) {
156
- this .product .setName (name );
157
- return this ;
158
- }
159
-
160
- public ProductBuilder withDescription (String description ) {
161
- this .product .setDescription (description );
162
- return this ;
163
- }
164
-
165
- public ProductBuilder withPopularity (Integer popularity ) {
166
- this .product .setPopularity (popularity );
167
- return this ;
168
- }
169
-
170
- public ProductBuilder inCategory (String category ) {
171
-
172
- List <String > categories = new ArrayList <>();
173
- categories .add (category );
174
-
175
- if (this .product .getCategory () == null ) {
176
- categories .addAll (this .product .getCategory ());
177
- }
178
-
179
- this .product .setCategory (categories );
180
- return this ;
181
-
182
- }
183
-
184
- public Product build () {
185
- return this .product ;
186
- }
187
-
188
- }
189
133
}
0 commit comments