Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
41 clients/java/src/main/java/com/senseidb/search/client/json/req/filter/CustomFilter.java
@@ -0,0 +1,41 @@
+package com.senseidb.search.client.json.req.filter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.senseidb.search.client.json.CustomJsonHandler;
+import com.senseidb.search.client.json.JsonField;
+
+/**
+ * User may supply his own implementation of the query
+ *
+ */
+@CustomJsonHandler(FilterJsonHandler.class)
+public class CustomFilter implements Filter {
+ @JsonField("class")
+ private String cls;
+ @JsonField("params")
+ private List<String> params = new ArrayList<String>();
+ @JsonField("values")
+ private List<Object> values = new ArrayList<Object>();
+
+ public CustomFilter(String cls, List<String> params, List<Object> values) {
+ super();
+ this.cls = cls;
+ this.params = params;
+ this.values = values;
+ }
+
+ public String getCls() {
+ return cls;
+ }
+
+ public List<String> getParams() {
+ return params;
+ }
+
+ public List<Object> getValues() {
+ return values;
+ }
+
+}
View
15 clients/java/src/main/java/com/senseidb/search/client/json/req/filter/FilterJsonHandler.java
@@ -76,6 +76,21 @@ public JSONObject serialize(Filter bean) throws JSONException {
if (bean instanceof QueryFilter) {
return new JSONObject().put("query", queryJsonHandler.serialize(((QueryFilter) bean).getQuery()));
}
+ if(bean instanceof CustomFilter) {
+ CustomFilter custom = (CustomFilter) bean;
+ JSONObject ret = new JSONObject();
+ if (custom.getCls() != null) {
+ ret.put("class", custom.getCls());
+ }
+ if (custom.getParams() != null) {
+ ret.put("params", new JSONArray(custom.getParams()));
+ }
+ if (custom.getValues() != null) {
+ ret.put("values", new JSONArray(custom.getValues()));
+ }
+
+ return new JSONObject().put("custom", ret);
+ }
throw new UnsupportedOperationException(bean.getClass() + " is not supported");
}
View
4 clients/java/src/main/java/com/senseidb/search/client/json/req/filter/Filters.java
@@ -13,6 +13,10 @@
import com.senseidb.search.client.json.req.query.Query;
public class Filters {
+ public static CustomFilter customFilter(String cls, List<String> params, List<Object> values) {
+ return new CustomFilter(cls, params, values);
+ }
+
public static Ids ids(List<String> values, List<String> excludes) {
return new Ids(values, excludes);
}
View
9 clients/java/src/main/java/com/senseidb/search/client/json/req/query/Queries.java
@@ -62,11 +62,14 @@ public static SpanTerm spanTerm(String field, String value, Double boost) {
return new SpanTerm(field, value, boost);
}
public static TextQuery textQuery(String field, String text, Operator operator, Type type, double boost) {
- return new TextQuery(field, text, operator, type, boost);
+ return new TextQuery(field, text, operator, type, boost, null);
}
public static TextQuery textQuery(String field, String text, Operator operator, double boost) {
- return new TextQuery(field, text, operator, null, boost);
- }
+ return new TextQuery(field, text, operator, null, boost, null);
+ }
+ public static TextQuery textQuery(String field, String text, Operator operator, double boost, String analyzer) {
+ return new TextQuery(field, text, operator, null, boost, analyzer);
+ }
public static FilteredQuery filteredQuery(Query query, Filter filter, double boost) {
return new FilteredQuery(query, filter, boost);
}
View
7 clients/java/src/main/java/com/senseidb/search/client/json/req/query/TextQuery.java
@@ -135,14 +135,16 @@
private Operator operator;
private Type type;
private double boost;
+ private String analyzer;
- public TextQuery(String field, String value, Operator operator, Type type, double boost) {
+ public TextQuery(String field, String value, Operator operator, Type type, double boost, String analyzer) {
super();
this.field = field;
this.value = value;
this.operator = operator;
this.type = type;
this.boost = boost;
+ this.analyzer = analyzer;
}
public static enum Type {
@@ -170,4 +172,7 @@ public double getBoost() {
return boost;
}
+ public String getAnalyzer() {
+ return analyzer;
+ }
}
View
35 clients/java/src/test/java/com/senseidb/test/client/json/JsonSerializationTest.java
@@ -1,14 +1,21 @@
package com.senseidb.test.client.json;
+import java.util.Arrays;
+import java.util.List;
+
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import com.senseidb.search.client.json.JsonDeserializer;
import com.senseidb.search.client.json.JsonSerializer;
import com.senseidb.search.client.json.req.FacetInit;
+import com.senseidb.search.client.json.req.Operator;
import com.senseidb.search.client.json.req.SenseiClientRequest;
+import com.senseidb.search.client.json.req.filter.Filters;
+import com.senseidb.search.client.json.req.query.Queries;
+import com.senseidb.search.client.json.req.query.Query;
import com.senseidb.search.client.json.res.SenseiResult;
public class JsonSerializationTest extends Assert {
@@ -57,4 +64,32 @@ public void test5QueriesSerialization() throws Exception {
JSONObject json = (JSONObject) JsonSerializer.serialize(senseiRequest);
System.out.println(json.toString(3));
}
+
+ @Test
+ public void testTextQueriesWithAnalyzerSerialization() throws Exception {
+ SenseiClientRequest.Builder builder = SenseiClientRequest.builder();
+ List innerQueries = Arrays.asList(
+ Queries.textQuery("name", "anything", Operator.or, 1.0, "org.apache.lucene.analysis.WhitespaceAnalyzer")
+ );
+ builder.query(Queries.bool(innerQueries, null, null, 2, 2.0, true));
+ SenseiClientRequest senseiRequest = builder.build();
+ JSONObject json = (JSONObject) JsonSerializer.serialize(senseiRequest);
+ assertTrue(json.toString().indexOf("analyzer") != 0);
+ System.out.println(json.toString());
+ }
+
+ @Test
+ public void testCustomFilterSerialization() throws Exception {
+ SenseiClientRequest.Builder builder = SenseiClientRequest.builder();
+ builder.filter(
+ Filters.customFilter("org.apache.lucene.analysis.Filter",
+ Arrays.asList("long"),
+ Arrays.asList((Object)new Integer(100000)))
+ );
+
+ SenseiClientRequest senseiRequest = builder.build();
+ JSONObject json = (JSONObject) JsonSerializer.serialize(senseiRequest);
+ assertTrue(json.toString().indexOf("custom") != 0);
+ System.out.println(json.toString());
+ }
}

No commit comments for this range

Something went wrong with that request. Please try again.