From ca1960c2bfab0184509b632534bf687c56d54021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rene=CC=81=20Kriegler?= Date: Wed, 21 Dec 2022 14:26:32 +0100 Subject: [PATCH] Updating json-path #44 --- pom.xml | 13 ++++ .../querqy/elasticsearch/query/Rewriter.java | 2 +- .../SimpleCommonRulesRewriterFactoryTest.java | 61 +++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ddd8d5b..20b8953 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,7 @@ 2.27.0 0.8 1.19.0 + 2.7.0 5.5.lucene900.1 8 @@ -71,6 +72,18 @@ org.querqy querqy-lucene ${querqy.lucene.version} + + + com.jayway.jsonpath + json-path + + + + + + com.jayway.jsonpath + json-path + ${json-path.version} diff --git a/src/main/java/querqy/elasticsearch/query/Rewriter.java b/src/main/java/querqy/elasticsearch/query/Rewriter.java index f05ccac..367b238 100644 --- a/src/main/java/querqy/elasticsearch/query/Rewriter.java +++ b/src/main/java/querqy/elasticsearch/query/Rewriter.java @@ -104,7 +104,7 @@ public Map getParams() { return params; } - public void setParams(Map params) { + public void setParams(final Map params) { this.params = params; } diff --git a/src/test/java/querqy/elasticsearch/rewriter/SimpleCommonRulesRewriterFactoryTest.java b/src/test/java/querqy/elasticsearch/rewriter/SimpleCommonRulesRewriterFactoryTest.java index 995e305..10d0eee 100644 --- a/src/test/java/querqy/elasticsearch/rewriter/SimpleCommonRulesRewriterFactoryTest.java +++ b/src/test/java/querqy/elasticsearch/rewriter/SimpleCommonRulesRewriterFactoryTest.java @@ -69,5 +69,66 @@ public void testBooleanInput() throws ExecutionException, InterruptedException { } + public void testRuleSelectionCriteria() throws ExecutionException, InterruptedException { + indexDocs( + doc("id", "1", "field1", "a"), + doc("id", "2", "field1", "c") + ); + + final Map content = new HashMap<>(); + content.put("class", SimpleCommonRulesRewriterFactory.class.getName()); + + final Map config = new HashMap<>(); + config.put("allowBooleanInput", true); + config.put("rules", "a=>\nSYNONYM: c\n@lang:\"l1\""); + content.put("config", config); + + final PutRewriterRequest request = new PutRewriterRequest("common_rules", content); + + client().execute(PutRewriterAction.INSTANCE, request).get(); + + QuerqyQueryBuilder querqyQuery = new QuerqyQueryBuilder(getInstanceFromNode(QuerqyProcessor.class)); + + final Map criteria = new HashMap<>(); + criteria.put("filter", "$[?(@.lang == 'l1')]"); + final Map params = new HashMap<>(); + params.put("criteria", criteria); + + final Rewriter rewriter = new Rewriter("common_rules"); + rewriter.setParams(params); + + querqyQuery.setRewriters(singletonList(rewriter)); + querqyQuery.setMatchingQuery(new MatchingQuery("a")); + querqyQuery.setMinimumShouldMatch("1"); + querqyQuery.setQueryFieldsAndBoostings(singletonList("field1")); + + SearchRequestBuilder searchRequestBuilder = client().prepareSearch(getIndexName()); + searchRequestBuilder.setQuery(querqyQuery); + + SearchResponse response = client().search(searchRequestBuilder.request()).get(); + SearchHits hits = response.getHits(); + + assertEquals(2L, hits.getTotalHits().value); + + + querqyQuery = new QuerqyQueryBuilder(getInstanceFromNode(QuerqyProcessor.class)); + criteria.put("filter", "$[?(@.lang == 'l2')]"); + + querqyQuery.setRewriters(singletonList(rewriter)); + querqyQuery.setMatchingQuery(new MatchingQuery("a")); + querqyQuery.setMinimumShouldMatch("1"); + querqyQuery.setQueryFieldsAndBoostings(singletonList("field1")); + + searchRequestBuilder = client().prepareSearch(getIndexName()); + searchRequestBuilder.setQuery(querqyQuery); + + response = client().search(searchRequestBuilder.request()).get(); + hits = response.getHits(); + + assertEquals(1L, hits.getTotalHits().value); + + + + } } \ No newline at end of file