diff --git a/gradle.properties b/gradle.properties index ed8022bc0..d2af75728 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=com.marklogic -version=7.0-SNAPSHOT +version=7.1-SNAPSHOT describedName=MarkLogic Java Client API publishUrl=file:../marklogic-java/releases diff --git a/marklogic-client-api/src/main/java/com/marklogic/client/type/PlanSearchOptions.java b/marklogic-client-api/src/main/java/com/marklogic/client/type/PlanSearchOptions.java index ef07719c6..197163c84 100644 --- a/marklogic-client-api/src/main/java/com/marklogic/client/type/PlanSearchOptions.java +++ b/marklogic-client-api/src/main/java/com/marklogic/client/type/PlanSearchOptions.java @@ -8,31 +8,50 @@ * for a row pipeline. */ public interface PlanSearchOptions { + /** * Changed in release 7.0.0 to return a float, as the server requires a float and throws an error on a double. */ XsFloatVal getQualityWeight(); - ScoreMethod getScoreMethod(); + + ScoreMethod getScoreMethod(); + /** * @since 7.0.0; requires MarkLogic 12 or higher. */ XsDoubleVal getBm25LengthWeight(); + /** * Changed in release 7.0.0 to return a float, as the server requires a float and throws an error on a double. */ - PlanSearchOptions withQualityWeight(float qualityWeight); + PlanSearchOptions withQualityWeight(float qualityWeight); + /** * Changed in release 7.0.0 to return a float, as the server requires a float and throws an error on a double. */ - PlanSearchOptions withQualityWeight(XsFloatVal qualityWeight); - PlanSearchOptions withScoreMethod(ScoreMethod scoreMethod); + PlanSearchOptions withQualityWeight(XsFloatVal qualityWeight); + + PlanSearchOptions withScoreMethod(ScoreMethod scoreMethod); + /** * @since 7.0.0; requires MarkLogic 12 or higher. */ PlanSearchOptions withBm25LengthWeight(double bm25LengthWeight); - enum ScoreMethod { - LOGTFIDF, LOGTF, SIMPLE, BM25; - // zero and random aren't in the 12 EA release. - //ZERO, RANDOM; - } + + enum ScoreMethod { + LOGTFIDF, + LOGTF, + SIMPLE, + BM25, + + /** + * @since 7.1.0; requires MarkLogic 12 EA2 or higher. + */ + ZERO, + + /** + * @since 7.1.0; requires MarkLogic 12 EA2 or higher. + */ + RANDOM; + } } diff --git a/marklogic-client-api/src/test/java/com/marklogic/client/test/rows/FromSearchDocsWithOptionsTest.java b/marklogic-client-api/src/test/java/com/marklogic/client/test/rows/FromSearchDocsWithOptionsTest.java index 56d28394d..120e5c2db 100644 --- a/marklogic-client-api/src/test/java/com/marklogic/client/test/rows/FromSearchDocsWithOptionsTest.java +++ b/marklogic-client-api/src/test/java/com/marklogic/client/test/rows/FromSearchDocsWithOptionsTest.java @@ -8,25 +8,39 @@ import com.marklogic.client.test.Common; import com.marklogic.client.test.junit5.RequiresML12; import com.marklogic.client.type.PlanSearchOptions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; +/** + * These tests do not attempt to verify that a score method produces a particular ordering. Instead, they verify + * that each score method option is accepted by the server. + */ @ExtendWith(RequiresML12.class) class FromSearchDocsWithOptionsTest extends AbstractOpticUpdateTest { - @Test - void bm25() { -// Note that this does not actually test that the scoring is correct. -// It only tests that including the BM25 scoring option and a valid bm25LengthWeight do not cause any problems. + @BeforeEach + void setupTest() { rowManager.withUpdate(false); + } + + @ValueSource(strings = {"bm25", "zero", "random", "simple", "logtfidf", "logtf"}) + @ParameterizedTest + void scoreMethod(String scoreMethod) { PlanSearchOptions options = op.searchOptions() - .withScoreMethod(PlanSearchOptions.ScoreMethod.BM25) - .withBm25LengthWeight(0.25); + .withScoreMethod(PlanSearchOptions.ScoreMethod.valueOf(scoreMethod.toUpperCase())); + + if ("bm25".equalsIgnoreCase(scoreMethod)) { + options.withBm25LengthWeight(0.25); + } + List rows = resultRows(op.fromSearchDocs(op.cts.wordQuery("saxophone"), null, options)); assertEquals(2, rows.size()); } @@ -47,10 +61,9 @@ void bm25ViaSearchOptions() { @Test void qualityWeight() { -// Note that this does not actually test that the scoring is correct. -// It only tests that including a valid qualityWeight value does not cause any problems. - rowManager.withUpdate(false); - PlanSearchOptions options = op.searchOptions().withScoreMethod(PlanSearchOptions.ScoreMethod.LOGTFIDF).withQualityWeight(0.75F); + PlanSearchOptions options = op.searchOptions() + .withScoreMethod(PlanSearchOptions.ScoreMethod.LOGTFIDF) + .withQualityWeight(0.75F); List rows = resultRows(op.fromSearchDocs(op.cts.wordQuery("saxophone"), null, options)); assertEquals(2, rows.size()); }