You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by fo...@apache.org on 2021/05/10 09:56:25 UTC
svn commit: r1889720 - in /jackrabbit/oak/trunk/oak-search-elastic/src:
main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java
test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticDynamicBoostQueryTest.java
Author: fortino
Date: Mon May 10 09:56:25 2021
New Revision: 1889720
URL: http://svn.apache.org/viewvc?rev=1889720&view=rev
Log:
GRANITE-34058: use dynamic boost in must query
Modified:
jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticDynamicBoostQueryTest.java
Modified: jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java?rev=1889720&r1=1889719&r2=1889720&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java (original)
+++ jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java Mon May 10 09:56:25 2021
@@ -569,10 +569,11 @@ public class ElasticRequestHandler {
if (boost != null) {
fullTextQuery.boost(Float.parseFloat(boost));
}
- BoolQueryBuilder boolQueryBuilder = boolQuery().must(fullTextQuery);
- // add dynamic boosts in SHOULD if available
+ BoolQueryBuilder shouldBoolQueryWrapper = boolQuery().should(fullTextQuery);
+ // add dynamic boosts in OR if available
Stream<QueryBuilder> dynamicScoreQueries = dynamicScoreQueries(text);
- dynamicScoreQueries.forEach(boolQueryBuilder::should);
+ dynamicScoreQueries.forEach(shouldBoolQueryWrapper::should);
+ BoolQueryBuilder boolQueryBuilder = boolQuery().must(shouldBoolQueryWrapper);
if (not) {
BoolQueryBuilder bq = boolQuery().mustNot(boolQueryBuilder);
Modified: jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticDynamicBoostQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticDynamicBoostQueryTest.java?rev=1889720&r1=1889719&r2=1889720&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticDynamicBoostQueryTest.java (original)
+++ jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticDynamicBoostQueryTest.java Mon May 10 09:56:25 2021
@@ -106,6 +106,38 @@ public class ElasticDynamicBoostQueryTes
});
}
+ @Test
+ public void dynamicBoostWithAdditionalTags() throws CommitFailedException {
+ configureIndex();
+
+ Tree test = createNodeWithType(root.getTree("/"), "test", NT_UNSTRUCTURED);
+ Tree item1Metadata = createNodeWithMetadata(test, "item1", "flower with a lot of colors");
+ Tree item1Color1 = createNodeWithType(item1Metadata,"color1", NT_UNSTRUCTURED);
+ item1Color1.setProperty("name", "red");
+ item1Color1.setProperty("confidence", 9.0);
+ Tree item1Color2 = createNodeWithType(item1Metadata,"color2", NT_UNSTRUCTURED);
+ item1Color2.setProperty("name", "blue");
+ item1Color2.setProperty("confidence", 1.0);
+
+ Tree item2Metadata = createNodeWithMetadata(test, "item2", "flower with a lot of colors");
+ Tree item2Color1 = createNodeWithType(item2Metadata,"color1", NT_UNSTRUCTURED);
+ item2Color1.setProperty("name", "blue");
+ item2Color1.setProperty("confidence", 9.0);
+ Tree item2Color2 = createNodeWithType(item2Metadata,"color2", NT_UNSTRUCTURED);
+ item2Color2.setProperty("name", "red");
+ item2Color2.setProperty("confidence", 1.0);
+ root.commit();
+
+ assertEventually(() -> {
+ assertQuery("//element(*, dam:Asset)[jcr:contains(@title, 'flower')]",
+ XPATH, Arrays.asList("/test/item1", "/test/item2"));
+ assertOrderedQuery("select [jcr:path] from [dam:Asset] where contains(title, 'red flower')",
+ Arrays.asList("/test/item1", "/test/item2"));
+ assertOrderedQuery("select [jcr:path] from [dam:Asset] where contains(title, 'blue flower')",
+ Arrays.asList("/test/item2", "/test/item1"));
+ });
+ }
+
private void configureIndex() throws CommitFailedException {
NodeTypeRegistry.register(root, toInputStream(ASSET_NODE_TYPE), "test nodeType");
IndexDefinitionBuilder builder = createIndex(true, "dam:Asset", "title", "dynamicBoost");