Skip to content

Added support for zero and random #1730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<RowRecord> rows = resultRows(op.fromSearchDocs(op.cts.wordQuery("saxophone"), null, options));
assertEquals(2, rows.size());
}
Expand All @@ -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<RowRecord> rows = resultRows(op.fromSearchDocs(op.cts.wordQuery("saxophone"), null, options));
assertEquals(2, rows.size());
}
Expand Down