This is an automated email from the ASF dual-hosted git repository.
fortino pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 057a0de357 OAK-9829: always add filter on FV field to prevent plugin
failures (#613)
057a0de357 is described below
commit 057a0de357003bac0f6d1e9515280b1d847b6b37
Author: Fabrizio Fortino <[email protected]>
AuthorDate: Sat Jul 9 07:59:08 2022 +0200
OAK-9829: always add filter on FV field to prevent plugin failures (#613)
---
.../oak/plugins/index/elastic/query/ElasticRequestHandler.java | 9 ++++++---
.../oak/plugins/index/elastic/ElasticSimilarQueryTest.java | 9 ++++++++-
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git
a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java
b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java
index 4f026ef314..41cee6ba11 100644
---
a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java
+++
b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java
@@ -317,9 +317,10 @@ public class ElasticRequestHandler {
continue;
}
+ String similarityPropFieldName =
FieldNames.createSimilarityFieldName(pd.name);
String knnQuery = "{" +
" \"elastiknn_nearest_neighbors\": {" +
- " \"field\": \"" +
FieldNames.createSimilarityFieldName(pd.name) + "\"," +
+ " \"field\": \"" + similarityPropFieldName + "\"," +
" \"model\": \"" +
pd.getSimilaritySearchParameters().getQueryModel() + "\"," +
" \"similarity\": \"" +
pd.getSimilaritySearchParameters().getQueryTimeSimilarityFunction() + "\"," +
" \"candidates\": " +
pd.getSimilaritySearchParameters().getCandidates() + "," +
@@ -332,8 +333,10 @@ public class ElasticRequestHandler {
" }" +
"}";
- query.should(s -> s
- .wrapper(w ->
w.query(Base64.getEncoder().encodeToString(knnQuery.getBytes(StandardCharsets.UTF_8))))
+ query
+ .filter(fb -> fb.exists(ef ->
ef.field(similarityPropFieldName)))
+ .should(s -> s
+ .wrapper(w ->
w.query(Base64.getEncoder().encodeToString(knnQuery.getBytes(StandardCharsets.UTF_8))))
);
}
}
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSimilarQueryTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSimilarQueryTest.java
index 0b7868254a..eaaa34d3b9 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSimilarQueryTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSimilarQueryTest.java
@@ -33,6 +33,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
import java.nio.charset.Charset;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -302,7 +303,7 @@ public class ElasticSimilarQueryTest extends
ElasticAbstractQueryTest {
File file = new File(uri);
Collection<String> children = new LinkedList<>();
- for (String line : IOUtils.readLines(new FileInputStream(file),
Charset.defaultCharset())) {
+ for (String line :
IOUtils.readLines(Files.newInputStream(file.toPath()),
Charset.defaultCharset())) {
String[] split = line.split(",");
List<Double> values =
Arrays.stream(split).skip(1).map(Double::parseDouble).collect(Collectors.toList());
byte[] bytes = toByteArray(values);
@@ -315,6 +316,12 @@ public class ElasticSimilarQueryTest extends
ElasticAbstractQueryTest {
child.setProperty("fv", blob, Type.BINARY);
children.add(child.getPath());
}
+
+ // add a node without FV, the plugin cannot handle it directly
+ Tree child = test.addChild("nofv");
+ child.setProperty("nofv", "test");
+ children.add(child.getPath());
+
root.commit();
// check that similarity changes across different feature vectors