Skip to content

Commit

Permalink
Updating json-path #44
Browse files Browse the repository at this point in the history
  • Loading branch information
renekrie committed Jan 5, 2023
1 parent 96d4421 commit ca1960c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<mockito.version>2.27.0</mockito.version>
<spatial4j.version>0.8</spatial4j.version>
<jts.version>1.19.0</jts.version>
<json-path.version>2.7.0</json-path.version>

<querqy.lucene.version>5.5.lucene900.1</querqy.lucene.version>
<es.major.version>8</es.major.version>
Expand All @@ -71,6 +72,18 @@
<groupId>org.querqy</groupId>
<artifactId>querqy-lucene</artifactId>
<version>${querqy.lucene.version}</version>
<exclusions>
<exclusion>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>${json-path.version}</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/querqy/elasticsearch/query/Rewriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public Map<String, Object> getParams() {
return params;
}

public void setParams(Map<String, Object> params) {
public void setParams(final Map<String, Object> params) {
this.params = params;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> content = new HashMap<>();
content.put("class", SimpleCommonRulesRewriterFactory.class.getName());

final Map<String, Object> 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<String, Object> criteria = new HashMap<>();
criteria.put("filter", "$[?(@.lang == 'l1')]");
final Map<String, Object> 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);



}

}

0 comments on commit ca1960c

Please sign in to comment.