Skip to content

Commit

Permalink
morph TestFieldValueFeature.query into addAndQueryId21
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoerschke committed Sep 8, 2023
1 parent ae6d160 commit 1a5b7b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -528,18 +528,13 @@ public void testThatCorrectFieldValueFeatureIsUsedForDocValueTypes() throws Exce
final String fstore = "testThatCorrectFieldValueFeatureIsUsedForDocValueTypes" + field;
final String modelName = field + "-model";

assertU(adoc("id", "21", field, fieldValue));
assertU(commit());

loadFeatureAndModel(getObservingFieldValueFeatureClassName(), field, fstore, modelName);

query(field, modelName);

assertEquals(fieldAndScorerClass[2], ObservingFieldValueFeature.usedScorerClass);
addAndQueryId21(field, modelName, fieldAndScorerClass[2], fieldValue);
}
}

void loadFeatureAndModel(String featureClassName, String field, String fstore, String modelName) throws Exception {
protected void loadFeatureAndModel(String featureClassName, String field, String fstore, String modelName) throws Exception {
loadFeature(
field, featureClassName, fstore, "{\"field\":\"" + field + "\"}");

Expand All @@ -551,7 +546,11 @@ void loadFeatureAndModel(String featureClassName, String field, String fstore, S
"{\"weights\":{\"" + field + "\":1.0}}");
}

void query(String field, String modelName) throws Exception {
protected void addAndQueryId21(String field, String modelName, String expectedUsedScorerClass, String fieldValue) throws Exception {

assertU(adoc("id", "21", field, fieldValue));
assertU(commit());

final SolrQuery query = new SolrQuery("id:21");
query.add("rq", "{!ltr model=" + modelName + " reRankDocs=4}");
query.add("fl", "[fv]");
Expand All @@ -563,6 +562,8 @@ void query(String field, String modelName) throws Exception {
"/response/docs/[0]/=={'[fv]':'"
+ FeatureLoggerTestUtils.toFeatureVector(field, "1.0")
+ "'}");

assertEquals(expectedUsedScorerClass, ObservingFieldValueFeature.usedScorerClass);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,22 @@ protected String storedDvIsTrendy_FieldValueFeatureScorer_className() {
public void test_LegacyFieldValueFeature_behavesDifferentlyThan_FieldValueFeature() throws Exception {
// the field storedDvIsTrendy has stored=true and docValues=true
final String field = "storedDvIsTrendy";
final String fieldValue = "1";
String fstore = "test_LegacyFieldValueFeature_behavesDifferentlyThan_FieldValueFeature" + field;

assertU(adoc("id", "21", field, fieldValue));
assertU(commit());
// demonstrate that & how the FieldValueFeature & LegacyFieldValueFeature implementations differ

// the LegacyFieldValueFeature does not use docValues
loadAndQuery(getObservingFieldValueFeatureClassName(), field, fstore);

String legacyScorerClass = ObservingFieldValueFeature.usedScorerClass;
assertEquals(
FieldValueFeature.FieldValueFeatureWeight.FieldValueFeatureScorer.class.getName(),
legacyScorerClass);
loadAndQuery(getObservingFieldValueFeatureClassName(), field, FieldValueFeature.FieldValueFeatureWeight.FieldValueFeatureScorer.class.getName());

// the FieldValueFeature does use docValues
loadAndQuery(super.getObservingFieldValueFeatureClassName(), field, fstore);

String scorerClass = ObservingFieldValueFeature.usedScorerClass;
assertEquals(
FieldValueFeature.FieldValueFeatureWeight.SortedDocValuesFieldValueFeatureScorer.class.getName(),
scorerClass);
loadAndQuery(super.getObservingFieldValueFeatureClassName(), field, FieldValueFeature.FieldValueFeatureWeight.SortedDocValuesFieldValueFeatureScorer.class.getName());
}

void loadAndQuery(String featureClassName, String field, String fstore) throws Exception {
private void loadAndQuery(String featureClassName, String field, String expectedUsedScorerClass) throws Exception {
final String modelName = field + "-model-" + featureClassName;
final String featureStoreName = fstore + featureClassName;
final String featureStoreName = "test_LegacyFieldValueFeature_behavesDifferentlyThan_FieldValueFeature_" + field + "_" + featureClassName;

loadFeatureAndModel(featureClassName, field, featureStoreName, modelName);

query(field, modelName);
addAndQueryId21(field, modelName, expectedUsedScorerClass, "1");
}
}

0 comments on commit 1a5b7b7

Please sign in to comment.