Skip to content

Commit ae74623

Browse files
committed
StructuredQueryBuilder.word(...) or underlying cts:word-query doesn't work as I thought, it only queries direct child text whereas I wanted more a container query style. Based on that, I'll depend on existing containerQuery(query) and term(...) methods instead
1 parent 00b604d commit ae74623

File tree

3 files changed

+21
-30
lines changed

3 files changed

+21
-30
lines changed

src/main/java/com/marklogic/client/impl/PojoQueryBuilderImpl.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public StructuredQueryDefinition value(String pojoField, String[] options,
105105
return value(jsonProperty(pojoField), null, options, weight, values);
106106
}
107107
}
108-
public StructuredQueryDefinition word(String pojoField, String[] words) {
108+
public StructuredQueryDefinition word(String pojoField, String... words) {
109109
if ( wrapQueries ) {
110110
return super.containerQuery(jsonProperty(classWrapper),
111111
super.word(jsonProperty(pojoField), words));
@@ -123,12 +123,6 @@ public StructuredQueryDefinition word(String pojoField, String[] options,
123123
return super.word(jsonProperty(pojoField), null, options, weight, words);
124124
}
125125
}
126-
public StructuredQueryDefinition word(String... words) {
127-
return super.word(jsonProperty(classWrapper), words);
128-
}
129-
public StructuredQueryDefinition word(String[] options, double weight, String... words) {
130-
return super.word(jsonProperty(classWrapper), null, options, weight, words);
131-
}
132126

133127
public String getRangeIndexType(String fieldName) {
134128
// map java types to acceptable Range Index types

src/main/java/com/marklogic/client/pojo/PojoQueryBuilder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ public StructuredQueryDefinition range(String pojoField, String[] options,
2525
public StructuredQueryDefinition value(String pojoField, String... values);
2626
public StructuredQueryDefinition value(String pojoField, String[] options,
2727
double weight, String... values);
28-
public StructuredQueryDefinition word(String pojoField, String[] words);
28+
public StructuredQueryDefinition word(String pojoField, String... words);
2929
public StructuredQueryDefinition word(String pojoField, String[] options,
3030
double weight, String... words);
31-
public StructuredQueryDefinition word(String... words);
32-
public StructuredQueryDefinition word(String[] options, double weight, String... words);
3331

3432
// All following method signatures copied from StructuredQueryBuilder since it has no interface we can extend
3533
public StructuredQueryDefinition and(StructuredQueryDefinition... queries);

src/test/java/com/marklogic/client/test/PojoFacadeTest.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void testC_QueryPojos() throws Exception {
107107

108108

109109
PojoQueryBuilder<City> qb = cities.getQueryBuilder();
110-
QueryDefinition query = qb.word("Tungi", "Dalatando", "Chittagong");
110+
QueryDefinition query = qb.term("Tungi", "Dalatando", "Chittagong");
111111
page = cities.search(query, 1);
112112
iterator = page.iterator();
113113
numRead = 0;
@@ -130,7 +130,7 @@ public void testC_QueryPojos() throws Exception {
130130
assertEquals("Failed to find number of records expected", 7, numRead);
131131
assertEquals("PojoPage failed to report number of records expected", numRead, page.size());
132132

133-
query = qb.containerQuery("alternateNames", qb.word("San", "Santo"));
133+
query = qb.containerQuery("alternateNames", qb.term("San", "Santo"));
134134
page = cities.search(query, 1);
135135
iterator = page.iterator();
136136
numRead = 0;
@@ -143,6 +143,17 @@ public void testC_QueryPojos() throws Exception {
143143
assertEquals("Failed to find number of records expected", 11, numRead);
144144
assertEquals("PojoPage failed to report number of records expected", numRead, page.size());
145145

146+
query = qb.range("population", Operator.LT, 350000);
147+
page = cities.search(query, 1);
148+
iterator = page.iterator();
149+
numRead = 0;
150+
while ( iterator.hasNext() ) {
151+
City city = iterator.next();
152+
numRead++;
153+
}
154+
assertEquals("Failed to find number of records expected", 21, numRead);
155+
assertEquals("PojoPage failed to report number of records expected", numRead, page.size());
156+
146157
query = qb.geospatial(
147158
qb.geoField("latLong"),
148159
qb.circle(-34, -58, 1)
@@ -190,17 +201,6 @@ public void testC_QueryPojos() throws Exception {
190201
// when this works we'll find out how many we expect
191202
assertEquals("Failed to find number of records expected", -1, numRead);
192203
assertEquals("PojoPage failed to report number of records expected", numRead, page.size());
193-
194-
query = qb.range("population", Operator.LT, 350000);
195-
page = cities.search(query, 1);
196-
iterator = page.iterator();
197-
numRead = 0;
198-
while ( iterator.hasNext() ) {
199-
City city = iterator.next();
200-
numRead++;
201-
}
202-
assertEquals("Failed to find number of records expected", 21, numRead);
203-
assertEquals("PojoPage failed to report number of records expected", numRead, page.size());
204204
}
205205

206206
@Test
@@ -241,17 +241,16 @@ public void testD_PojosWithChildren() throws Exception {
241241
query = countriesQb.range("continent", Operator.EQ, "AS");
242242
assertEquals("Should find two cities", 2, cities.search(query, 1).getTotalSize());
243243

244-
// the following currently don't work even in the cts:search layer
245-
// all countries containing the term "SA"
246-
query = countriesQb.word("SA");
244+
// all countries containing the term SA
245+
query = countriesQb.containerQuery(countriesQb.term("SA"));
247246
assertEquals("Should find one city", 1, cities.search(query, 1).getTotalSize());
248247

249-
// all cities containing the term "SA"
250-
query = qb.word("SA");
251-
assertEquals("Should find two cities", 2, cities.search(query, 1).getTotalSize());
248+
// all cities containing the term SA
249+
query = qb.containerQuery(qb.term("SA"));
250+
assertEquals("Should find two cities", 61, cities.search(query, 1).getTotalSize());
252251

253252
// all countries containing the field "currencyName" with the term "peso"
254-
query = countriesQb.word("currencyName", new String[]{"peso"});
253+
query = countriesQb.word("currencyName", "peso");
255254
assertEquals("Should find one city", 1, cities.search(query, 1).getTotalSize());
256255
}
257256

0 commit comments

Comments
 (0)