Skip to content

Commit ec2394c

Browse files
author
Anton Hosgood
committed
feat: add dynamic boost test
1 parent 8472821 commit ec2394c

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/dynamicBoost/LuceneDynamicBoostTest.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,37 @@ public void dynamicBoostLiteShouldGiveLessRelevanceToTags() throws Exception {
184184
List.of("/test/asset3", "/test/asset2"));
185185
}
186186

187+
@Test
188+
public void dynamicBoostMaxLengthFiltering() throws Exception {
189+
createAssetsIndexAndProperties(false, false, true, 10);
190+
191+
Tree testParent = createNodeWithType(root.getTree("/"), "test", JcrConstants.NT_UNSTRUCTURED, "");
192+
193+
Tree predicted1 = createAssetNodeWithPredicted(testParent, "asset1", "test");
194+
createPredictedTag(predicted1, "short", 0.9);
195+
createPredictedTag(predicted1, "exactly10!", 0.8);
196+
createPredictedTag(predicted1, "this is too long", 0.7);
197+
198+
Tree predicted2 = createAssetNodeWithPredicted(testParent, "asset2", "test");
199+
createPredictedTag(predicted2, "short", 0.9);
200+
createPredictedTag(predicted2, "exactly10!", 0.8);
201+
202+
root.commit();
203+
204+
assertEventually(() -> {
205+
assertQuery("select [jcr:path] from [dam:Asset] where contains(*, 'short')", SQL2,
206+
List.of("/test/asset1", "/test/asset2"));
207+
assertQuery("select [jcr:path] from [dam:Asset] where contains(*, 'exactly10!')", SQL2,
208+
List.of("/test/asset1", "/test/asset2"));
209+
210+
assertQuery("select [jcr:path] from [dam:Asset] where contains(*, 'this is too long')", SQL2, List.of());
211+
});
212+
}
213+
187214
@Override
188-
protected void createAssetsIndexAndProperties(boolean lite, boolean similarityTags) throws Exception {
215+
protected void createAssetsIndexAndProperties(boolean lite, boolean similarityTags, boolean useInFullTextQuery, Integer maxTagLength) throws Exception {
189216
factory.queryTermsProvider = new FulltextQueryTermsProviderImpl();
190-
super.createAssetsIndexAndProperties(lite, similarityTags);
217+
super.createAssetsIndexAndProperties(lite, similarityTags, useInFullTextQuery, maxTagLength);
191218
}
192219

193220
private String runIndexingTest(Class<?> loggerClass, boolean nameProperty) throws CommitFailedException {

oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/DynamicBoostCommonTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ protected void createAssetsIndexAndProperties(boolean lite, boolean similarityTa
234234
}
235235

236236
protected void createAssetsIndexAndProperties(boolean lite, boolean similarityTags, boolean useInFullTextQuery) throws Exception {
237+
createAssetsIndexAndProperties(lite, similarityTags, useInFullTextQuery, null);
238+
}
239+
240+
protected void createAssetsIndexAndProperties(boolean lite, boolean similarityTags, boolean useInFullTextQuery, Integer maxTagLength) throws Exception {
237241
NodeTypeRegistry.register(root, new ByteArrayInputStream(ASSET_NODE_TYPE.getBytes()), "test nodeType");
238242
Tree indexRuleProps = createIndex("dam:Asset", lite);
239243

@@ -250,6 +254,11 @@ protected void createAssetsIndexAndProperties(boolean lite, boolean similarityTa
250254
predictedTags.setProperty("similarityTags", true);
251255
}
252256

257+
if (maxTagLength != null) {
258+
Tree indexDef = root.getTree("/oak:index/" + TEST_INDEX_NAME);
259+
indexDef.setProperty(FulltextIndexConstants.MAX_TAG_LENGTH, maxTagLength);
260+
}
261+
253262
root.commit();
254263
}
255264

oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinitionTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -514,31 +514,31 @@ public void customTikaMimeTypes() {
514514
}
515515

516516
@Test
517-
public void maxExtractLength() {
517+
public void similarityTagMaxLength() {
518518
NodeBuilder defnb = newFTIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo",
519519
"lucene", Set.of(TYPENAME_STRING));
520520
IndexDefinition defn = new IndexDefinition(root, defnb.getNodeState(), "/foo");
521-
assertEquals(-IndexDefinition.DEFAULT_MAX_EXTRACT_LENGTH * IndexDefinition.DEFAULT_MAX_FIELD_LENGTH,
522-
defn.getMaxExtractLength());
523-
521+
assertEquals(IndexDefinition.DEFAULT_MAX_TAG_LENGTH, defn.getMaxTagLength());
524522

525-
defnb.child(TIKA).setProperty(FulltextIndexConstants.TIKA_MAX_EXTRACT_LENGTH, 1000);
523+
defnb.setProperty(FulltextIndexConstants.MAX_TAG_LENGTH, 50);
526524

527525
defn = new IndexDefinition(root, defnb.getNodeState(), "/foo");
528-
assertEquals(1000, defn.getMaxExtractLength());
526+
assertEquals(50, defn.getMaxTagLength());
529527
}
530528

531529
@Test
532-
public void similarityTagMaxLength() {
530+
public void maxExtractLength() {
533531
NodeBuilder defnb = newFTIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo",
534532
"lucene", Set.of(TYPENAME_STRING));
535533
IndexDefinition defn = new IndexDefinition(root, defnb.getNodeState(), "/foo");
536-
assertEquals(IndexDefinition.DEFAULT_MAX_TAG_LENGTH, defn.getMaxTagLength());
534+
assertEquals(-IndexDefinition.DEFAULT_MAX_EXTRACT_LENGTH * IndexDefinition.DEFAULT_MAX_FIELD_LENGTH,
535+
defn.getMaxExtractLength());
537536

538-
defnb.setProperty(FulltextIndexConstants.MAX_TAG_LENGTH, 50);
537+
538+
defnb.child(TIKA).setProperty(FulltextIndexConstants.TIKA_MAX_EXTRACT_LENGTH, 1000);
539539

540540
defn = new IndexDefinition(root, defnb.getNodeState(), "/foo");
541-
assertEquals(50, defn.getMaxTagLength());
541+
assertEquals(1000, defn.getMaxExtractLength());
542542
}
543543

544544
@Test(expected = IllegalStateException.class)

0 commit comments

Comments
 (0)