Skip to content

Commit 82b468f

Browse files
authored
Merge pull request #1730 from marklogic/feature/more-score-methods
Added support for zero and random
2 parents fb8baf0 + 08b0f93 commit 82b468f

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group=com.marklogic
2-
version=7.0-SNAPSHOT
2+
version=7.1-SNAPSHOT
33
describedName=MarkLogic Java Client API
44
publishUrl=file:../marklogic-java/releases
55

marklogic-client-api/src/main/java/com/marklogic/client/type/PlanSearchOptions.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,50 @@
88
* for a row pipeline.
99
*/
1010
public interface PlanSearchOptions {
11+
1112
/**
1213
* Changed in release 7.0.0 to return a float, as the server requires a float and throws an error on a double.
1314
*/
1415
XsFloatVal getQualityWeight();
15-
ScoreMethod getScoreMethod();
16+
17+
ScoreMethod getScoreMethod();
18+
1619
/**
1720
* @since 7.0.0; requires MarkLogic 12 or higher.
1821
*/
1922
XsDoubleVal getBm25LengthWeight();
23+
2024
/**
2125
* Changed in release 7.0.0 to return a float, as the server requires a float and throws an error on a double.
2226
*/
23-
PlanSearchOptions withQualityWeight(float qualityWeight);
27+
PlanSearchOptions withQualityWeight(float qualityWeight);
28+
2429
/**
2530
* Changed in release 7.0.0 to return a float, as the server requires a float and throws an error on a double.
2631
*/
27-
PlanSearchOptions withQualityWeight(XsFloatVal qualityWeight);
28-
PlanSearchOptions withScoreMethod(ScoreMethod scoreMethod);
32+
PlanSearchOptions withQualityWeight(XsFloatVal qualityWeight);
33+
34+
PlanSearchOptions withScoreMethod(ScoreMethod scoreMethod);
35+
2936
/**
3037
* @since 7.0.0; requires MarkLogic 12 or higher.
3138
*/
3239
PlanSearchOptions withBm25LengthWeight(double bm25LengthWeight);
33-
enum ScoreMethod {
34-
LOGTFIDF, LOGTF, SIMPLE, BM25;
35-
// zero and random aren't in the 12 EA release.
36-
//ZERO, RANDOM;
37-
}
40+
41+
enum ScoreMethod {
42+
LOGTFIDF,
43+
LOGTF,
44+
SIMPLE,
45+
BM25,
46+
47+
/**
48+
* @since 7.1.0; requires MarkLogic 12 EA2 or higher.
49+
*/
50+
ZERO,
51+
52+
/**
53+
* @since 7.1.0; requires MarkLogic 12 EA2 or higher.
54+
*/
55+
RANDOM;
56+
}
3857
}

marklogic-client-api/src/test/java/com/marklogic/client/test/rows/FromSearchDocsWithOptionsTest.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,39 @@
88
import com.marklogic.client.test.Common;
99
import com.marklogic.client.test.junit5.RequiresML12;
1010
import com.marklogic.client.type.PlanSearchOptions;
11+
import org.junit.jupiter.api.BeforeEach;
1112
import org.junit.jupiter.api.Disabled;
1213
import org.junit.jupiter.api.Test;
1314
import org.junit.jupiter.api.extension.ExtendWith;
15+
import org.junit.jupiter.params.ParameterizedTest;
16+
import org.junit.jupiter.params.provider.ValueSource;
1417

1518
import java.util.List;
1619

1720
import static org.junit.jupiter.api.Assertions.assertEquals;
1821

22+
/**
23+
* These tests do not attempt to verify that a score method produces a particular ordering. Instead, they verify
24+
* that each score method option is accepted by the server.
25+
*/
1926
@ExtendWith(RequiresML12.class)
2027
class FromSearchDocsWithOptionsTest extends AbstractOpticUpdateTest {
2128

22-
@Test
23-
void bm25() {
24-
// Note that this does not actually test that the scoring is correct.
25-
// It only tests that including the BM25 scoring option and a valid bm25LengthWeight do not cause any problems.
29+
@BeforeEach
30+
void setupTest() {
2631
rowManager.withUpdate(false);
32+
}
33+
34+
@ValueSource(strings = {"bm25", "zero", "random", "simple", "logtfidf", "logtf"})
35+
@ParameterizedTest
36+
void scoreMethod(String scoreMethod) {
2737
PlanSearchOptions options = op.searchOptions()
28-
.withScoreMethod(PlanSearchOptions.ScoreMethod.BM25)
29-
.withBm25LengthWeight(0.25);
38+
.withScoreMethod(PlanSearchOptions.ScoreMethod.valueOf(scoreMethod.toUpperCase()));
39+
40+
if ("bm25".equalsIgnoreCase(scoreMethod)) {
41+
options.withBm25LengthWeight(0.25);
42+
}
43+
3044
List<RowRecord> rows = resultRows(op.fromSearchDocs(op.cts.wordQuery("saxophone"), null, options));
3145
assertEquals(2, rows.size());
3246
}
@@ -47,10 +61,9 @@ void bm25ViaSearchOptions() {
4761

4862
@Test
4963
void qualityWeight() {
50-
// Note that this does not actually test that the scoring is correct.
51-
// It only tests that including a valid qualityWeight value does not cause any problems.
52-
rowManager.withUpdate(false);
53-
PlanSearchOptions options = op.searchOptions().withScoreMethod(PlanSearchOptions.ScoreMethod.LOGTFIDF).withQualityWeight(0.75F);
64+
PlanSearchOptions options = op.searchOptions()
65+
.withScoreMethod(PlanSearchOptions.ScoreMethod.LOGTFIDF)
66+
.withQualityWeight(0.75F);
5467
List<RowRecord> rows = resultRows(op.fromSearchDocs(op.cts.wordQuery("saxophone"), null, options));
5568
assertEquals(2, rows.size());
5669
}

0 commit comments

Comments
 (0)